Sonic Blaze Testnet

Token

Algebra Positions NFT-V2 (ALGB-POS)
ERC-721

Overview

Max Total Supply

6 ALGB-POS

Holders

4

Market

Onchain Market Cap

-

Circulating Supply Market Cap

-
Balance
0 ALGB-POS
0x0000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
Loading...
Loading

Click here to update the token information / general information
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.

Contract Source Code Verified (Exact Match)

Contract Name:
NonfungiblePositionManager

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 0 runs

Other Settings:
paris EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 60 : NonfungiblePositionManager.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.20;

import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol';
import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraFactory.sol';
import '@cryptoalgebra/integral-core/contracts/libraries/Constants.sol';
import '@cryptoalgebra/integral-core/contracts/libraries/FullMath.sol';

import './interfaces/INonfungiblePositionManager.sol';
import './interfaces/INonfungibleTokenPositionDescriptor.sol';
import './interfaces/IPositionFollower.sol';
import './libraries/PoolInteraction.sol';
import './libraries/OracleLibrary.sol';
import './libraries/PoolAddress.sol';
import './base/LiquidityManagement.sol';
import './base/PeripheryImmutableState.sol';
import './base/Multicall.sol';
import './base/ERC721Permit.sol';
import './base/PeripheryValidation.sol';
import './base/SelfPermit.sol';
import './base/PoolInitializer.sol';

/// @title Algebra Integral 1.0 NFT positions
/// @notice Wraps Algebra positions in the ERC721 non-fungible token interface
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
contract NonfungiblePositionManager is
    INonfungiblePositionManager,
    Multicall,
    ERC721Permit,
    PeripheryImmutableState,
    PoolInitializer,
    LiquidityManagement,
    PeripheryValidation,
    SelfPermit
{
    using PoolInteraction for IAlgebraPool;

    // details about the Algebra position
    struct Position {
        uint88 nonce; // the nonce for permits
        address operator; // the address that is approved for spending this token
        uint80 poolId; // the ID of the pool with which this token is connected
        int24 tickLower; // the tick range of the position
        int24 tickUpper;
        uint128 liquidity; // the liquidity of the position
        uint256 feeGrowthInside0LastX128; // the fee growth of the aggregate position as of the last action on the individual position
        uint256 feeGrowthInside1LastX128;
        uint128 tokensOwed0; // how many uncollected tokens are owed to the position, as of the last computation
        uint128 tokensOwed1;
    }

    // details about withdrawal fee for position
    struct PositionWithdrawalFee {
        uint32 lastUpdateTimestamp; // last increase/decrease liquidity timestamp
        uint128 withdrawalFeeLiquidity; // liqudity of accumulated withdrawal fee
    }

    /// @dev The role which has the right to change the farming center address
    bytes32 public constant NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE =
        keccak256('NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE');

    uint64 public constant FEE_DENOMINATOR = 1e3;

    /// @inheritdoc INonfungiblePositionManager
    address public override farmingCenter;

    /// @inheritdoc INonfungiblePositionManager
    address public override defaultWithdrawalFeesVault;

    /// @inheritdoc INonfungiblePositionManager
    mapping(uint256 tokenId => address farmingCenterAddress) public override farmingApprovals;

    /// @inheritdoc INonfungiblePositionManager
    mapping(uint256 tokenId => address farmingCenterAddress) public tokenFarmedIn;

    mapping(address pool => WithdrawalFeePoolParams params) private withdrawalFeePoolParams;

    /// @dev The address of the token descriptor contract, which handles generating token URIs for position tokens
    address private immutable _tokenDescriptor;

    /// @dev IDs of pools assigned by this contract
    mapping(address poolAddress => uint80 poolId) private _poolIds;

    /// @dev Pool keys by pool ID, to save on SSTOREs for position data
    mapping(uint80 poolId => PoolAddress.PoolKey poolKey) private _poolIdToPoolKey;

    /// @dev The token ID position data
    mapping(uint256 tokenId => Position position) private _positions;

    /// @dev The token ID withdrawal fee position data
    mapping(uint256 tokenId => PositionWithdrawalFee data) private _positionsWithdrawalFee;

    /// @dev The ID of the next token that will be minted. Skips 0
    uint176 private _nextId = 1;
    /// @dev The ID of the next pool that is used for the first time. Skips 0
    uint80 private _nextPoolId = 1;

    modifier isAuthorizedForToken(uint256 tokenId) {
        _checkAuthorizationForToken(tokenId);
        _;
    }

    modifier onlyAdministrator() {
        _hasRoleOrOwner();
        _;
    }

    constructor(
        address _factory,
        address _WNativeToken,
        address _tokenDescriptor_,
        address _poolDeployer,
        address _vault
    )
        ERC721Permit('Algebra Positions NFT-V2', 'ALGB-POS', '2')
        PeripheryImmutableState(_factory, _WNativeToken, _poolDeployer)
    {
        _tokenDescriptor = _tokenDescriptor_;
        require(_vault != address(0));
        defaultWithdrawalFeesVault = _vault;
    }

    function positionsWithdrawalFee(
        uint256 tokenId
    ) external view override returns (uint32 lastUpdateTimestamp, uint128 withdrawalFeeLiquidity) {
        PositionWithdrawalFee memory _position = _positionsWithdrawalFee[tokenId];
        return (_position.lastUpdateTimestamp, _position.withdrawalFeeLiquidity);
    }

    function getWithdrawalFeePoolParams(
        address pool
    ) external view override returns (WithdrawalFeePoolParams memory params) {
        return withdrawalFeePoolParams[pool];
    }

    /// @inheritdoc INonfungiblePositionManager
    function positions(
        uint256 tokenId
    )
        external
        view
        override
        returns (
            uint88 nonce,
            address operator,
            address token0,
            address token1,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        )
    {
        Position storage position = _positions[tokenId];
        // single SLOAD
        uint80 poolId = position.poolId;
        tickLower = position.tickLower;
        tickUpper = position.tickUpper;
        liquidity = position.liquidity;
        require(poolId != 0, 'Invalid token ID');
        PoolAddress.PoolKey storage poolKey = _poolIdToPoolKey[poolId];
        return (
            position.nonce,
            position.operator,
            poolKey.token0,
            poolKey.token1,
            tickLower,
            tickUpper,
            liquidity,
            position.feeGrowthInside0LastX128,
            position.feeGrowthInside1LastX128,
            position.tokensOwed0,
            position.tokensOwed1
        );
    }

    /// @inheritdoc INonfungiblePositionManager
    function mint(
        MintParams calldata params
    )
        external
        payable
        override
        checkDeadline(params.deadline)
        returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)
    {
        IAlgebraPool pool;
        uint128 liquidityDesired;
        (liquidityDesired, liquidity, amount0, amount1, pool) = addLiquidity(
            AddLiquidityParams({
                token0: params.token0,
                token1: params.token1,
                recipient: address(this),
                tickLower: params.tickLower,
                tickUpper: params.tickUpper,
                amount0Desired: params.amount0Desired,
                amount1Desired: params.amount1Desired,
                amount0Min: params.amount0Min,
                amount1Min: params.amount1Min
            })
        );
        unchecked {
            _mint(params.recipient, (tokenId = _nextId++));
        }

        (, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, , ) = pool._getPositionInPool(
            address(this),
            params.tickLower,
            params.tickUpper
        );

        // idempotent set
        uint80 poolId = _cachePoolKey(
            address(pool),
            PoolAddress.PoolKey({token0: params.token0, token1: params.token1})
        );

        _positions[tokenId] = Position({
            nonce: 0,
            operator: address(0),
            poolId: poolId,
            tickLower: params.tickLower,
            tickUpper: params.tickUpper,
            liquidity: liquidity,
            feeGrowthInside0LastX128: feeGrowthInside0LastX128,
            feeGrowthInside1LastX128: feeGrowthInside1LastX128,
            tokensOwed0: 0,
            tokensOwed1: 0
        });

        _positionsWithdrawalFee[tokenId] = PositionWithdrawalFee({
            lastUpdateTimestamp: uint32(_blockTimestamp()),
            withdrawalFeeLiquidity: 0
        });

        emit IncreaseLiquidity(tokenId, liquidityDesired, liquidity, amount0, amount1, address(pool));
    }

    /// @dev Caches a pool key
    function _cachePoolKey(address pool, PoolAddress.PoolKey memory poolKey) private returns (uint80 poolId) {
        if ((poolId = _poolIds[pool]) == 0) {
            unchecked {
                _poolIds[pool] = (poolId = _nextPoolId++);
            }
            _poolIdToPoolKey[poolId] = poolKey;
        }
    }

    function _getPoolById(uint80 poolId) private view returns (address) {
        return PoolAddress.computeAddress(poolDeployer, _poolIdToPoolKey[poolId]);
    }

    function _updateUncollectedFees(
        Position storage position,
        IAlgebraPool pool,
        address owner,
        int24 tickLower,
        int24 tickUpper,
        uint128 positionLiquidity
    ) private returns (uint128 tokensOwed0, uint128 tokensOwed1) {
        (, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, , ) = pool._getPositionInPool(
            owner,
            tickLower,
            tickUpper
        );
        unchecked {
            tokensOwed0 = uint128(
                FullMath.mulDiv(
                    feeGrowthInside0LastX128 - position.feeGrowthInside0LastX128,
                    positionLiquidity,
                    Constants.Q128
                )
            );
            tokensOwed1 = uint128(
                FullMath.mulDiv(
                    feeGrowthInside1LastX128 - position.feeGrowthInside1LastX128,
                    positionLiquidity,
                    Constants.Q128
                )
            );
        }

        position.feeGrowthInside0LastX128 = feeGrowthInside0LastX128;
        position.feeGrowthInside1LastX128 = feeGrowthInside1LastX128;
    }

    function _calculateWithdrawalFees(
        address pool,
        uint32 lastUpdateTimestamp,
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity
    ) private view returns (uint128 withdrawalFeeLiquidity) {
        WithdrawalFeePoolParams memory params = withdrawalFeePoolParams[pool];

        uint256 token0apr = params.apr0;
        uint256 token1apr = params.apr1;
        uint16 withdrawalFee = params.withdrawalFee;

        if ((token0apr > 0 || token1apr > 0) && withdrawalFee > 0) {
            uint32 period = uint32(_blockTimestamp()) - lastUpdateTimestamp;

            if (period == 0) return 0;
            address oracle = IAlgebraPool(pool).plugin();

            if (oracle == address(0)) return 0;
            int24 timeWeightedAverageTick = OracleLibrary.consult(oracle, period);

            uint160 tickLowerPrice = TickMath.getSqrtRatioAtTick(tickLower);
            uint160 tickUpperPrice = TickMath.getSqrtRatioAtTick(tickUpper);

            (uint256 averageAmount0, uint256 averageAmount1) = LiquidityAmounts.getAmountsForLiquidity(
                TickMath.getSqrtRatioAtTick(timeWeightedAverageTick),
                tickLowerPrice,
                tickUpperPrice,
                liquidity
            );

            if (token0apr > 0) {
                uint256 amount0EarnedFromStake = (token0apr * period * averageAmount0) / (FEE_DENOMINATOR * 365 days);
                uint128 amount0ToWithdraw = uint128((amount0EarnedFromStake * withdrawalFee) / FEE_DENOMINATOR);
                withdrawalFeeLiquidity += LiquidityAmounts.getLiquidityForAmount0(
                    tickLowerPrice,
                    tickUpperPrice,
                    amount0ToWithdraw
                );
            }

            if (token1apr > 0) {
                uint256 amount1EarnedFromStake = (token1apr * period * averageAmount1) / (FEE_DENOMINATOR * 365 days);
                uint128 amount1ToWithdraw = uint128((amount1EarnedFromStake * withdrawalFee) / FEE_DENOMINATOR);
                withdrawalFeeLiquidity += LiquidityAmounts.getLiquidityForAmount1(
                    tickLowerPrice,
                    tickUpperPrice,
                    amount1ToWithdraw
                );
            }
        }
    }

    /// @inheritdoc INonfungiblePositionManager
    function increaseLiquidity(
        IncreaseLiquidityParams calldata params
    )
        external
        payable
        override
        checkDeadline(params.deadline)
        returns (uint128 liquidity, uint256 amount0, uint256 amount1)
    {
        Position storage position = _positions[params.tokenId];

        PoolAddress.PoolKey storage poolKey = _poolIdToPoolKey[position.poolId];
        int24 tickLower = position.tickLower;
        int24 tickUpper = position.tickUpper;
        uint128 positionLiquidity = position.liquidity;

        IAlgebraPool pool;
        uint128 liquidityDesired;
        (liquidityDesired, liquidity, amount0, amount1, pool) = addLiquidity(
            AddLiquidityParams({
                token0: poolKey.token0,
                token1: poolKey.token1,
                tickLower: tickLower,
                tickUpper: tickUpper,
                amount0Desired: params.amount0Desired,
                amount1Desired: params.amount1Desired,
                amount0Min: params.amount0Min,
                amount1Min: params.amount1Min,
                recipient: address(this)
            })
        );

        // this is now updated to the current transaction
        (uint128 tokensOwed0, uint128 tokensOwed1) = _updateUncollectedFees(
            position,
            pool,
            address(this),
            tickLower,
            tickUpper,
            positionLiquidity
        );

        unchecked {
            if (tokensOwed0 | tokensOwed1 != 0) {
                position.tokensOwed0 += tokensOwed0;
                position.tokensOwed1 += tokensOwed1;
            }
            position.liquidity = positionLiquidity + liquidity;
        }

        {
            PositionWithdrawalFee storage _position = _positionsWithdrawalFee[params.tokenId];
            uint128 withdrawalFeeLiquidity = _calculateWithdrawalFees(
                address(pool),
                _position.lastUpdateTimestamp,
                tickLower,
                tickUpper,
                positionLiquidity
            );
            _position.lastUpdateTimestamp = uint32(_blockTimestamp());
            _position.withdrawalFeeLiquidity += withdrawalFeeLiquidity;
        }

        emit IncreaseLiquidity(params.tokenId, liquidityDesired, liquidity, amount0, amount1, address(pool));

        _applyLiquidityDeltaInFarming(params.tokenId, int256(uint256(liquidity)));
    }

    /// @inheritdoc INonfungiblePositionManager
    function decreaseLiquidity(
        DecreaseLiquidityParams calldata params
    )
        external
        payable
        override
        isAuthorizedForToken(params.tokenId)
        checkDeadline(params.deadline)
        returns (uint256 amount0, uint256 amount1)
    {
        require(params.liquidity > 0);
        Position storage position = _positions[params.tokenId];

        (uint80 poolId, int24 tickLower, int24 tickUpper, uint128 positionLiquidity) = (
            position.poolId,
            position.tickLower,
            position.tickUpper,
            position.liquidity
        );
        require(positionLiquidity >= params.liquidity);

        IAlgebraPool pool = IAlgebraPool(_getPoolById(poolId));

        uint128 positionWithdrawalFeeLiquidity;
        {
            PositionWithdrawalFee storage _position = _positionsWithdrawalFee[params.tokenId];
            positionWithdrawalFeeLiquidity = _position.withdrawalFeeLiquidity;
            positionWithdrawalFeeLiquidity += _calculateWithdrawalFees(
                address(pool),
                _position.lastUpdateTimestamp,
                tickLower,
                tickUpper,
                positionLiquidity
            );
            _position.lastUpdateTimestamp = uint32(_blockTimestamp());
            positionWithdrawalFeeLiquidity = positionWithdrawalFeeLiquidity > positionLiquidity
                ? positionLiquidity
                : positionWithdrawalFeeLiquidity;

            _position.withdrawalFeeLiquidity = 0;
        }

        if (positionWithdrawalFeeLiquidity > 0) {
            (amount0, amount1) = pool._burnPositionInPool(tickLower, tickUpper, positionWithdrawalFeeLiquidity);
            FeesVault[] memory vaults = withdrawalFeePoolParams[address(pool)].feeVaults;
            if (vaults.length == 0) {
                pool.collect(defaultWithdrawalFeesVault, tickLower, tickUpper, uint128(amount0), uint128(amount1));
            } else {
                for (uint i = 0; i < vaults.length; i++) {
                    uint16 feePart = vaults[i].fee;
                    pool.collect(
                        vaults[i].feeVault,
                        tickLower,
                        tickUpper,
                        uint128((amount0 * feePart) / FEE_DENOMINATOR),
                        uint128((amount1 * feePart) / FEE_DENOMINATOR)
                    );
                }
            }
        }

        uint128 liquidityDeltaWithoutFee = params.liquidity > positionLiquidity - positionWithdrawalFeeLiquidity
            ? positionLiquidity - positionWithdrawalFeeLiquidity
            : params.liquidity;

        (amount0, amount1) = pool._burnPositionInPool(tickLower, tickUpper, liquidityDeltaWithoutFee);

        require(amount0 >= params.amount0Min && amount1 >= params.amount1Min, 'Price slippage check');

        // scope to prevent stack-too-deep
        {
            // this is now updated to the current transaction
            (uint128 tokensOwed0, uint128 tokensOwed1) = _updateUncollectedFees(
                position,
                pool,
                address(this),
                tickLower,
                tickUpper,
                positionLiquidity
            );

            unchecked {
                position.tokensOwed0 += uint128(amount0) + tokensOwed0;
                position.tokensOwed1 += uint128(amount1) + tokensOwed1;

                // subtraction is safe because we checked positionLiquidity is gte params.liquidity
                position.liquidity = positionLiquidity - liquidityDeltaWithoutFee - positionWithdrawalFeeLiquidity;
            }
        }

        emit DecreaseLiquidity(
            params.tokenId,
            liquidityDeltaWithoutFee,
            positionWithdrawalFeeLiquidity,
            amount0,
            amount1
        );

        _applyLiquidityDeltaInFarming(
            params.tokenId,
            -int256(uint256(liquidityDeltaWithoutFee + positionWithdrawalFeeLiquidity))
        );
    }

    /// @inheritdoc INonfungiblePositionManager
    function collect(
        CollectParams calldata params
    ) external payable override isAuthorizedForToken(params.tokenId) returns (uint256 amount0, uint256 amount1) {
        require(params.amount0Max > 0 || params.amount1Max > 0);
        // allow collecting to the nft position manager address with address 0
        address recipient = params.recipient == address(0) ? address(this) : params.recipient;

        Position storage position = _positions[params.tokenId];
        IAlgebraPool pool = IAlgebraPool(_getPoolById(position.poolId));

        // trigger an update of the position fees owed and fee growth snapshots if it has any liquidity
        int24 tickLower = position.tickLower;
        int24 tickUpper = position.tickUpper;
        uint128 positionLiquidity = position.liquidity;

        (uint128 tokensOwed0, uint128 tokensOwed1) = (position.tokensOwed0, position.tokensOwed1);
        if (positionLiquidity > 0) {
            pool._burnPositionInPool(tickLower, tickUpper, 0);
            (uint128 _tokensOwed0, uint128 _tokensOwed1) = _updateUncollectedFees(
                position,
                pool,
                address(this),
                tickLower,
                tickUpper,
                positionLiquidity
            );

            unchecked {
                tokensOwed0 += _tokensOwed0;
                tokensOwed1 += _tokensOwed1;
            }
        }

        // compute the arguments to give to the pool#collect method
        (uint128 amount0Collect, uint128 amount1Collect) = (
            params.amount0Max > tokensOwed0 ? tokensOwed0 : params.amount0Max,
            params.amount1Max > tokensOwed1 ? tokensOwed1 : params.amount1Max
        );

        // the actual amounts collected are returned
        (amount0, amount1) = pool.collect(recipient, tickLower, tickUpper, amount0Collect, amount1Collect);

        // sometimes there will be a few less wei than expected due to rounding down in core, but we just subtract the full amount expected
        // instead of the actual amount so we can burn the token
        unchecked {
            (position.tokensOwed0, position.tokensOwed1) = (tokensOwed0 - amount0Collect, tokensOwed1 - amount1Collect);
        }

        emit Collect(params.tokenId, recipient, amount0Collect, amount1Collect);
    }

    /// @inheritdoc INonfungiblePositionManager
    function burn(uint256 tokenId) external payable override isAuthorizedForToken(tokenId) {
        Position storage position = _positions[tokenId];
        require(position.liquidity | position.tokensOwed0 | position.tokensOwed1 == 0);

        delete _positions[tokenId];
        delete tokenFarmedIn[tokenId];
        _burn(tokenId);
    }

    /// @inheritdoc INonfungiblePositionManager
    function approveForFarming(
        uint256 tokenId,
        bool approve,
        address farmingAddress
    ) external payable override isAuthorizedForToken(tokenId) {
        address newValue;
        if (approve) {
            require(farmingAddress == farmingCenter);
            newValue = farmingAddress;
        }
        farmingApprovals[tokenId] = newValue;
    }

    /// @inheritdoc INonfungiblePositionManager
    function switchFarmingStatus(uint256 tokenId, bool toActive) external override {
        address _farmingCenter = farmingCenter;
        bool accessAllowed = msg.sender == _farmingCenter;
        address newFarmForToken;
        if (toActive) {
            require(farmingApprovals[tokenId] == _farmingCenter, 'Not approved for farming');
            newFarmForToken = _farmingCenter;
        } else {
            // can be switched off by current farming center or by the farming center in which nft is farmed
            accessAllowed = accessAllowed || msg.sender == tokenFarmedIn[tokenId];
        }
        require(accessAllowed, 'Only FarmingCenter');
        tokenFarmedIn[tokenId] = newFarmForToken;
    }

    /// @inheritdoc INonfungiblePositionManager
    function setFarmingCenter(address newFarmingCenter) external override onlyAdministrator {
        farmingCenter = newFarmingCenter;
        emit FarmingCenter(newFarmingCenter);
    }

    /// @inheritdoc INonfungiblePositionManager
    function setTokenAPR(address pool, uint64 _apr0, uint64 _apr1) external override onlyAdministrator {
        require(_apr0 <= FEE_DENOMINATOR && _apr1 <= FEE_DENOMINATOR);
        WithdrawalFeePoolParams storage params = withdrawalFeePoolParams[pool];
        params.apr0 = _apr0;
        params.apr1 = _apr1;
    }

    function setVaultsForPool(
        address pool,
        uint16[] memory fees,
        address[] memory vaults
    ) external override onlyAdministrator {
        uint16 totalFee;
        FeesVault[] storage vaultsForPool = withdrawalFeePoolParams[pool].feeVaults;
        require(vaults.length == fees.length, 'Vaults and fees length mismatch');
        if (vaultsForPool.length != 0 || fees.length == 0) {
            delete withdrawalFeePoolParams[pool].feeVaults;
        }
        for (uint256 i = 0; i < fees.length; i++) {
            require(vaults[i] != address(0), 'Vault address cannot be 0');
            vaultsForPool.push(FeesVault(vaults[i], fees[i]));
            totalFee += fees[i];
            emit FeeVaultForPool(pool, vaults[i], fees[i]);
        }
        if (fees.length != 0) {
            require(totalFee == FEE_DENOMINATOR, 'Total fee must be equal to FEE_DENOMINATOR');
            withdrawalFeePoolParams[pool].feeVaults = vaultsForPool;
        }
    }

    /// @inheritdoc INonfungiblePositionManager
    function setWithdrawalFee(address pool, uint16 newWithdrawalFee) external override onlyAdministrator {
        require(newWithdrawalFee <= FEE_DENOMINATOR);
        withdrawalFeePoolParams[pool].withdrawalFee = newWithdrawalFee;
    }

    /// @inheritdoc INonfungiblePositionManager
    function setVaultAddress(address newVault) external override onlyAdministrator {
        require(newVault != address(0));
        defaultWithdrawalFeesVault = newVault;
    }

    /// @inheritdoc IERC721Metadata
    function tokenURI(uint256 tokenId) public view override(ERC721, IERC721Metadata) returns (string memory) {
        _requireMinted(tokenId);
        return INonfungibleTokenPositionDescriptor(_tokenDescriptor).tokenURI(this, tokenId);
    }

    /// @inheritdoc IERC721
    function getApproved(uint256 tokenId) public view override(ERC721, IERC721) returns (address) {
        _requireMinted(tokenId);
        return _positions[tokenId].operator;
    }

    /// @inheritdoc INonfungiblePositionManager
    function isApprovedOrOwner(address spender, uint256 tokenId) external view override returns (bool) {
        _requireMinted(tokenId);
        return _isApprovedOrOwner(spender, tokenId);
    }

    function _checkAuthorizationForToken(uint256 tokenId) private view {
        require(_isApprovedOrOwner(msg.sender, tokenId), 'Not approved');
    }

    function _hasRoleOrOwner() private view {
        require(IAlgebraFactory(factory).hasRoleOrOwner(NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE, msg.sender));
    }

    function _applyLiquidityDeltaInFarming(uint256 tokenId, int256 liquidityDelta) private {
        address _tokenFarmedIn = tokenFarmedIn[tokenId];
        if (_tokenFarmedIn == address(0)) return;

        address _farmingCenter = farmingCenter;
        if (_farmingCenter == address(0)) return;

        if (_tokenFarmedIn == _farmingCenter) {
            // errors without message (i.e. out of gas) will be propagated
            // custom errors will be propagated
            try IPositionFollower(_farmingCenter).applyLiquidityDelta(tokenId, liquidityDelta) {
                // do nothing
            } catch Panic(uint256) {
                emit FarmingFailed(tokenId);
            } catch Error(string memory) {
                emit FarmingFailed(tokenId);
            }
        }
    }

    /// @dev Gets the current nonce for a token ID and then increments it, returning the original value
    function _getAndIncrementNonce(uint256 tokenId) internal override returns (uint256) {
        unchecked {
            return uint256(_positions[tokenId].nonce++);
        }
    }

    /// @dev Overrides to clear operator and farming approval before any transfer (including burn, but not including mint)
    function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batch) internal override {
        // transfer from address(0) is mint
        if (from != address(0)) {
            // clear approvals
            _positions[tokenId].operator = address(0);
            delete farmingApprovals[tokenId];
        }
        super._beforeTokenTransfer(from, to, tokenId, batch);
    }

    /// @dev Overrides _approve to use the operator in the position, which is packed with the position permit nonce
    function _approve(address to, uint256 tokenId) internal override(ERC721) {
        _positions[tokenId].operator = to;
        emit Approval(ownerOf(tokenId), to, tokenId);
    }
}

File 2 of 60 : IAlgebraMintCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IAlgebraPoolActions#mint
/// @notice Any contract that calls IAlgebraPoolActions#mint must implement this interface
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraMintCallback {
  /// @notice Called to `msg.sender` after minting liquidity to a position from IAlgebraPool#mint.
  /// @dev In the implementation you must pay the pool tokens owed for the minted liquidity.
  /// The caller of this method _must_ be checked to be a AlgebraPool deployed by the canonical AlgebraFactory.
  /// @param amount0Owed The amount of token0 due to the pool for the minted liquidity
  /// @param amount1Owed The amount of token1 due to the pool for the minted liquidity
  /// @param data Any data passed through by the caller via the IAlgebraPoolActions#mint call
  function algebraMintCallback(uint256 amount0Owed, uint256 amount1Owed, bytes calldata data) external;
}

File 3 of 60 : IAlgebraFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
pragma abicoder v2;

import './plugin/IAlgebraPluginFactory.sol';
import './vault/IAlgebraVaultFactory.sol';

/// @title The interface for the Algebra Factory
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraFactory {
  /// @notice Emitted when a process of ownership renounce is started
  /// @param timestamp The timestamp of event
  /// @param finishTimestamp The timestamp when ownership renounce will be possible to finish
  event RenounceOwnershipStart(uint256 timestamp, uint256 finishTimestamp);

  /// @notice Emitted when a process of ownership renounce cancelled
  /// @param timestamp The timestamp of event
  event RenounceOwnershipStop(uint256 timestamp);

  /// @notice Emitted when a process of ownership renounce finished
  /// @param timestamp The timestamp of ownership renouncement
  event RenounceOwnershipFinish(uint256 timestamp);

  /// @notice Emitted when a pool is created
  /// @param token0 The first token of the pool by address sort order
  /// @param token1 The second token of the pool by address sort order
  /// @param pool The address of the created pool
  event Pool(address indexed token0, address indexed token1, address pool);

  /// @notice Emitted when the default community fee is changed
  /// @param newDefaultCommunityFee The new default community fee value
  event DefaultCommunityFee(uint16 newDefaultCommunityFee);

  /// @notice Emitted when the default tickspacing is changed
  /// @param newDefaultTickspacing The new default tickspacing value
  event DefaultTickspacing(int24 newDefaultTickspacing);

  /// @notice Emitted when the default fee is changed
  /// @param newDefaultFee The new default fee value
  event DefaultFee(uint16 newDefaultFee);

  /// @notice Emitted when the defaultPluginFactory address is changed
  /// @param defaultPluginFactoryAddress The new defaultPluginFactory address
  event DefaultPluginFactory(address defaultPluginFactoryAddress);

  /// @notice Emitted when the vaultFactory address is changed
  /// @param newVaultFactory The new vaultFactory address
  event VaultFactory(address newVaultFactory);

  /// @notice role that can change communityFee and tickspacing in pools
  /// @return The hash corresponding to this role
  function POOLS_ADMINISTRATOR_ROLE() external view returns (bytes32);

  /// @notice Returns `true` if `account` has been granted `role` or `account` is owner.
  /// @param role The hash corresponding to the role
  /// @param account The address for which the role is checked
  /// @return bool Whether the address has this role or the owner role or not
  function hasRoleOrOwner(bytes32 role, address account) external view returns (bool);

  /// @notice Returns the current owner of the factory
  /// @dev Can be changed by the current owner via transferOwnership(address newOwner)
  /// @return The address of the factory owner
  function owner() external view returns (address);

  /// @notice Returns the current poolDeployerAddress
  /// @return The address of the poolDeployer
  function poolDeployer() external view returns (address);

  /// @notice Returns the default community fee
  /// @return Fee which will be set at the creation of the pool
  function defaultCommunityFee() external view returns (uint16);

  /// @notice Returns the default fee
  /// @return Fee which will be set at the creation of the pool
  function defaultFee() external view returns (uint16);

  /// @notice Returns the default tickspacing
  /// @return Tickspacing which will be set at the creation of the pool
  function defaultTickspacing() external view returns (int24);

  /// @notice Return the current pluginFactory address
  /// @dev This contract is used to automatically set a plugin address in new liquidity pools
  /// @return Algebra plugin factory
  function defaultPluginFactory() external view returns (IAlgebraPluginFactory);

  /// @notice Return the current vaultFactory address
  /// @dev This contract is used to automatically set a vault address in new liquidity pools
  /// @return Algebra vault factory
  function vaultFactory() external view returns (IAlgebraVaultFactory);

  /// @notice Returns the default communityFee, tickspacing, fee and communityFeeVault for pool
  /// @param pool the address of liquidity pool
  /// @return communityFee which will be set at the creation of the pool
  /// @return tickSpacing which will be set at the creation of the pool
  /// @return fee which will be set at the creation of the pool
  /// @return communityFeeVault the address of communityFeeVault
  function defaultConfigurationForPool(
    address pool
  ) external view returns (uint16 communityFee, int24 tickSpacing, uint16 fee, address communityFeeVault);

  /// @notice Deterministically computes the pool address given the token0 and token1
  /// @dev The method does not check if such a pool has been created
  /// @param token0 first token
  /// @param token1 second token
  /// @return pool The contract address of the Algebra pool
  function computePoolAddress(address token0, address token1) external view returns (address pool);

  /// @notice Returns the pool address for a given pair of tokens, or address 0 if it does not exist
  /// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
  /// @param tokenA The contract address of either token0 or token1
  /// @param tokenB The contract address of the other token
  /// @return pool The pool address
  function poolByPair(address tokenA, address tokenB) external view returns (address pool);

  /// @notice returns keccak256 of AlgebraPool init bytecode.
  /// @dev the hash value changes with any change in the pool bytecode
  /// @return Keccak256 hash of AlgebraPool contract init bytecode
  function POOL_INIT_CODE_HASH() external view returns (bytes32);

  /// @return timestamp The timestamp of the beginning of the renounceOwnership process
  function renounceOwnershipStartTimestamp() external view returns (uint256 timestamp);

  /// @notice Creates a pool for the given two tokens
  /// @param tokenA One of the two tokens in the desired pool
  /// @param tokenB The other of the two tokens in the desired pool
  /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0.
  /// The call will revert if the pool already exists or the token arguments are invalid.
  /// @return pool The address of the newly created pool
  function createPool(address tokenA, address tokenB) external returns (address pool);

  /// @dev updates default community fee for new pools
  /// @param newDefaultCommunityFee The new community fee, _must_ be <= MAX_COMMUNITY_FEE
  function setDefaultCommunityFee(uint16 newDefaultCommunityFee) external;

  /// @dev updates default fee for new pools
  /// @param newDefaultFee The new  fee, _must_ be <= MAX_DEFAULT_FEE
  function setDefaultFee(uint16 newDefaultFee) external;

  /// @dev updates default tickspacing for new pools
  /// @param newDefaultTickspacing The new tickspacing, _must_ be <= MAX_TICK_SPACING and >= MIN_TICK_SPACING
  function setDefaultTickspacing(int24 newDefaultTickspacing) external;

  /// @dev updates pluginFactory address
  /// @param newDefaultPluginFactory address of new plugin factory
  function setDefaultPluginFactory(address newDefaultPluginFactory) external;

  /// @dev updates vaultFactory address
  /// @param newVaultFactory address of new vault factory
  function setVaultFactory(address newVaultFactory) external;

  /// @notice Starts process of renounceOwnership. After that, a certain period
  /// of time must pass before the ownership renounce can be completed.
  function startRenounceOwnership() external;

  /// @notice Stops process of renounceOwnership and removes timer.
  function stopRenounceOwnership() external;
}

File 4 of 60 : IAlgebraPool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.4;

import './pool/IAlgebraPoolImmutables.sol';
import './pool/IAlgebraPoolState.sol';
import './pool/IAlgebraPoolActions.sol';
import './pool/IAlgebraPoolPermissionedActions.sol';
import './pool/IAlgebraPoolEvents.sol';
import './pool/IAlgebraPoolErrors.sol';

/// @title The interface for a Algebra Pool
/// @dev The pool interface is broken up into many smaller pieces.
/// This interface includes custom error definitions and cannot be used in older versions of Solidity.
/// For older versions of Solidity use #IAlgebraPoolLegacy
/// Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPool is
  IAlgebraPoolImmutables,
  IAlgebraPoolState,
  IAlgebraPoolActions,
  IAlgebraPoolPermissionedActions,
  IAlgebraPoolEvents,
  IAlgebraPoolErrors
{
  // used only for combining interfaces
}

File 5 of 60 : IAlgebraPluginFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title An interface for a contract that is capable of deploying Algebra plugins
/// @dev Such a factory is needed if the plugin should be automatically created and connected to each new pool
interface IAlgebraPluginFactory {
  /// @notice Deploys new plugin contract for pool
  /// @param pool The address of the pool for which the new plugin will be created
  /// @param token0 First token of the pool
  /// @param token1 Second token of the pool
  /// @return New plugin address
  function createPlugin(address pool, address token0, address token1) external returns (address);
}

File 6 of 60 : IAlgebraPoolActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissionless pool actions
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolActions {
  /// @notice Sets the initial price for the pool
  /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
  /// @dev Initialization should be done in one transaction with pool creation to avoid front-running
  /// @param initialPrice The initial sqrt price of the pool as a Q64.96
  function initialize(uint160 initialPrice) external;

  /// @notice Adds liquidity for the given recipient/bottomTick/topTick position
  /// @dev The caller of this method receives a callback in the form of IAlgebraMintCallback#algebraMintCallback
  /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
  /// on bottomTick, topTick, the amount of liquidity, and the current price.
  /// @param leftoversRecipient The address which will receive potential surplus of paid tokens
  /// @param recipient The address for which the liquidity will be created
  /// @param bottomTick The lower tick of the position in which to add liquidity
  /// @param topTick The upper tick of the position in which to add liquidity
  /// @param liquidityDesired The desired 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
  /// @return liquidityActual The actual minted amount of liquidity
  function mint(
    address leftoversRecipient,
    address recipient,
    int24 bottomTick,
    int24 topTick,
    uint128 liquidityDesired,
    bytes calldata data
  ) external returns (uint256 amount0, uint256 amount1, uint128 liquidityActual);

  /// @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 bottomTick The lower tick of the position for which to collect fees
  /// @param topTick 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 bottomTick,
    int24 topTick,
    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 bottomTick The lower tick of the position for which to burn liquidity
  /// @param topTick The upper tick of the position for which to burn liquidity
  /// @param amount How much liquidity to burn
  /// @param data Any data that should be passed through to the plugin
  /// @return amount0 The amount of token0 sent to the recipient
  /// @return amount1 The amount of token1 sent to the recipient
  function burn(int24 bottomTick, int24 topTick, uint128 amount, bytes calldata data) 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 IAlgebraSwapCallback#algebraSwapCallback
  /// @param recipient The address to receive the output of the swap
  /// @param zeroToOne The direction of the swap, true for token0 to token1, false for token1 to token0
  /// @param amountRequired The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
  /// @param limitSqrtPrice 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. If using the Router it should contain SwapRouter#SwapCallbackData
  /// @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 zeroToOne,
    int256 amountRequired,
    uint160 limitSqrtPrice,
    bytes calldata data
  ) external returns (int256 amount0, int256 amount1);

  /// @notice Swap token0 for token1, or token1 for token0 with prepayment
  /// @dev The caller of this method receives a callback in the form of IAlgebraSwapCallback#algebraSwapCallback
  /// caller must send tokens in callback before swap calculation
  /// the actually sent amount of tokens is used for further calculations
  /// @param leftoversRecipient The address which will receive potential surplus of paid tokens
  /// @param recipient The address to receive the output of the swap
  /// @param zeroToOne The direction of the swap, true for token0 to token1, false for token1 to token0
  /// @param amountToSell The amount of the swap, only positive (exact input) amount allowed
  /// @param limitSqrtPrice 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. If using the Router it should contain SwapRouter#SwapCallbackData
  /// @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 swapWithPaymentInAdvance(
    address leftoversRecipient,
    address recipient,
    bool zeroToOne,
    int256 amountToSell,
    uint160 limitSqrtPrice,
    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 IAlgebraFlashCallback#algebraFlashCallback
  /// @dev All excess tokens paid in the callback are distributed to currently in-range liquidity providers as an additional fee.
  /// If there are no in-range liquidity providers, the fee will be transferred to the first active provider in the future
  /// @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;
}

File 7 of 60 : IAlgebraPoolErrors.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.4;

/// @title Errors emitted by a pool
/// @notice Contains custom errors emitted by the pool
/// @dev Custom errors are separated from the common pool interface for compatibility with older versions of Solidity
interface IAlgebraPoolErrors {
  // ####  pool errors  ####

  /// @notice Emitted by the reentrancy guard
  error locked();

  /// @notice Emitted if arithmetic error occurred
  error arithmeticError();

  /// @notice Emitted if an attempt is made to initialize the pool twice
  error alreadyInitialized();

  /// @notice Emitted if an attempt is made to mint or swap in uninitialized pool
  error notInitialized();

  /// @notice Emitted if 0 is passed as amountRequired to swap function
  error zeroAmountRequired();

  /// @notice Emitted if invalid amount is passed as amountRequired to swap function
  error invalidAmountRequired();

  /// @notice Emitted if the pool received fewer tokens than it should have
  error insufficientInputAmount();

  /// @notice Emitted if there was an attempt to mint zero liquidity
  error zeroLiquidityDesired();
  /// @notice Emitted if actual amount of liquidity is zero (due to insufficient amount of tokens received)
  error zeroLiquidityActual();

  /// @notice Emitted if the pool received fewer tokens0 after flash than it should have
  error flashInsufficientPaid0();
  /// @notice Emitted if the pool received fewer tokens1 after flash than it should have
  error flashInsufficientPaid1();

  /// @notice Emitted if limitSqrtPrice param is incorrect
  error invalidLimitSqrtPrice();

  /// @notice Tick must be divisible by tickspacing
  error tickIsNotSpaced();

  /// @notice Emitted if a method is called that is accessible only to the factory owner or dedicated role
  error notAllowed();

  /// @notice Emitted if new tick spacing exceeds max allowed value
  error invalidNewTickSpacing();
  /// @notice Emitted if new community fee exceeds max allowed value
  error invalidNewCommunityFee();

  /// @notice Emitted if an attempt is made to manually change the fee value, but dynamic fee is enabled
  error dynamicFeeActive();
  /// @notice Emitted if an attempt is made by plugin to change the fee value, but dynamic fee is disabled
  error dynamicFeeDisabled();
  /// @notice Emitted if an attempt is made to change the plugin configuration, but the plugin is not connected
  error pluginIsNotConnected();
  /// @notice Emitted if a plugin returns invalid selector after hook call
  /// @param expectedSelector The expected selector
  error invalidHookResponse(bytes4 expectedSelector);

  // ####  LiquidityMath errors  ####

  /// @notice Emitted if liquidity underflows
  error liquiditySub();
  /// @notice Emitted if liquidity overflows
  error liquidityAdd();

  // ####  TickManagement errors  ####

  /// @notice Emitted if the topTick param not greater then the bottomTick param
  error topTickLowerOrEqBottomTick();
  /// @notice Emitted if the bottomTick param is lower than min allowed value
  error bottomTickLowerThanMIN();
  /// @notice Emitted if the topTick param is greater than max allowed value
  error topTickAboveMAX();
  /// @notice Emitted if the liquidity value associated with the tick exceeds MAX_LIQUIDITY_PER_TICK
  error liquidityOverflow();
  /// @notice Emitted if an attempt is made to interact with an uninitialized tick
  error tickIsNotInitialized();
  /// @notice Emitted if there is an attempt to insert a new tick into the list of ticks with incorrect indexes of the previous and next ticks
  error tickInvalidLinks();

  // ####  SafeTransfer errors  ####

  /// @notice Emitted if token transfer failed internally
  error transferFailed();

  // ####  TickMath errors  ####

  /// @notice Emitted if tick is greater than the maximum or less than the minimum allowed value
  error tickOutOfRange();
  /// @notice Emitted if price is greater than the maximum or less than the minimum allowed value
  error priceOutOfRange();
}

File 8 of 60 : IAlgebraPoolEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Events emitted by a pool
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolEvents {
  /// @notice Emitted exactly once by a pool when #initialize is first called on the pool
  /// @dev Mint/Burn/Swaps cannot be emitted by the pool before Initialize
  /// @param price 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 price, 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 bottomTick The lower tick of the position
  /// @param topTick The upper tick of the position
  /// @param liquidityAmount 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 bottomTick,
    int24 indexed topTick,
    uint128 liquidityAmount,
    uint256 amount0,
    uint256 amount1
  );

  /// @notice Emitted when fees are collected by the owner of a position
  /// @param owner The owner of the position for which fees are collected
  /// @param recipient The address that received fees
  /// @param bottomTick The lower tick of the position
  /// @param topTick 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 bottomTick, int24 indexed topTick, 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 bottomTick The lower tick of the position
  /// @param topTick The upper tick of the position
  /// @param liquidityAmount 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 bottomTick, int24 indexed topTick, uint128 liquidityAmount, 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 price 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 price, 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 when the community fee is changed by the pool
  /// @param communityFeeNew The updated value of the community fee in thousandths (1e-3)
  event CommunityFee(uint16 communityFeeNew);

  /// @notice Emitted when the tick spacing changes
  /// @param newTickSpacing The updated value of the new tick spacing
  event TickSpacing(int24 newTickSpacing);

  /// @notice Emitted when the plugin address changes
  /// @param newPluginAddress New plugin address
  event Plugin(address newPluginAddress);

  /// @notice Emitted when the plugin config changes
  /// @param newPluginConfig New plugin config
  event PluginConfig(uint8 newPluginConfig);

  /// @notice Emitted when the fee changes inside the pool
  /// @param fee The current fee in hundredths of a bip, i.e. 1e-6
  event Fee(uint16 fee);

  event CommunityVault(address newCommunityVault);
}

File 9 of 60 : IAlgebraPoolImmutables.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that never changes
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolImmutables {
  /// @notice The Algebra factory contract, which must adhere to the IAlgebraFactory 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 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 10 of 60 : IAlgebraPoolPermissionedActions.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 permissioned addresses
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolPermissionedActions {
  /// @notice Set the community's % share of the fees. Only factory owner or POOLS_ADMINISTRATOR_ROLE role
  /// @param newCommunityFee The new community fee percent in thousandths (1e-3)
  function setCommunityFee(uint16 newCommunityFee) external;

  /// @notice Set the new tick spacing values. Only factory owner or POOLS_ADMINISTRATOR_ROLE role
  /// @param newTickSpacing The new tick spacing value
  function setTickSpacing(int24 newTickSpacing) external;

  /// @notice Set the new plugin address. Only factory owner or POOLS_ADMINISTRATOR_ROLE role
  /// @param newPluginAddress The new plugin address
  function setPlugin(address newPluginAddress) external;

  /// @notice Set new plugin config. Only factory owner or POOLS_ADMINISTRATOR_ROLE role
  /// @param newConfig In the new configuration of the plugin,
  /// each bit of which is responsible for a particular hook.
  function setPluginConfig(uint8 newConfig) external;

  /// @notice Set new community fee vault address. Only factory owner or POOLS_ADMINISTRATOR_ROLE role
  /// @dev Community fee vault receives collected community fees.
  /// **accumulated but not yet sent to the vault community fees once will be sent to the `newCommunityVault` address**
  /// @param newCommunityVault The address of new community fee vault
  function setCommunityVault(address newCommunityVault) external;

  /// @notice Set new pool fee. Can be called by owner if dynamic fee is disabled.
  /// Called by the plugin if dynamic fee is enabled
  /// @param newFee The new fee value
  function setFee(uint16 newFee) external;
}

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

/// @title Pool state that can change
/// @dev Important security note: when using this data by external contracts, it is necessary to take into account the possibility
/// of manipulation (including read-only reentrancy).
/// This interface is based on the UniswapV3 interface, credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolState {
  /// @notice Safely get most important state values of Algebra Integral AMM
  /// @dev Several values exposed as a single method to save gas when accessed externally.
  /// **Important security note: this method checks reentrancy lock and should be preferred in most cases**.
  /// @return sqrtPrice The current price of the pool as a sqrt(dToken1/dToken0) Q64.96 value
  /// @return tick The current global tick of the pool. May not always be equal to SqrtTickMath.getTickAtSqrtRatio(price) if the price is on a tick boundary
  /// @return lastFee The current (last known) pool fee value in hundredths of a bip, i.e. 1e-6 (so '100' is '0.01%'). May be obsolete if using dynamic fee plugin
  /// @return pluginConfig The current plugin config as bitmap. Each bit is responsible for enabling/disabling the hooks, the last bit turns on/off dynamic fees logic
  /// @return activeLiquidity  The currently in-range liquidity available to the pool
  /// @return nextTick The next initialized tick after current global tick
  /// @return previousTick The previous initialized tick before (or at) current global tick
  function safelyGetStateOfAMM()
    external
    view
    returns (uint160 sqrtPrice, int24 tick, uint16 lastFee, uint8 pluginConfig, uint128 activeLiquidity, int24 nextTick, int24 previousTick);

  /// @notice Allows to easily get current reentrancy lock status
  /// @dev can be used to prevent read-only reentrancy.
  /// This method just returns `globalState.unlocked` value
  /// @return unlocked Reentrancy lock flag, true if the pool currently is unlocked, otherwise - false
  function isUnlocked() external view returns (bool unlocked);

  // ! IMPORTANT security note: the pool state can be manipulated.
  // ! The following methods do not check reentrancy lock themselves.

  /// @notice The globalState structure in the pool stores many values but requires only one slot
  /// and is exposed as a single method to save gas when accessed externally.
  /// @dev **important security note: caller should check `unlocked` flag to prevent read-only reentrancy**
  /// @return price The current price of the pool as a sqrt(dToken1/dToken0) 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(price) if the price is on a tick boundary
  /// @return lastFee The current (last known) pool fee value in hundredths of a bip, i.e. 1e-6 (so '100' is '0.01%'). May be obsolete if using dynamic fee plugin
  /// @return pluginConfig The current plugin config as bitmap. Each bit is responsible for enabling/disabling the hooks, the last bit turns on/off dynamic fees logic
  /// @return communityFee The community fee represented as a percent of all collected fee in thousandths, i.e. 1e-3 (so 100 is 10%)
  /// @return unlocked Reentrancy lock flag, true if the pool currently is unlocked, otherwise - false
  function globalState() external view returns (uint160 price, int24 tick, uint16 lastFee, uint8 pluginConfig, uint16 communityFee, bool unlocked);

  /// @notice Look up information about a specific tick in the pool
  /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy**
  /// @param tick The tick to look up
  /// @return liquidityTotal The total amount of position liquidity that uses the pool either as tick lower or tick upper
  /// @return liquidityDelta How much liquidity changes when the pool price crosses the tick
  /// @return prevTick The previous tick in tick list
  /// @return nextTick The next tick in tick list
  /// @return outerFeeGrowth0Token The fee growth on the other side of the tick from the current tick in token0
  /// @return outerFeeGrowth1Token The fee growth on the other side of the tick from the current tick in token1
  /// 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 (
      uint256 liquidityTotal,
      int128 liquidityDelta,
      int24 prevTick,
      int24 nextTick,
      uint256 outerFeeGrowth0Token,
      uint256 outerFeeGrowth1Token
    );

  /// @notice The timestamp of the last sending of tokens to community vault
  /// @return The timestamp truncated to 32 bits
  function communityFeeLastTimestamp() external view returns (uint32);

  /// @notice The amounts of token0 and token1 that will be sent to the vault
  /// @dev Will be sent COMMUNITY_FEE_TRANSFER_FREQUENCY after communityFeeLastTimestamp
  /// @return communityFeePending0 The amount of token0 that will be sent to the vault
  /// @return communityFeePending1 The amount of token1 that will be sent to the vault
  function getCommunityFeePending() external view returns (uint128 communityFeePending0, uint128 communityFeePending1);

  /// @notice Returns the address of currently used plugin
  /// @dev The plugin is subject to change
  /// @return pluginAddress The address of currently used plugin
  function plugin() external view returns (address pluginAddress);

  /// @notice The contract to which community fees are transferred
  /// @return communityVaultAddress The communityVault address
  function communityVault() external view returns (address communityVaultAddress);

  /// @notice Returns 256 packed tick initialized boolean values. See TickTree for more information
  /// @param wordPosition Index of 256-bits word with ticks
  /// @return The 256-bits word with packed ticks info
  function tickTable(int16 wordPosition) external view returns (uint256);

  /// @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
  /// @return The fee growth accumulator for token0
  function totalFeeGrowth0Token() 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
  /// @return The fee growth accumulator for token1
  function totalFeeGrowth1Token() external view returns (uint256);

  /// @notice The current pool fee value
  /// @dev In case dynamic fee is enabled in the pool, this method will call the plugin to get the current fee.
  /// If the plugin implements complex fee logic, this method may return an incorrect value or revert.
  /// In this case, see the plugin implementation and related documentation.
  /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy**
  /// @return currentFee The current pool fee value in hundredths of a bip, i.e. 1e-6
  function fee() external view returns (uint16 currentFee);

  /// @notice The tracked token0 and token1 reserves of pool
  /// @dev If at any time the real balance is larger, the excess will be transferred to liquidity providers as additional fee.
  /// If the balance exceeds uint128, the excess will be sent to the communityVault.
  /// @return reserve0 The last known reserve of token0
  /// @return reserve1 The last known reserve of token1
  function getReserves() external view returns (uint128 reserve0, uint128 reserve1);

  /// @notice Returns the information about a position by the position's key
  /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy**
  /// @param key The position's key is a packed concatenation of the owner address, bottomTick and topTick indexes
  /// @return liquidity The amount of liquidity in the position
  /// @return innerFeeGrowth0Token Fee growth of token0 inside the tick range as of the last mint/burn/poke
  /// @return innerFeeGrowth1Token Fee growth of token1 inside the tick range as of the last mint/burn/poke
  /// @return fees0 The computed amount of token0 owed to the position as of the last mint/burn/poke
  /// @return fees1 The computed amount of token1 owed to the position as of the last mint/burn/poke
  function positions(
    bytes32 key
  ) external view returns (uint256 liquidity, uint256 innerFeeGrowth0Token, uint256 innerFeeGrowth1Token, uint128 fees0, uint128 fees1);

  /// @notice The currently in range liquidity available to the pool
  /// @dev This value has no relationship to the total liquidity across all ticks.
  /// Returned value cannot exceed type(uint128).max
  /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy**
  /// @return The current in range liquidity
  function liquidity() external view returns (uint128);

  /// @notice The current tick spacing
  /// @dev Ticks can only be initialized by new mints at multiples of this value
  /// e.g.: a tickSpacing of 60 means ticks can be initialized every 60th tick, i.e., ..., -120, -60, 0, 60, 120, ...
  /// However, tickspacing can be changed after the ticks have been initialized.
  /// This value is an int24 to avoid casting even though it is always positive.
  /// @return The current tick spacing
  function tickSpacing() external view returns (int24);

  /// @notice The previous initialized tick before (or at) current global tick
  /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy**
  /// @return The previous initialized tick
  function prevTickGlobal() external view returns (int24);

  /// @notice The next initialized tick after current global tick
  /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy**
  /// @return The next initialized tick
  function nextTickGlobal() external view returns (int24);

  /// @notice The root of tick search tree
  /// @dev Each bit corresponds to one node in the second layer of tick tree: '1' if node has at least one active bit.
  /// **important security note: caller should check reentrancy lock to prevent read-only reentrancy**
  /// @return The root of tick search tree as bitmap
  function tickTreeRoot() external view returns (uint32);

  /// @notice The second layer of tick search tree
  /// @dev Each bit in node corresponds to one node in the leafs layer (`tickTable`) of tick tree: '1' if leaf has at least one active bit.
  /// **important security note: caller should check reentrancy lock to prevent read-only reentrancy**
  /// @return The node of tick search tree second layer
  function tickTreeSecondLayer(int16) external view returns (uint256);
}

File 12 of 60 : IAlgebraVaultFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title The interface for the Algebra Vault Factory
/// @notice This contract can be used for automatic vaults creation
/// @dev Version: Algebra Integral
interface IAlgebraVaultFactory {
  /// @notice returns address of the community fee vault for the pool
  /// @param pool the address of Algebra Integral pool
  /// @return communityFeeVault the address of community fee vault
  function getVaultForPool(address pool) external view returns (address communityFeeVault);

  /// @notice creates the community fee vault for the pool if needed
  /// @param pool the address of Algebra Integral pool
  /// @return communityFeeVault the address of community fee vault
  function createVaultForPool(address pool) external returns (address communityFeeVault);
}

File 13 of 60 : Constants.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0 <0.9.0;

/// @title Contains common constants for Algebra contracts
/// @dev Constants moved to the library, not the base contract, to further emphasize their constant nature
library Constants {
  uint8 internal constant RESOLUTION = 96;
  uint256 internal constant Q96 = 1 << 96;
  uint256 internal constant Q128 = 1 << 128;

  uint24 internal constant FEE_DENOMINATOR = 1e6;
  uint16 internal constant FLASH_FEE = 0.01e4; // fee for flash loan in hundredths of a bip (0.01%)
  uint16 internal constant INIT_DEFAULT_FEE = 0.05e4; // init default fee value in hundredths of a bip (0.05%)
  uint16 internal constant MAX_DEFAULT_FEE = 5e4; // max default fee value in hundredths of a bip (5%)

  int24 internal constant INIT_DEFAULT_TICK_SPACING = 60;
  int24 internal constant MAX_TICK_SPACING = 500;
  int24 internal constant MIN_TICK_SPACING = 1;

  // the frequency with which the accumulated community fees are sent to the vault
  uint32 internal constant COMMUNITY_FEE_TRANSFER_FREQUENCY = 8 hours;

  // max(uint128) / (MAX_TICK - MIN_TICK)
  uint128 internal constant MAX_LIQUIDITY_PER_TICK = 191757638537527648490752896198553;

  uint16 internal constant MAX_COMMUNITY_FEE = 1e3; // 100%
  uint256 internal constant COMMUNITY_FEE_DENOMINATOR = 1e3;
  // role that can change settings in pools
  bytes32 internal constant POOLS_ADMINISTRATOR_ROLE = keccak256('POOLS_ADMINISTRATOR');
}

File 14 of 60 : FullMath.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

  /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
  /// @param a The multiplicand
  /// @param b The multiplier
  /// @param denominator The divisor
  /// @return result The 256-bit result
  function mulDivRoundingUp(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
    unchecked {
      if (a == 0 || ((result = a * b) / a == b)) {
        require(denominator > 0);
        assembly {
          result := add(div(result, denominator), gt(mod(result, denominator), 0))
        }
      } else {
        result = mulDiv(a, b, denominator);
        if (mulmod(a, b, denominator) > 0) {
          require(result < type(uint256).max);
          result++;
        }
      }
    }
  }

  /// @notice Returns ceil(x / y)
  /// @dev division by 0 has unspecified behavior, and must be checked externally
  /// @param x The dividend
  /// @param y The divisor
  /// @return z The quotient, ceil(x / y)
  function unsafeDivRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
    assembly {
      z := add(div(x, y), gt(mod(x, y), 0))
    }
  }
}

File 15 of 60 : TickMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.4 <0.9.0;

import '../interfaces/pool/IAlgebraPoolErrors.sol';

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries
library TickMath {
  /// @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 price 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 price) {
    unchecked {
      // get abs value
      int24 absTickMask = tick >> (24 - 1);
      uint256 absTick = uint24((tick + absTickMask) ^ absTickMask);
      if (absTick > uint24(MAX_TICK)) revert IAlgebraPoolErrors.tickOutOfRange();

      uint256 ratio = 0x100000000000000000000000000000000;
      if (absTick & 0x1 != 0) ratio = 0xfffcb933bd6fad37aa2d162d1a594001;
      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) {
        if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
        if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;
      }

      if (tick > 0) {
        assembly {
          ratio := div(not(0), 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
      price = uint160((ratio + 0xFFFFFFFF) >> 32);
    }
  }

  /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
  /// @dev Throws in case price < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
  /// ever return.
  /// @param price 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 price) internal pure returns (int24 tick) {
    unchecked {
      // second inequality must be >= because the price can never reach the price at the max tick
      if (price < MIN_SQRT_RATIO || price >= MAX_SQRT_RATIO) revert IAlgebraPoolErrors.priceOutOfRange();
      uint256 ratio = uint256(price) << 32;

      uint256 r = ratio;
      uint256 msb;

      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) <= price ? tickHi : tickLow;
    }
  }
}

File 16 of 60 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

// EIP-2612 is Final as of 2022-11-01. This file is deprecated.

import "./IERC20Permit.sol";

File 17 of 60 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (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.
 */
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].
     */
    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 18 of 60 : 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 19 of 60 : ERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/ERC721.sol)

pragma solidity ^0.8.0;

import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
    using Address for address;
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to owner address
    mapping(uint256 => address) private _owners;

    // Mapping owner address to token count
    mapping(address => uint256) private _balances;

    // Mapping from token ID to approved address
    mapping(uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: address zero is not a valid owner");
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _ownerOf(tokenId);
        require(owner != address(0), "ERC721: invalid token ID");
        return owner;
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        _requireMinted(tokenId);

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overridden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not token owner or approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        _requireMinted(tokenId);

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(address from, address to, uint256 tokenId) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
        _safeTransfer(from, to, tokenId, data);
    }

    /**
     * @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.
     *
     * `data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
     */
    function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
        return _owners[tokenId];
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return _ownerOf(tokenId) != address(0);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
        _mint(to, tokenId);
        require(
            _checkOnERC721Received(address(0), to, tokenId, data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId, 1);

        // Check that tokenId was not minted by `_beforeTokenTransfer` hook
        require(!_exists(tokenId), "ERC721: token already minted");

        unchecked {
            // Will not overflow unless all 2**256 token ids are minted to the same owner.
            // Given that tokens are minted one by one, it is impossible in practice that
            // this ever happens. Might change if we allow batch minting.
            // The ERC fails to describe this case.
            _balances[to] += 1;
        }

        _owners[tokenId] = to;

        emit Transfer(address(0), to, tokenId);

        _afterTokenTransfer(address(0), to, tokenId, 1);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     * This is an internal function that does not check if the sender is authorized to operate on the token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId);

        _beforeTokenTransfer(owner, address(0), tokenId, 1);

        // Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook
        owner = ERC721.ownerOf(tokenId);

        // Clear approvals
        delete _tokenApprovals[tokenId];

        unchecked {
            // Cannot overflow, as that would require more tokens to be burned/transferred
            // out than the owner initially received through minting and transferring in.
            _balances[owner] -= 1;
        }
        delete _owners[tokenId];

        emit Transfer(owner, address(0), tokenId);

        _afterTokenTransfer(owner, address(0), tokenId, 1);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(address from, address to, uint256 tokenId) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId, 1);

        // Check that tokenId was not transferred by `_beforeTokenTransfer` hook
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");

        // Clear approvals from the previous owner
        delete _tokenApprovals[tokenId];

        unchecked {
            // `_balances[from]` cannot overflow for the same reason as described in `_burn`:
            // `from`'s balance is the number of token held, which is at least one before the current
            // transfer.
            // `_balances[to]` could overflow in the conditions described in `_mint`. That would require
            // all 2**256 token ids to be minted, which in practice is impossible.
            _balances[from] -= 1;
            _balances[to] += 1;
        }
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);

        _afterTokenTransfer(from, to, tokenId, 1);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits an {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits an {ApprovalForAll} event.
     */
    function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
        require(owner != operator, "ERC721: approve to caller");
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Reverts if the `tokenId` has not been minted yet.
     */
    function _requireMinted(uint256 tokenId) internal view virtual {
        require(_exists(tokenId), "ERC721: invalid token ID");
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory data
    ) private returns (bool) {
        if (to.isContract()) {
            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
                return retval == IERC721Receiver.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert("ERC721: transfer to non ERC721Receiver implementer");
                } else {
                    /// @solidity memory-safe-assembly
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } else {
            return true;
        }
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting and burning. If {ERC721Consecutive} is
     * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.
     * - When `from` is zero, the tokens will be minted for `to`.
     * - When `to` is zero, ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     * - `batchSize` is non-zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}

    /**
     * @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is
     * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.
     * - When `from` is zero, the tokens were minted for `to`.
     * - When `to` is zero, ``from``'s tokens were burned.
     * - `from` and `to` are never both zero.
     * - `batchSize` is non-zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}

    /**
     * @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
     *
     * WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariant
     * being that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens such
     * that `ownerOf(tokenId)` is `a`.
     */
    // solhint-disable-next-line func-name-mixedcase
    function __unsafe_increaseBalance(address account, uint256 amount) internal {
        _balances[account] += amount;
    }
}

File 20 of 60 : ERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/extensions/ERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "../ERC721.sol";
import "./IERC721Enumerable.sol";

/**
 * @dev This implements an optional extension of {ERC721} defined in the EIP that adds
 * enumerability of all the token ids in the contract as well as all token ids owned by each
 * account.
 */
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
    // Mapping from owner to list of owned token IDs
    mapping(address => mapping(uint256 => uint256)) private _ownedTokens;

    // Mapping from token ID to index of the owner tokens list
    mapping(uint256 => uint256) private _ownedTokensIndex;

    // Array with all token ids, used for enumeration
    uint256[] private _allTokens;

    // Mapping from token id to position in the allTokens array
    mapping(uint256 => uint256) private _allTokensIndex;

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
        return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
        require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
        return _ownedTokens[owner][index];
    }

    /**
     * @dev See {IERC721Enumerable-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _allTokens.length;
    }

    /**
     * @dev See {IERC721Enumerable-tokenByIndex}.
     */
    function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
        require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
        return _allTokens[index];
    }

    /**
     * @dev See {ERC721-_beforeTokenTransfer}.
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 firstTokenId,
        uint256 batchSize
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, firstTokenId, batchSize);

        if (batchSize > 1) {
            // Will only trigger during construction. Batch transferring (minting) is not available afterwards.
            revert("ERC721Enumerable: consecutive transfers not supported");
        }

        uint256 tokenId = firstTokenId;

        if (from == address(0)) {
            _addTokenToAllTokensEnumeration(tokenId);
        } else if (from != to) {
            _removeTokenFromOwnerEnumeration(from, tokenId);
        }
        if (to == address(0)) {
            _removeTokenFromAllTokensEnumeration(tokenId);
        } else if (to != from) {
            _addTokenToOwnerEnumeration(to, tokenId);
        }
    }

    /**
     * @dev Private function to add a token to this extension's ownership-tracking data structures.
     * @param to address representing the new owner of the given token ID
     * @param tokenId uint256 ID of the token to be added to the tokens list of the given address
     */
    function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
        uint256 length = ERC721.balanceOf(to);
        _ownedTokens[to][length] = tokenId;
        _ownedTokensIndex[tokenId] = length;
    }

    /**
     * @dev Private function to add a token to this extension's token tracking data structures.
     * @param tokenId uint256 ID of the token to be added to the tokens list
     */
    function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
        _allTokensIndex[tokenId] = _allTokens.length;
        _allTokens.push(tokenId);
    }

    /**
     * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
     * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
     * gas optimizations e.g. when performing a transfer operation (avoiding double writes).
     * This has O(1) time complexity, but alters the order of the _ownedTokens array.
     * @param from address representing the previous owner of the given token ID
     * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
     */
    function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
        // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
        // then delete the last slot (swap and pop).

        uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
        uint256 tokenIndex = _ownedTokensIndex[tokenId];

        // When the token to delete is the last token, the swap operation is unnecessary
        if (tokenIndex != lastTokenIndex) {
            uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];

            _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
            _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
        }

        // This also deletes the contents at the last position of the array
        delete _ownedTokensIndex[tokenId];
        delete _ownedTokens[from][lastTokenIndex];
    }

    /**
     * @dev Private function to remove a token from this extension's token tracking data structures.
     * This has O(1) time complexity, but alters the order of the _allTokens array.
     * @param tokenId uint256 ID of the token to be removed from the tokens list
     */
    function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
        // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
        // then delete the last slot (swap and pop).

        uint256 lastTokenIndex = _allTokens.length - 1;
        uint256 tokenIndex = _allTokensIndex[tokenId];

        // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
        // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
        // an 'if' statement (like in _removeTokenFromOwnerEnumeration)
        uint256 lastTokenId = _allTokens[lastTokenIndex];

        _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
        _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index

        // This also deletes the contents at the last position of the array
        delete _allTokensIndex[tokenId];
        _allTokens.pop();
    }
}

File 21 of 60 : 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 22 of 60 : 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 23 of 60 : 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 24 of 60 : 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 25 of 60 : 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 26 of 60 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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;
    }
}

File 27 of 60 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 28 of 60 : 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);
}

File 29 of 60 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

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

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

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

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

File 30 of 60 : SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

File 31 of 60 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 32 of 60 : BlockTimestamp.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.20;

/// @title Function for getting block timestamp
/// @dev Base contract that is overridden for tests
abstract contract BlockTimestamp {
    /// @dev Method that exists purely to be overridden for tests
    /// @return The current block timestamp
    function _blockTimestamp() internal view virtual returns (uint256) {
        return block.timestamp;
    }
}

File 33 of 60 : ERC721Permit.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.20;

import '@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol';
import '@openzeppelin/contracts/utils/Address.sol';

import '../interfaces/external/IERC1271.sol';
import '../interfaces/IERC721Permit.sol';
import './BlockTimestamp.sol';

/// @title ERC721 with permit
/// @notice Nonfungible tokens that support an approve via signature, i.e. permit
abstract contract ERC721Permit is BlockTimestamp, ERC721Enumerable, IERC721Permit {
    bytes32 private constant _TYPE_HASH =
        keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)');

    /// @dev Gets the current nonce for a token ID and then increments it, returning the original value
    function _getAndIncrementNonce(uint256 tokenId) internal virtual returns (uint256);

    /// @dev The hash of the name used in the permit signature verification
    bytes32 private immutable nameHash;

    /// @dev The hash of the version string used in the permit signature verification
    bytes32 private immutable versionHash;

    bytes32 private immutable _cachedDomainSeparator;
    uint256 private immutable _cachedChainId;
    address private immutable _cachedThis;

    /// @notice Computes the nameHash and versionHash
    constructor(string memory name_, string memory symbol_, string memory version_) ERC721(name_, symbol_) {
        nameHash = keccak256(bytes(name_));
        versionHash = keccak256(bytes(version_));

        _cachedChainId = block.chainid;
        _cachedDomainSeparator = _buildDomainSeparator();
        _cachedThis = address(this);
    }

    /// @inheritdoc IERC721Permit
    function DOMAIN_SEPARATOR() public view override returns (bytes32) {
        if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
            return _cachedDomainSeparator;
        } else {
            return _buildDomainSeparator();
        }
    }

    function _buildDomainSeparator() private view returns (bytes32) {
        return keccak256(abi.encode(_TYPE_HASH, nameHash, versionHash, block.chainid, address(this)));
    }

    /// @inheritdoc IERC721Permit
    bytes32 public constant override PERMIT_TYPEHASH =
        keccak256('Permit(address spender,uint256 tokenId,uint256 nonce,uint256 deadline)');

    /// @inheritdoc IERC721Permit
    function permit(
        address spender,
        uint256 tokenId,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable override {
        require(_blockTimestamp() <= deadline, 'Permit expired');

        bytes32 digest = keccak256(
            abi.encodePacked(
                '\x19\x01',
                DOMAIN_SEPARATOR(),
                keccak256(abi.encode(PERMIT_TYPEHASH, spender, tokenId, _getAndIncrementNonce(tokenId), deadline))
            )
        );
        address owner = ownerOf(tokenId);
        require(spender != owner, 'ERC721Permit: approval to current owner');

        if (Address.isContract(owner)) {
            _checkAuthorization(IERC1271(owner).isValidSignature(digest, abi.encodePacked(r, s, v)) == 0x1626ba7e);
        } else {
            address recoveredAddress = ecrecover(digest, v, r, s);
            require(recoveredAddress != address(0), 'Invalid signature');
            _checkAuthorization(recoveredAddress == owner);
        }

        _approve(spender, tokenId);
    }

    function _checkAuthorization(bool isAuthorized) private pure {
        require(isAuthorized, 'Unauthorized');
    }
}

File 34 of 60 : LiquidityManagement.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.20;

import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraFactory.sol';
import '@cryptoalgebra/integral-core/contracts/interfaces/callback/IAlgebraMintCallback.sol';
import '@cryptoalgebra/integral-core/contracts/libraries/TickMath.sol';

import '../libraries/PoolAddress.sol';
import '../libraries/CallbackValidation.sol';
import '../libraries/LiquidityAmounts.sol';

import '../libraries/PoolInteraction.sol';

import './PeripheryPayments.sol';
import './PeripheryImmutableState.sol';

/// @title Liquidity management functions
/// @notice Internal functions for safely managing liquidity in Algebra
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
abstract contract LiquidityManagement is IAlgebraMintCallback, PeripheryImmutableState, PeripheryPayments {
    using PoolInteraction for IAlgebraPool;
    struct MintCallbackData {
        PoolAddress.PoolKey poolKey;
        address payer;
    }

    /// @inheritdoc IAlgebraMintCallback
    function algebraMintCallback(uint256 amount0Owed, uint256 amount1Owed, bytes calldata data) external override {
        MintCallbackData memory decoded = abi.decode(data, (MintCallbackData));
        CallbackValidation.verifyCallback(poolDeployer, decoded.poolKey);

        if (amount0Owed > 0) pay(decoded.poolKey.token0, decoded.payer, msg.sender, amount0Owed);
        if (amount1Owed > 0) pay(decoded.poolKey.token1, decoded.payer, msg.sender, amount1Owed);
    }

    struct AddLiquidityParams {
        address token0;
        address token1;
        address recipient;
        int24 tickLower;
        int24 tickUpper;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
    }

    /// @notice Add liquidity to an initialized pool
    function addLiquidity(
        AddLiquidityParams memory params
    )
        internal
        returns (uint128 liquidity, uint128 actualLiquidity, uint256 amount0, uint256 amount1, IAlgebraPool pool)
    {
        PoolAddress.PoolKey memory poolKey = PoolAddress.PoolKey({token0: params.token0, token1: params.token1});

        pool = IAlgebraPool(PoolAddress.computeAddress(poolDeployer, poolKey));

        // compute the liquidity amount
        {
            uint160 sqrtPriceX96 = pool._getSqrtPrice();
            uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(params.tickLower);
            uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(params.tickUpper);

            liquidity = LiquidityAmounts.getLiquidityForAmounts(
                sqrtPriceX96,
                sqrtRatioAX96,
                sqrtRatioBX96,
                params.amount0Desired,
                params.amount1Desired
            );
        }

        (amount0, amount1, actualLiquidity) = pool.mint(
            msg.sender,
            params.recipient,
            params.tickLower,
            params.tickUpper,
            liquidity,
            abi.encode(MintCallbackData({poolKey: poolKey, payer: msg.sender}))
        );

        require(amount0 >= params.amount0Min && amount1 >= params.amount1Min, 'Price slippage check');
    }
}

File 35 of 60 : Multicall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.20;

import '../interfaces/IMulticall.sol';

/// @title Multicall
/// @notice Enables calling multiple methods in a single call to the contract
abstract contract Multicall is IMulticall {
    /// @inheritdoc IMulticall
    function multicall(bytes[] calldata data) external payable override returns (bytes[] memory results) {
        results = new bytes[](data.length);
        unchecked {
            for (uint256 i = 0; i < data.length; i++) {
                (bool success, bytes memory result) = address(this).delegatecall(data[i]);
                if (!success) {
                    // Look for revert reason and bubble it up if present
                    require(result.length > 0);
                    // The easiest way to bubble the revert reason is using memory via assembly
                    assembly ('memory-safe') {
                        revert(add(32, result), mload(result))
                    }
                }
                results[i] = result;
            }
        }
    }
}

File 36 of 60 : PeripheryImmutableState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.20;

import '../interfaces/IPeripheryImmutableState.sol';

/// @title Immutable state
/// @notice Immutable state used by periphery contracts
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
abstract contract PeripheryImmutableState is IPeripheryImmutableState {
    /// @inheritdoc IPeripheryImmutableState
    address public immutable override factory;
    /// @inheritdoc IPeripheryImmutableState
    address public immutable override poolDeployer;
    /// @inheritdoc IPeripheryImmutableState
    address public immutable override WNativeToken;

    constructor(address _factory, address _WNativeToken, address _poolDeployer) {
        factory = _factory;
        poolDeployer = _poolDeployer;
        WNativeToken = _WNativeToken;
    }
}

File 37 of 60 : PeripheryPayments.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

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

import '../interfaces/IPeripheryPayments.sol';
import '../interfaces/external/IWNativeToken.sol';

import '../libraries/TransferHelper.sol';

import './PeripheryImmutableState.sol';

/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
abstract contract PeripheryPayments is IPeripheryPayments, PeripheryImmutableState {
    receive() external payable {
        require(msg.sender == WNativeToken, 'Not WNativeToken');
    }

    function _balanceOfToken(address token) private view returns (uint256) {
        return (IERC20(token).balanceOf(address(this)));
    }

    /// @inheritdoc IPeripheryPayments
    function unwrapWNativeToken(uint256 amountMinimum, address recipient) external payable override {
        uint256 balanceWNativeToken = _balanceOfToken(WNativeToken);
        require(balanceWNativeToken >= amountMinimum, 'Insufficient WNativeToken');

        if (balanceWNativeToken > 0) {
            IWNativeToken(WNativeToken).withdraw(balanceWNativeToken);
            TransferHelper.safeTransferNative(recipient, balanceWNativeToken);
        }
    }

    /// @inheritdoc IPeripheryPayments
    function sweepToken(address token, uint256 amountMinimum, address recipient) external payable override {
        uint256 balanceToken = _balanceOfToken(token);
        require(balanceToken >= amountMinimum, 'Insufficient token');

        if (balanceToken > 0) {
            TransferHelper.safeTransfer(token, recipient, balanceToken);
        }
    }

    /// @inheritdoc IPeripheryPayments
    function refundNativeToken() external payable override {
        if (address(this).balance > 0) TransferHelper.safeTransferNative(msg.sender, address(this).balance);
    }

    /// @param token The token to pay
    /// @param payer The entity that must pay
    /// @param recipient The entity that will receive payment
    /// @param value The amount to pay
    function pay(address token, address payer, address recipient, uint256 value) internal {
        if (token == WNativeToken && address(this).balance >= value) {
            // pay with WNativeToken
            // "address(this).balance >= value" may unexpectedly become false (including due to frontrun)
            // so this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of tokens
            IWNativeToken(WNativeToken).deposit{value: value}(); // wrap only what is needed to pay
            IWNativeToken(WNativeToken).transfer(recipient, value);
        } else if (payer == address(this)) {
            // pay with tokens already in the contract (for the exact input multihop case)
            TransferHelper.safeTransfer(token, recipient, value);
        } else {
            // pull payment
            TransferHelper.safeTransferFrom(token, payer, recipient, value);
        }
    }
}

File 38 of 60 : PeripheryValidation.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.20;

import './BlockTimestamp.sol';

/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
abstract contract PeripheryValidation is BlockTimestamp {
    modifier checkDeadline(uint256 deadline) {
        _checkDeadline(deadline);
        _;
    }

    function _checkDeadline(uint256 deadline) private view {
        require(_blockTimestamp() <= deadline, 'Transaction too old');
    }
}

File 39 of 60 : PoolInitializer.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.20;

import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraFactory.sol';
import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol';
import './PeripheryImmutableState.sol';
import '../interfaces/IPoolInitializer.sol';

import '../libraries/PoolInteraction.sol';

/// @title Creates and initializes Algebra Pools
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
abstract contract PoolInitializer is IPoolInitializer, PeripheryImmutableState {
    using PoolInteraction for IAlgebraPool;

    /// @inheritdoc IPoolInitializer
    function createAndInitializePoolIfNecessary(
        address token0,
        address token1,
        uint160 sqrtPriceX96
    ) external payable override returns (address pool) {
        require(token0 < token1, 'Invalid order of tokens');

        pool = IAlgebraFactory(factory).poolByPair(token0, token1);

        if (pool == address(0)) {
            pool = IAlgebraFactory(factory).createPool(token0, token1);

            _initializePool(pool, sqrtPriceX96);
        } else {
            uint160 sqrtPriceX96Existing = IAlgebraPool(pool)._getSqrtPrice();
            if (sqrtPriceX96Existing == 0) {
                _initializePool(pool, sqrtPriceX96);
            }
        }
    }

    function _initializePool(address pool, uint160 initPrice) private {
        IAlgebraPool(pool).initialize(initPrice);
    }
}

File 40 of 60 : SelfPermit.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol';

import '../interfaces/ISelfPermit.sol';
import '../interfaces/external/IERC20PermitAllowed.sol';

/// @title Self Permit
/// @notice Functionality to call permit on any EIP-2612-compliant token for use in the route
/// @dev These functions are expected to be embedded in multicalls to allow EOAs to approve a contract and call a function
/// that requires an approval in a single transaction.
abstract contract SelfPermit is ISelfPermit {
    /// @inheritdoc ISelfPermit
    function selfPermit(
        address token,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public payable override {
        IERC20Permit(token).permit(msg.sender, address(this), value, deadline, v, r, s);
    }

    /// @inheritdoc ISelfPermit
    function selfPermitIfNecessary(
        address token,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable override {
        if (_getAllowance(token) < value) selfPermit(token, value, deadline, v, r, s);
    }

    /// @inheritdoc ISelfPermit
    function selfPermitAllowed(
        address token,
        uint256 nonce,
        uint256 expiry,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public payable override {
        IERC20PermitAllowed(token).permit(msg.sender, address(this), nonce, expiry, true, v, r, s);
    }

    /// @inheritdoc ISelfPermit
    function selfPermitAllowedIfNecessary(
        address token,
        uint256 nonce,
        uint256 expiry,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable override {
        if (_getAllowance(token) < type(uint256).max) selfPermitAllowed(token, nonce, expiry, v, r, s);
    }

    function _getAllowance(address token) private view returns (uint256) {
        return IERC20(token).allowance(msg.sender, address(this));
    }
}

File 41 of 60 : IERC1271.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Interface for verifying contract-based account signatures
/// @notice Interface that verifies provided signature for the data
/// @dev Interface defined by EIP-1271
interface IERC1271 {
    /// @notice Returns whether the provided signature is valid for the provided data
    /// @dev MUST return the bytes4 magic value 0x1626ba7e when function passes.
    /// MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5).
    /// MUST allow external calls.
    /// @param hash Hash of the data to be signed
    /// @param signature Signature byte array associated with _data
    /// @return magicValue The bytes4 magic value 0x1626ba7e
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}

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

/// @title Interface for permit
/// @notice Interface used by DAI/CHAI for permit
interface IERC20PermitAllowed {
    /// @notice Approve the spender to spend some tokens via the holder signature
    /// @dev This is the permit interface used by DAI and CHAI
    /// @param holder The address of the token holder, the token owner
    /// @param spender The address of the token spender
    /// @param nonce The holder's nonce, increases at each call to permit
    /// @param expiry The timestamp at which the permit is no longer valid
    /// @param allowed Boolean that sets approval amount, true for type(uint256).max and false for 0
    /// @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 holder,
        address spender,
        uint256 nonce,
        uint256 expiry,
        bool allowed,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
}

File 43 of 60 : IVolatilityOracle.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title The interface for the Algebra volatility oracle
/// @dev This contract stores timepoints and calculates statistical averages
interface IVolatilityOracle {
    /// @notice Returns the accumulator values as of each time seconds ago from the given time in the array of `secondsAgos`
    /// @dev Reverts if `secondsAgos` > oldest timepoint
    /// @dev `volatilityCumulative` values for timestamps after the last timepoint _should not_ be compared because they may differ due to interpolation errors
    /// @param secondsAgos Each amount of time to look back, in seconds, at which point to return a timepoint
    /// @return tickCumulatives The cumulative tick since the pool was first initialized, as of each `secondsAgo`
    /// @return volatilityCumulatives The cumulative volatility values since the pool was first initialized, as of each `secondsAgo`
    function getTimepoints(
        uint32[] memory secondsAgos
    ) external view returns (int56[] memory tickCumulatives, uint88[] memory volatilityCumulatives);
}

File 44 of 60 : IWNativeToken.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

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

/// @title Interface for WNativeToken
interface IWNativeToken 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 45 of 60 : 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 separator 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 46 of 60 : IMulticall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

/// @title Multicall interface
/// @notice Enables calling multiple methods in a single call to the contract
interface IMulticall {
    /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
    /// @dev The `msg.value` should not be trusted for any method callable from multicall.
    /// @param data The encoded function data for each of the calls to make to this contract
    /// @return results The results from each of the calls passed in via data
    function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}

File 47 of 60 : 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';

/// @title Non-fungible token for positions
/// @notice Wraps Algebra positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
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 liquidityDesired The amount by which liquidity for the NFT position was increased
    /// @param actualLiquidity the actual liquidity that was added into a pool. Could differ from
    /// _liquidity_ when using FeeOnTransfer tokens
    /// @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 liquidityDesired,
        uint128 actualLiquidity,
        uint256 amount0,
        uint256 amount1,
        address pool
    );

    /// @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 withdrawalFeeliquidity Withdrawal fee liq
    /// @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,
        uint128 withdrawalFeeliquidity,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted when a fee vault is set for a pool
    /// @param pool The address of the pool to which the vault have been applied
    /// @param feeVault The address of the fee vault
    /// @param fee Percentage of withdrawal fee that will be sent to the vault
    event FeeVaultForPool(address pool, address feeVault, uint16 fee);

    /// @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 Emitted if farming failed in call from NonfungiblePositionManager.
    /// @dev Should never be emitted
    /// @param tokenId The ID of corresponding token
    event FarmingFailed(uint256 indexed tokenId);

    /// @notice Emitted after farming center address change
    /// @param farmingCenterAddress The new address of connected farming center
    event FarmingCenter(address farmingCenterAddress);

    /// @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 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 (
            uint88 nonce,
            address operator,
            address token0,
            address token1,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    struct MintParams {
        address token0;
        address token1;
        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.
    /// @dev If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens
    /// @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 liquidity delta amount as a result of the increase
    /// @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
    /// @dev If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens
    /// @return liquidity The liquidity delta amount as a result of the increase
    /// @return amount0 The amount of token0 to achieve resulting liquidity
    /// @return amount1 The amount of token1 to achieve 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;

    /// @notice Changes approval of token ID for farming.
    /// @param tokenId The ID of the token that is being approved / unapproved
    /// @param approve New status of approval
    /// @param farmingAddress The address of farming: used to prevent tx frontrun
    function approveForFarming(uint256 tokenId, bool approve, address farmingAddress) external payable;

    /// @notice Changes farming status of token to 'farmed' or 'not farmed'
    /// @dev can be called only by farmingCenter
    /// @param tokenId The ID of the token
    /// @param toActive The new status
    function switchFarmingStatus(uint256 tokenId, bool toActive) external;

    struct FeesVault {
        address feeVault;
        uint16 fee;
    }

    struct WithdrawalFeePoolParams {
        uint64 apr0;
        uint64 apr1;
        uint16 withdrawalFee;
        FeesVault[] feeVaults;
    }

    /// @notice Returns withdrawal fee params for pool
    /// @param pool Pool address
    /// @return params
    function getWithdrawalFeePoolParams(address pool) external view returns (WithdrawalFeePoolParams memory params);

    /// @notice Changes withdrawalFee for pool
    /// @dev can be called only by factory owner or NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE
    /// @param pool The address of the pool to which the settings have been applied
    /// @param newWithdrawalFee Percentage of lst token earnings that will be sent to the vault
    function setWithdrawalFee(address pool, uint16 newWithdrawalFee) external;

    /// @notice Changes tokens apr for pool
    /// @dev can be called only by factory owner or NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE
    /// @param pool The address of the pool to which the settings have been applied
    /// @param apr0 APR of LST token0
    /// @param apr1 APR of LST token1
    function setTokenAPR(address pool, uint64 apr0, uint64 apr1) external;

    /// @notice Changes fee vault for pool
    /// @dev can be called only by factory owner or NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE
    /// @param pool The address of the pool to which the settings have been applied
    /// @param fees array of fees values
    /// @param vaults array of vault addresses
    function setVaultsForPool(address pool, uint16[] memory fees, address[] memory vaults) external;

    /// @notice Returns vault address to which fees will be sent
    /// @return vault The actual vault address
    function defaultWithdrawalFeesVault() external view returns (address vault);

    /// @notice Changes vault address
    /// @dev can be called only by factory owner or NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE
    /// @param newVault The new address of vault
    function setVaultAddress(address newVault) external;

    /// @notice Returns withdrawalFee information associated with a given token ID
    /// @param tokenId The ID of the token that represents the position
    /// @return lastUpdateTimestamp Last increase/decrease liquidity timestamp
    /// @return withdrawalFeeLiquidity Liqudity of accumulated withdrawal fee
    function positionsWithdrawalFee(
        uint256 tokenId
    ) external view returns (uint32 lastUpdateTimestamp, uint128 withdrawalFeeLiquidity);

    /// @notice Changes address of farmingCenter
    /// @dev can be called only by factory owner or NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE
    /// @param newFarmingCenter The new address of farmingCenter
    function setFarmingCenter(address newFarmingCenter) external;

    /// @notice Returns whether `spender` is allowed to manage `tokenId`
    /// @dev Requirement: `tokenId` must exist
    function isApprovedOrOwner(address spender, uint256 tokenId) external view returns (bool);

    /// @notice Returns the address of currently connected farming, if any
    /// @return The address of the farming center contract, which handles farmings logic
    function farmingCenter() external view returns (address);

    /// @notice Returns the address of farming that is approved for this token, if any
    function farmingApprovals(uint256 tokenId) external view returns (address);

    /// @notice Returns the address of farming in which this token is farmed, if any
    function tokenFarmedIn(uint256 tokenId) external view returns (address);
}

File 48 of 60 : INonfungibleTokenPositionDescriptor.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import './INonfungiblePositionManager.sol';

/// @title Describes position NFT tokens via URI
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
interface INonfungibleTokenPositionDescriptor {
    /// @notice Produces the URI describing a particular token ID for a position manager
    /// @dev Note this URI may be a data: URI with the JSON contents directly inlined
    /// @param positionManager The position manager for which to describe the token
    /// @param tokenId The ID of the token for which to produce a description, which may not be valid
    /// @return The URI of the ERC721-compliant metadata
    function tokenURI(INonfungiblePositionManager positionManager, uint256 tokenId)
        external
        view
        returns (string memory);
}

File 49 of 60 : 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
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
interface IPeripheryImmutableState {
    /// @return Returns the address of the Algebra factory
    function factory() external view returns (address);

    /// @return Returns the address of the pool Deployer
    function poolDeployer() external view returns (address);

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

File 50 of 60 : 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 NativeToken
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
interface IPeripheryPayments {
    /// @notice Unwraps the contract's WNativeToken balance and sends it to recipient as NativeToken.
    /// @dev The amountMinimum parameter prevents malicious contracts from stealing WNativeToken from users.
    /// @param amountMinimum The minimum amount of WNativeToken to unwrap
    /// @param recipient The address receiving NativeToken
    function unwrapWNativeToken(uint256 amountMinimum, address recipient) external payable;

    /// @notice Refunds any NativeToken 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 refundNativeToken() 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 51 of 60 : IPoolInitializer.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

/// @title Creates and initializes Algebra Pools
/// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that
/// require the pool to exist.
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
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 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,
        uint160 sqrtPriceX96
    ) external payable returns (address pool);
}

File 52 of 60 : IPositionFollower.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Contract tracking liquidity position
/// @notice Using these methods farmingCenter receives information about changes in the positions
interface IPositionFollower {
    /// @notice Report a change of liquidity in position
    /// @param tokenId The ID of the token for which liquidity is being added
    /// @param liquidityDelta The amount of added liquidity
    function applyLiquidityDelta(uint256 tokenId, int256 liquidityDelta) external;
}

File 53 of 60 : ISelfPermit.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

/// @title Self Permit
/// @notice Functionality to call permit on any EIP-2612-compliant token for use in the route
interface ISelfPermit {
    /// @notice Permits this contract to spend a given token from `msg.sender`
    /// @dev The `owner` is always msg.sender and the `spender` is always address(this).
    /// @param token The address of the token spent
    /// @param value The amount that can be spent of token
    /// @param deadline A timestamp, the current blocktime must be less than or equal to this timestamp
    /// @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 selfPermit(
        address token,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable;

    /// @notice Permits this contract to spend a given token from `msg.sender`
    /// @dev The `owner` is always msg.sender and the `spender` is always address(this).
    /// Can be used instead of #selfPermit to prevent calls from failing due to a frontrun of a call to #selfPermit
    /// @param token The address of the token spent
    /// @param value The amount that can be spent of token
    /// @param deadline A timestamp, the current blocktime must be less than or equal to this timestamp
    /// @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 selfPermitIfNecessary(
        address token,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable;

    /// @notice Permits this contract to spend the sender's tokens for permit signatures that have the `allowed` parameter
    /// @dev The `owner` is always msg.sender and the `spender` is always address(this)
    /// @param token The address of the token spent
    /// @param nonce The current nonce of the owner
    /// @param expiry The timestamp at which the permit is no longer valid
    /// @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 selfPermitAllowed(
        address token,
        uint256 nonce,
        uint256 expiry,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable;

    /// @notice Permits this contract to spend the sender's tokens for permit signatures that have the `allowed` parameter
    /// @dev The `owner` is always msg.sender and the `spender` is always address(this)
    /// Can be used instead of #selfPermitAllowed to prevent calls from failing due to a frontrun of a call to #selfPermitAllowed.
    /// @param token The address of the token spent
    /// @param nonce The current nonce of the owner
    /// @param expiry The timestamp at which the permit is no longer valid
    /// @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 selfPermitAllowedIfNecessary(
        address token,
        uint256 nonce,
        uint256 expiry,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable;
}

File 54 of 60 : CallbackValidation.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol';
import './PoolAddress.sol';

/// @notice Provides validation for callbacks from Algebra Pools
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
library CallbackValidation {
    /// @notice Returns the address of a valid Algebra Pool
    /// @param poolDeployer The contract address of the Algebra pool deployer
    /// @param tokenA The contract address of either token0 or token1
    /// @param tokenB The contract address of the other token
    /// @return pool The Algebra pool contract address
    function verifyCallback(
        address poolDeployer,
        address tokenA,
        address tokenB
    ) internal view returns (IAlgebraPool pool) {
        return verifyCallback(poolDeployer, PoolAddress.getPoolKey(tokenA, tokenB));
    }

    /// @notice Returns the address of a valid Algebra Pool
    /// @param poolDeployer The contract address of the Algebra pool deployer
    /// @param poolKey The identifying key of the ALgebra pool
    /// @return pool The Algebra pool contract address
    function verifyCallback(
        address poolDeployer,
        PoolAddress.PoolKey memory poolKey
    ) internal view returns (IAlgebraPool pool) {
        pool = IAlgebraPool(PoolAddress.computeAddress(poolDeployer, poolKey));
        require(msg.sender == address(pool), 'Invalid caller of callback');
    }
}

File 55 of 60 : LiquidityAmounts.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import '@cryptoalgebra/integral-core/contracts/libraries/FullMath.sol';
import '@cryptoalgebra/integral-core/contracts/libraries/Constants.sol';

/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
library LiquidityAmounts {
    /// @notice Downcasts uint256 to uint128
    /// @param x The uint258 to be downcasted
    /// @return y The passed value, downcasted to uint128
    function toUint128(uint256 x) private pure returns (uint128 y) {
        require((y = uint128(x)) == x);
    }

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

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

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

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);
            uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);

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

    /// @notice Computes the amount of token0 for a given amount of liquidity and a price range
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount0 The amount of token0
    function getAmount0ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0) {
        unchecked {
            if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

            return
                FullMath.mulDiv(
                    uint256(liquidity) << Constants.RESOLUTION,
                    sqrtRatioBX96 - sqrtRatioAX96,
                    sqrtRatioBX96
                ) / sqrtRatioAX96;
        }
    }

    /// @notice Computes the amount of token1 for a given amount of liquidity and a price range
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount1 The amount of token1
    function getAmount1ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        unchecked {
            return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, Constants.Q96);
        }
    }

    /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current
    /// pool prices and the prices at the tick boundaries
    /// @param sqrtRatioX96 A sqrt price representing the current pool prices
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount0 The amount of token0
    /// @return amount1 The amount of token1
    function getAmountsForLiquidity(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0, uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity);
            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity);
        } else {
            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
        }
    }
}

File 56 of 60 : OracleLibrary.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.4;

import '../interfaces/external/IVolatilityOracle.sol';

/// @title Oracle library
/// @notice Provides functions to integrate with Algebra pool TWAP VolatilityOracle
library OracleLibrary {
    /// @notice Fetches time-weighted average tick using Algebra VolatilityOracle
    /// @param oracleAddress The address of oracle
    /// @param period Number of seconds in the past to start calculating time-weighted average
    /// @return timeWeightedAverageTick The time-weighted average tick from (block.timestamp - period) to block.timestamp
    function consult(address oracleAddress, uint32 period) internal view returns (int24 timeWeightedAverageTick) {
        require(period != 0, 'Period is zero');

        uint32[] memory secondAgos = new uint32[](2);
        secondAgos[0] = period;
        secondAgos[1] = 0;

        IVolatilityOracle oracle = IVolatilityOracle(oracleAddress);
        (int56[] memory tickCumulatives, ) = oracle.getTimepoints(secondAgos);
        int56 tickCumulativesDelta = tickCumulatives[1] - tickCumulatives[0];

        timeWeightedAverageTick = int24(tickCumulativesDelta / int56(uint56(period)));

        // Always round to negative infinity
        if (tickCumulativesDelta < 0 && (tickCumulativesDelta % int56(uint56(period)) != 0)) timeWeightedAverageTick--;
    }
}

File 57 of 60 : 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 poolDeployer and tokens
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
library PoolAddress {
    bytes32 internal constant POOL_INIT_CODE_HASH = 0xf96d2474815c32e070cd63233f06af5413efc5dcb430aee4ff18cc29007c562d;

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

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

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

File 58 of 60 : PoolInteraction.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.20;

import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol';

import './PositionKey.sol';

/// @title Implements commonly used interactions with Algebra pool
library PoolInteraction {
    function _getPositionInPool(
        IAlgebraPool pool,
        address owner,
        int24 tickLower,
        int24 tickUpper
    )
        internal
        view
        returns (
            uint256 liquidityAmount,
            uint256 innerFeeGrowth0Token,
            uint256 innerFeeGrowth1Token,
            uint128 fees0,
            uint128 fees1
        )
    {
        return pool.positions(PositionKey.compute(owner, tickLower, tickUpper));
    }

    function _getSqrtPrice(IAlgebraPool pool) internal view returns (uint160 sqrtPriceX96) {
        (sqrtPriceX96, , , , , ) = pool.globalState();
    }

    function _burnPositionInPool(
        IAlgebraPool pool,
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity
    ) internal returns (uint256 amount0, uint256 amount1) {
        return pool.burn(tickLower, tickUpper, liquidity, '0x0');
    }
}

File 59 of 60 : PositionKey.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

library PositionKey {
    /// @dev Returns the key of the position in the core library
    function compute(
        address owner,
        int24 bottomTick,
        int24 topTick
    ) internal pure returns (bytes32 key) {
        assembly {
            key := or(shl(24, or(shl(24, owner), and(bottomTick, 0xFFFFFF))), and(topTick, 0xFFFFFF))
        }
    }
}

File 60 of 60 : TransferHelper.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;

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

/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
library TransferHelper {
    /// @notice Transfers tokens from the targeted address to the given destination
    /// @notice Errors with 'STF' if transfer fails
    /// @param token The contract address of the token to be transferred
    /// @param from The originating address from which the tokens will be transferred
    /// @param to The destination address of the transfer
    /// @param value The amount to be transferred
    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value)
        );
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
    }

    /// @notice Transfers tokens from msg.sender to a recipient
    /// @dev Errors with ST if transfer fails
    /// @param token The contract address of the token which will be transferred
    /// @param to The recipient of the transfer
    /// @param value The value of the transfer
    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
    }

    /// @notice Approves the stipulated contract to spend the given allowance in the given token
    /// @dev Errors with 'SA' if transfer fails
    /// @param token The contract address of the token to be approved
    /// @param to The target of the approval
    /// @param value The amount of the given token the target will be allowed to spend
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
    }

    /// @notice Transfers NativeToken to the recipient address
    /// @dev Fails with `STE`
    /// @param to The destination of the transfer
    /// @param value The value to be transferred
    function safeTransferNative(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, 'STE');
    }
}

Settings
{
  "evmVersion": "paris",
  "viaIR": true,
  "optimizer": {
    "enabled": true,
    "runs": 0
  },
  "metadata": {
    "bytecodeHash": "none"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WNativeToken","type":"address"},{"internalType":"address","name":"_tokenDescriptor_","type":"address"},{"internalType":"address","name":"_poolDeployer","type":"address"},{"internalType":"address","name":"_vault","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"tickOutOfRange","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Collect","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"withdrawalFeeliquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"DecreaseLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"farmingCenterAddress","type":"address"}],"name":"FarmingCenter","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"FarmingFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"address","name":"feeVault","type":"address"},{"indexed":false,"internalType":"uint16","name":"fee","type":"uint16"}],"name":"FeeVaultForPool","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityDesired","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"actualLiquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":false,"internalType":"address","name":"pool","type":"address"}],"name":"IncreaseLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_DENOMINATOR","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WNativeToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Owed","type":"uint256"},{"internalType":"uint256","name":"amount1Owed","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"algebraMintCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bool","name":"approve","type":"bool"},{"internalType":"address","name":"farmingAddress","type":"address"}],"name":"approveForFarming","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint128","name":"amount0Max","type":"uint128"},{"internalType":"uint128","name":"amount1Max","type":"uint128"}],"internalType":"struct INonfungiblePositionManager.CollectParams","name":"params","type":"tuple"}],"name":"collect","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"name":"createAndInitializePoolIfNecessary","outputs":[{"internalType":"address","name":"pool","type":"address"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct INonfungiblePositionManager.DecreaseLiquidityParams","name":"params","type":"tuple"}],"name":"decreaseLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"defaultWithdrawalFeesVault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"farmingApprovals","outputs":[{"internalType":"address","name":"farmingCenterAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"farmingCenter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"getWithdrawalFeePoolParams","outputs":[{"components":[{"internalType":"uint64","name":"apr0","type":"uint64"},{"internalType":"uint64","name":"apr1","type":"uint64"},{"internalType":"uint16","name":"withdrawalFee","type":"uint16"},{"components":[{"internalType":"address","name":"feeVault","type":"address"},{"internalType":"uint16","name":"fee","type":"uint16"}],"internalType":"struct INonfungiblePositionManager.FeesVault[]","name":"feeVaults","type":"tuple[]"}],"internalType":"struct INonfungiblePositionManager.WithdrawalFeePoolParams","name":"params","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount0Desired","type":"uint256"},{"internalType":"uint256","name":"amount1Desired","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct INonfungiblePositionManager.IncreaseLiquidityParams","name":"params","type":"tuple"}],"name":"increaseLiquidity","outputs":[{"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":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"isApprovedOrOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint256","name":"amount0Desired","type":"uint256"},{"internalType":"uint256","name":"amount1Desired","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct INonfungiblePositionManager.MintParams","name":"params","type":"tuple"}],"name":"mint","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":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"poolDeployer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"positions","outputs":[{"internalType":"uint88","name":"nonce","type":"uint88"},{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"feeGrowthInside0LastX128","type":"uint256"},{"internalType":"uint256","name":"feeGrowthInside1LastX128","type":"uint256"},{"internalType":"uint128","name":"tokensOwed0","type":"uint128"},{"internalType":"uint128","name":"tokensOwed1","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"positionsWithdrawalFee","outputs":[{"internalType":"uint32","name":"lastUpdateTimestamp","type":"uint32"},{"internalType":"uint128","name":"withdrawalFeeLiquidity","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"refundNativeToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermitAllowed","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermitAllowedIfNecessary","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermitIfNecessary","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newFarmingCenter","type":"address"}],"name":"setFarmingCenter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint64","name":"_apr0","type":"uint64"},{"internalType":"uint64","name":"_apr1","type":"uint64"}],"name":"setTokenAPR","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newVault","type":"address"}],"name":"setVaultAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint16[]","name":"fees","type":"uint16[]"},{"internalType":"address[]","name":"vaults","type":"address[]"}],"name":"setVaultsForPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint16","name":"newWithdrawalFee","type":"uint16"}],"name":"setWithdrawalFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"sweepToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bool","name":"toActive","type":"bool"}],"name":"switchFarmingStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenFarmedIn","outputs":[{"internalType":"address","name":"farmingCenterAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"unwrapWNativeToken","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]

6101a0346200033f57601f6200611a38819003918201601f19168301916001600160401b03831184841017620003445780849260a0946040528339810103126200033f576200004e8162000563565b6200005c6020830162000563565b6200006a6040840162000563565b906200008760806200007f6060870162000563565b950162000563565b9360405193620000978562000547565b601885527f416c676562726120506f736974696f6e73204e46542d56320000000000000000602086015260405194620000d08662000547565b6008865267414c47422d504f5360c01b602087015260405195620000f48762000547565b60018752601960f91b602088015281516001600160401b0381116200034457600054600181811c911680156200053c575b60208210146200044457601f8111620004e8575b50806020601f8211600114620004715760009162000465575b508160011b916000199060031b1c1916176000555b8051906001600160401b038211620003445760015490600182811c921680156200045a575b6020831014620004445781601f849311620003e0575b50602090601f831160011462000366576000926200035a575b50508160011b916000199060031b1c1916176001555b60208151910120948560805260208151910120948560a0524660e0526040519560208701917f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8352604088015260608701524660808701523060a087015260a0865260c086019580871060018060401b038811176200034457604087905251902060c05230610100908152610120918252610140928352610160938452760100000000000000000000000000000000000000000001601355610180948552956001600160a01b031680156200033f57600b80546001600160a01b031916919091179055615b61958662000579873960805186614e70015260a05186614e96015260c05186614e21015260e05186614edc01525185614deb01525184818161090e01528181611d050152614b8301525183818161234901528181612434015281816149c40152614f3b015251828181601d0152818161150101528181611b3b015261520e015251816108160152f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b015190503880620001bb565b60016000908152600080516020620060fa8339815191529350601f198516905b818110620003c75750908460019594939210620003ad575b505050811b01600155620001d1565b015160001960f88460031b161c191690553880806200039e565b9293602060018192878601518155019501930162000386565b6001600052909150600080516020620060fa833981519152601f840160051c8101916020851062000439575b90601f859493920160051c01905b818110620004295750620001a2565b600081558493506001016200041a565b90915081906200040c565b634e487b7160e01b600052602260045260246000fd5b91607f16916200018c565b90508301513862000152565b60008080529250600080516020620060da833981519152905b601f1983168410620004cf576001935082601f19811610620004b5575b5050811b0160005562000167565b85015160001960f88460031b161c191690553880620004a7565b858101518255602093840193600190920191016200048a565b60008052600080516020620060da833981519152601f830160051c81016020841062000534575b601f830160051c820181106200052757505062000139565b600081556001016200050f565b50806200050f565b90607f169062000125565b604081019081106001600160401b038211176200034457604052565b51906001600160a01b03821682036200033f5756fe6080806040526004361015610085575b50361561001b57600080fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316330361004d57005b60405162461bcd60e51b815260206004820152601060248201526f2737ba102ba730ba34bb32aa37b5b2b760811b6044820152606490fd5b600090813560e01c90816301ffc9a71461327d5750806306fdde03146131db578063081812fc146131bc578063095ea7b31461308e5780630c49ccbe14612bed578063135e53e0146127bc57806318160ddd1461279e578063219f5d171461259657806323b872dd1461256c5780632d0b22de146125395780632f745c591461248c57806330adf81f146124635780633119049a1461241e5780633644e515146124035780633dd657c51461228a578063418652701461226c57806342842e0e1461224457806342966c6814611f9b578063430c208114611f5d5780634659a49414611f445780634d10862d14611ed65780634f6ccce714611e4457806351246d6e14611cc05780636301727b14611c515780636352211e14611c2057806369bc35b214611b235780637022751514611a1457806370a08231146119e85780637ac2ff7b146116ff578063832f630a1461168157806385535cc5146116395780638692bd7d146115305780638af3ac85146114eb57806395d89b41146113fd57806399fbab88146112f25780639cc1a28314610d4b578063a22cb46514610c7d578063a4a78f0c14610c51578063aa7e1abd14610bb2578063ac9650d814610a27578063b227aa79146109fe578063b88d4fde14610971578063c2e3140a1461093d578063c45a0155146108f8578063c87b56dd146107cd578063d73792a9146107b0578063dba5281f14610787578063dd56e5d81461075e578063df2ab5bb146106db578063e7ce18a3146106a8578063e985e9c514610654578063f143536d146105fb578063f3995c67146105df5763fc6f78650361000f5760803660031901126105ca576102f7600435614b02565b6001600160801b039081610309614849565b16158015906105cd575b156105ca576001600160a01b03610328613c09565b166105bc5730915b60043582526011602052604082206001810154936001600160a01b0361035e6001600160501b038716614982565b16946004830154958487169660801c938260801c806104f5575b50610381614849565b88871690871611156104e5578788925b61039961485f565b87891690891611156104d55786998a955b876040519c8d9384936309e3d67b60e31b85528060681c60020b9060501c60020b60048601946103d9956148ea565b03818b5a94604095f19586156104ca576040998997610479575b50916004888587969461040e83809a81990316858701613c68565b9390920180546001600160801b031916929093031617905588516001600160a01b0390951685521660208401521681860152600435907f40d0efd1a53d60ecbf40971b9daf7dc90178c3aadc7aab1765632738fa8b8f0190606090a281845193168352166020820152f35b859950888096958195939950809461040e838f6004966104ae913d6040116104c3575b6104a6818361343d565b8101906148c9565b9f909f9d9799505050509450959650506103f3565b503d61049c565b6040513d8a823e3d90fd5b6104dd61485f565b998a956103aa565b6104ed614849565b978892610391565b90949760405191631d9de38760e11b83528460501c60020b8060048501528560681c60020b908160248601526000604486015260806064860152600360848601526203078360ec1b60a486015260408560c48160008a5af19485156105b0578a95610578575b509161056b91859330888c613d6f565b9201169801169338610378565b60408092939496503d83116105a9575b610592818361343d565b810103126105a457908893913861055b565b600080fd5b503d610588565b6040513d6000823e3d90fd5b6105c4613c09565b91610330565b80fd5b50816105d761485f565b161515610313565b506105f86105ec366134ac565b949390939291926154d7565b80f35b50346105ca5760203660031901126105ca57604080916004358152601260205220602082519161062a836133a2565b5463ffffffff811680845290821c6001600160801b03169190920181905282519182526020820152f35b50346105ca5760403660031901126105ca5761066e61334c565b6040610678613362565b9260018060a01b0380931681526005602052209116600052602052602060ff604060002054166040519015158152f35b50346105ca5760203660031901126105ca576020906004358152600d8252604060018060a01b0391205416604051908152f35b5060603660031901126105ca576106f061334c565b6106f8613378565b6107018261517d565b9060243582106107245781610714578380f35b61071d926159dc565b3880808380f35b60405162461bcd60e51b815260206004820152601260248201527124b739bab33334b1b4b2b73a103a37b5b2b760711b6044820152606490fd5b50346105ca57806003193601126105ca57600a546040516001600160a01b039091168152602090f35b50346105ca57806003193601126105ca57600b546040516001600160a01b039091168152602090f35b50346105ca57806003193601126105ca5760206040516103e88152f35b50346105ca576020806003193601126108e4576004356107f46107ef82613d39565b61358d565b60405163e9dc637560e01b8152306004820152602481019190915282816044817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9283156108ec578093610868575b5050610864604051928284938452830190613327565b0390f35b909192503d8082843e61087b818461343d565b82019183818403126108e4578051906001600160401b0382116108e8570182601f820112156108e4578051916108b0836134fb565b936108be604051958661343d565b8385528584840101116105ca5750906108dc91848085019101613304565b90388061084e565b5080fd5b8280fd5b604051903d90823e3d90fd5b50346105ca57806003193601126105ca576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50610947366134ac565b9380610955879593956155b1565b1061095e578680f35b610967956154d7565b3880808080808680f35b50346105ca5760803660031901126105ca5761098b61334c565b610993613362565b90606435906001600160401b0382116109fa57366023830112156109fa57816004013592846109c1856134fb565b936109cf604051958661343d565b85855236602487830101116108e457856105f89660246020930183880137850101526044359161365c565b8380fd5b50346105ca57806003193601126105ca576020604051600080516020615ad58339815191528152f35b506020806003193601126108e4576001600160401b0391600435908382116105ca57366023830112156105ca578160040135918483116108e45760059460243685881b84018201116109fa57610a7e859395613460565b94610a8c604051968761343d565b838652601f19610a9b85613460565b0187865b828110610ba257505050368190036042190190855b858110610b1b575050505050506040519280840190808552835180925280604083818801981b870101940192955b828710610aef5785850386f35b909192938280610b0b600193603f198a82030186528851613327565b9601920196019592919092610ae2565b83818b1b8301013583811215610b9e5782018481013590868211610b9a576044018136038113610b9a57818992918392604051928392833781018381520390305af4610b65613a51565b9015610b8b5790600191610b79828b6148a1565b52610b84818a6148a1565b5001610ab4565b8051908a8983156105ca575001fd5b8880fd5b8780fd5b6060898201830152899101610a9f565b50346105ca5760603660031901126105ca57610bcc61334c565b6001600160401b0360243581811692908390036105a4576044359182168083036105a457610bf8614b54565b6103e8808511159182610c46575b5050156109fa576001600160a01b03168352600e602052604080842080546001600160801b03191690931791901b600160401b600160801b031617905580f35b111590503880610c06565b50610c5b366134ac565b93909290600019610c6b876155b1565b10610c74578680f35b61096795615540565b50346105ca5760403660031901126105ca57610c9761334c565b610c9f6134ec565b6001600160a01b0390911690338214610d0a573383526005602052604083208260005260205260406000209015159060ff1981541660ff83161790556040519081527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a380f35b60405162461bcd60e51b815260206004820152601960248201527822a9219b99189d1030b8383937bb32903a379031b0b63632b960391b6044820152606490fd5b506101403660031901126105ca57610d65610124356153ea565b610de5610d70613bf3565b610d78613c09565b610d80613c1f565b610d88613c2f565b9160405193610d96856133bd565b6001600160a01b039081168552166020840152306040840152600290810b60608401520b608082015260843560a082015260a43560c082015260c43560e082015260e435610100820152614f02565b909290610104356001600160a01b03811690036105a457601380546001600160b01b031981166001600160b01b03808316600101161790915594610104356001600160a01b0316156112ae57610e4c610e466001600160b01b038816613d39565b15613cee565b6008546001600160b01b0387166000908152600960205260409020819055600160401b81101561121357610e89816001610e999301600855613b4b565b6001600160b01b038916916149e8565b610ea561010435613516565b610104356001600160a01b0316600090815260066020908152604080832084845282528083206001600160b01b038b1690819055808452600790925290912091909155610ef590610e4690613d39565b610104356001600160a01b0316808852600360209081526040808a20805460010190556001600160b01b038916808b526002909252892080546001600160a01b031916831790559088600080516020615b358339815191528180a4610f6b610f5b613c1f565b610f63613c2f565b9030856157ac565b505098915091610f79613bf3565b91610f82613c09565b60405193610f8f856133a2565b6001600160a01b0390811685529081166020808601919091529086168252600f90526040812080546001600160501b0316938415611229575b5050610fd2613c1f565b90610fdb613c2f565b6040519094906001600160401b03610140820190811190821117611213576101408101604090815283825260208083018581526001600160501b0390941682840152600295860b60608401529690940b6080828101919091526001600160801b038a1660a083015260c082019790975260e081019c909c526101008c018290526101208c018290526001600160b01b038b16825260119094529081208a5181546001600160581b0319166001600160581b039190911617815592519399600080516020615af5833981519152946111ea946111c0939261116a926110c8906001600160a01b031683613c3f565b6004600183019261112b60018060501b0360408501511694805495606086015160501b96608087015160681b62ffffff60681b16916080600180911b0319809962ffffff60501b16921617171781556080600180911b0360a08601511690613c68565b60c0830151600282015560e08301516003820155019160018f81901b03610100830151169083541617825561012060018f81901b039101511690613c68565b60405190611177826133a2565b4263ffffffff908116835260208084018381526001600160b01b038e168452601290915260409092209251835463ffffffff191691161782555160001960018d1b011690613c8b565b6040516001600160b01b038916949092839290916001600160a01b03169089908990899086613cb4565b0390a26040519360018060b01b03168452600180861b0316602084015260408301526060820152f35b634e487b7160e01b600052604160045260246000fd5b601380546001600160b01b038116600160b092831c81810190931b6001600160b01b0319169190911790925583546001600160501b03191681179093558284526010602090815260408520835181546001600160a01b03199081166001600160a01b039283161783559290940151920180549091169190921617905592503880610fc8565b606460405162461bcd60e51b815260206004820152602060248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152fd5b50346105ca5760203660031901126105ca57600435815260116020526040812060018101546001600160501b03811680156113c5578360409161016095526010602052209180549260018060a01b0392836001818454169301541660028401549260046003860154950154956040519760018060581b038116895260581c166020880152604087015260608601528060501c60020b60808601528060681c60020b60a086015260801c60c085015260e084015261010083015260018060801b03811661012083015260801c610140820152f35b60405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a59081d1bdad95b88125160821b6044820152606490fd5b50346105ca57806003193601126105ca57604051908060019182549283811c928185169485156114e1575b60209586861081146114cd578588528794939291879082156114ab575050600114611470575b505061145c9250038361343d565b610864604051928284938452830190613327565b908592508082528282205b85831061149357505061145c9350820101388061144e565b8054838901850152879450869390920191810161147b565b925093505061145c94915060ff191682840152151560051b820101388061144e565b634e487b7160e01b83526022600452602483fd5b93607f1693611428565b50346105ca57806003193601126105ca576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346105ca57602090816003193601126105ca5761154c61334c565b9060608060405161155c816133ec565b8381528386820152836040820152015260018060a01b038092168152600e8352604081209060405161158d816133ec565b82549460018060401b0394858716835281830195808860401c168752604084019761ffff9889809260801c1681526115c86001809901613b7c565b926060870193845260405199868b528160a08c01985116878c0152511660408a015251166060880152519660808088015287518094528260c08801980194915b8483106116155787890388f35b8551805182168a528401518216848a01526040909801979483019491860191611608565b50346105ca5760203660031901126105ca5761165361334c565b61165b614b54565b6001600160a01b031680156108e457600b80546001600160a01b03191691909117905580f35b5060603660031901126105ca576004356116996134ec565b906116a2613378565b6116ab82614b02565b83926116de575b508252600c6020526040822080546001600160a01b0319166001600160a01b0390921691909117905580f35b600a54919250906001600160a01b03908116908216036108e85790386116b2565b50611709366134ac565b90839296959342116119b25761171d614de8565b85875260209760118952604088209182549260018060581b03938481169460018601169060018060581b0319161790556040518a810190600080516020615b15833981519152825260018060a01b0397888a16958660408401528b6060840152608083015260a082015260a0815261179481613422565b519020604051908b82019261190160f01b845260228301526042820152604281526117be816133ec565b519020936117cb886135d4565b86811680941461195d578a94939291908a903b156118d6575061183d9596506040519385850152604084015260ff60f81b9060f81b16606083015260418252611813826133ec565b6040518080958194630b135d3f60e11b988984526004840152604060248401526044830190613327565b03915afa9081156118cb57859161189e575b506001600160e01b0319160361186a576105f8929350614d94565b60405162461bcd60e51b815260048101859052600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606490fd5b6118be9150863d88116118c4575b6118b6818361343d565b810190613a31565b3861184f565b503d6118ac565b6040513d87823e3d90fd5b9360ff60809498979360405194855216868401526040830152606082015282805260015afa15611952578451168015611919570361186a576105f8929350614d94565b60405162461bcd60e51b8152600481018790526011602482015270496e76616c6964207369676e617475726560781b6044820152606490fd5b6040513d86823e3d90fd5b60405162461bcd60e51b8152600481018c9052602760248201527f4552433732315065726d69743a20617070726f76616c20746f2063757272656e6044820152663a1037bbb732b960c91b6064820152608490fd5b60405162461bcd60e51b815260206004820152600e60248201526d14195c9b5a5d08195e1c1a5c995960921b6044820152606490fd5b50346105ca5760203660031901126105ca576020611a0c611a0761334c565b613516565b604051908152f35b50346105ca5760403660031901126105ca57600435611a316134ec565b600a546001600160a01b03908116338114939192859015611b045750818552600c602052808360408720541603611ac457925b15611a8a578352600d6020526040832080546001600160a01b0319169190921617905580f35b60405162461bcd60e51b815260206004820152601260248201527127b7363c902330b936b4b733a1b2b73a32b960711b6044820152606490fd5b60405162461bcd60e51b81526020600482015260186024820152774e6f7420617070726f76656420666f72206661726d696e6760401b6044820152606490fd5b93905080611a645750808452600d602052816040852054163314611a64565b5060403660031901126105ca57611b38613362565b907f0000000000000000000000000000000000000000000000000000000000000000611b638161517d565b906004358210611bdf5781611b76578280f35b6001600160a01b0316803b156108e857828091602460405180948193632e1a7d4d60e01b83528760048401525af18015611bd457611bc1575b50611bba9192615a82565b8038808280f35b91611bce611bba936133d9565b91611baf565b6040513d85823e3d90fd5b60405162461bcd60e51b815260206004820152601960248201527824b739bab33334b1b4b2b73a102ba730ba34bb32aa37b5b2b760391b6044820152606490fd5b50346105ca5760203660031901126105ca576020611c3f6004356135d4565b6040516001600160a01b039091168152f35b50346105ca5760403660031901126105ca57611c6b61334c565b6024359061ffff82168083036109fa576103e890611c87614b54565b116108e8576001600160a01b03168252600e60205260408220805461ffff60801b191660809290921b61ffff60801b1691909117905580f35b5060603660031901126105ca57611cd561334c565b90611cde613362565b906001600160a01b0360443581811681036108e857611d028285168387161061542d565b817f000000000000000000000000000000000000000000000000000000000000000016936040519463d9a641e160e01b8652602096878780611d48868560048401615473565b0381855afa968715611e395790889392918798611e1a575b508786811680611de957505086611d91959697985060405180968195829463e343361560e01b845260048401615473565b03925af19384156108ec5793611db6575b50611dad908361548d565b60405191168152f35b611dad919350611ddb90853d8711611de2575b611dd3818361343d565b810190613f42565b9290611da2565b503d611dc9565b925095965050859250611dfc9150615871565b1615611e0a575b5050611dad565b611e139161548d565b3880611e03565b611e32919850843d8611611de257611dd3818361343d565b9638611d60565b6040513d88823e3d90fd5b50346105ca5760203660031901126105ca57600435600854811015611e7c57611e6e602091613b4b565b90546040519160031b1c8152f35b60405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608490fd5b50346105ca5760203660031901126105ca577f29f9e1ebeee07596f3165f3e42cb9d4d8d22b0481e968d6c74be3dd037c15d9b6020611f1361334c565b611f1b614b54565b600a80546001600160a01b0319166001600160a01b03929092169182179055604051908152a180f35b506105f8611f51366134ac565b94939093929192615540565b50346105ca5760403660031901126105ca576020611f91611f7c61334c565b60243590611f8c6107ef83613d39565b6136f7565b6040519015158152f35b506020806003193601126108e45760043590611fb682614b02565b81835260118152826040812060018101908154916004820192835460018060801b0391828260801c92169060801c1717166109fa578382558390556002810183905560030182905555600d81526040832080546001600160a01b0319908116909155612021836135d4565b6001600160a01b03929083811690811580159081612216575b1561217e5750505060085484865260098252806040872055600160401b81101561216a57846120728260016120789401600855613b4b565b906149e8565b6008546000199390848101908111612156578587526009835261209f604088205491613b4b565b90549060031b1c6120b38161207284613b4b565b8752600983526040872055848652856040812055600854801561214257916002918588969594016120e381613b4b565b8782549160031b1b191690556008556120fb876135d4565b8787526004835260408720858154169055169384865260038252604086209081540190558585525260408320908154169055600080516020615b358339815191528280a480f35b634e487b7160e01b87526031600452602487fd5b634e487b7160e01b87526011600452602487fd5b634e487b7160e01b86526041600452602486fd5b61218a575b5050612078565b61219390613516565b600019810191908211612156578587526007835260408720548281036121da575b508587528660408120558652600682526040862090865281528460408120553880612183565b8188526006845260408820838952845260408820548289526006855260408920828a5285528060408a20558852600784526040882055386121b4565b878952601185526040808a208054600160581b600160f81b0319169055600c8652892080548716905561203a565b50346105ca576105f861225636613477565b906040519261226484613407565b85845261365c565b50806003193601126105ca57476122805780f35b6105f84733615a82565b50346105ca5760603660031901126105ca576004356024356044356001600160401b038082116123ff57366023830112156123ff5781600401359081116123ff5781013660248201116123ff5781900392606084126123ff5760408051946122f1866133a2565b126123ff5761236d9061233460646040519461230c866133a2565b6123186024820161338e565b86526123266044820161338e565b60208701528588520161338e565b60208601908152926001600160a01b039283917f00000000000000000000000000000000000000000000000000000000000000006156fd565b1633036123bd57806123a2575b5082612384578480f35b80602061239a9551015116903392511690615201565b388080808480f35b6123b790828651511633908486511690615201565b3861237a565b60405162461bcd60e51b815260206004820152601a602482015279496e76616c69642063616c6c6572206f662063616c6c6261636b60301b6044820152606490fd5b8480fd5b50346105ca57806003193601126105ca576020611a0c614de8565b50346105ca57806003193601126105ca576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346105ca57806003193601126105ca576020604051600080516020615b158339815191528152f35b50346105ca5760403660031901126105ca576124a661334c565b602435916124b382613516565b8310156124e05760209260409260018060a01b031682526006845282822090825283522054604051908152f35b60405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608490fd5b50346105ca5760203660031901126105ca576020906004358152600c8252604060018060a01b0391205416604051908152f35b50346105ca576105f861257e36613477565b9161259161258c84336136f7565b6135fa565b6137bf565b5060c03660031901126105ca576126b76060916125b460a4356153ea565b6004358152601160205260408120906040600080516020615af5833981519152612731600185015460018060501b0381168552601060205261271e61271861266486882060018060a01b03815416906001808060a01b039101541688519161261b836133bd565b8252602082015230888201528460501c60020b8c8201528460681c60020b608082015260243560a082015260443560c082015260643560e0820152608435610100820152614f02565b949399929a919c909b61268a8860801c8960681c60020b8a60501c60020b308a86613d6f565b908082176001600160801b031661275c575b5050608088901c8c016001600160801b031690600101613c68565b60043581526012602052209160018060a01b03169382546126f363ffffffff928060801c908060681c60020b9060501c60020b8585168a613f74565b63ffffffff19909116429092169190911780845560201c6001600160801b0316613d56565b90613c8b565b6040519182918789886004359886613cb4565b0390a26001600160801b03169161274a83600435614c6b565b60405192835260208301526040820152f35b6004830180546001600160801b038082169390930183166001600160801b0319909116178082556127979360809190911c0190911690613c68565b388061269c565b50346105ca57806003193601126105ca576020600854604051908152f35b50346105ca5760603660031901126105ca576127d661334c565b906024356001600160401b038082116108e857366023830112156108e857816004013561280281613460565b92612810604051948561343d565b8184526024602085019260051b82010190368211612bca57602401915b818310612bce575050506044359081116108e857366023820112156108e85780600401359061285b82613460565b91612869604051938461343d565b8083526024602084019160051b83010191368311612bca57602401905b828210612bb257505050612898614b54565b8260018060a01b0385168152600e60205260016040822001938251845103612b6d57845415801590612b64575b612b1b575b81905b8451821015612a7e576001600160a01b036128e883866148a1565b511615612a3d576001600160a01b0361290183866148a1565b511661ffff61291084886148a1565b51166040519161291f836133a2565b825260208201528654600160401b811015612a295760018101808955811015612a15579061ffff6020612975938a8852818820019260018060a01b0381511660018060a01b031985541617845501511690614a00565b61ffff8061298384886148a1565b511691160161ffff8111612a0157906129fb907fff5b7ae049a1a9fb20442c9c2abaa248c078a294b476cb51c8951028b775e46e60606001600160a01b036129cb84896148a1565b511661ffff6129da858b6148a1565b51166040519160018060a01b038d16835260208301526040820152a1614875565b906128cd565b634e487b7160e01b83526011600452602483fd5b634e487b7160e01b85526032600452602485fd5b634e487b7160e01b85526041600452602485fd5b60405162461bcd60e51b815260206004820152601960248201527805661756c7420616464726573732063616e6e6f74206265203603c1b6044820152606490fd5b868684928751612a8c578380f35b61ffff6103e8911603612ac3576001600160a01b039091168252600e60205260408220612abc9190600101614a1f565b8180808380f35b60405162461bcd60e51b815260206004820152602a60248201527f546f74616c20666565206d75737420626520657175616c20746f204645455f4460448201526922a727a6a4a720aa27a960b11b6064820152608490fd5b6001600160a01b0386168252600e6020526040822060010180548382559081612b46575b50506128ca565b835260208320908101905b81811015612b3f57838155600101612b51565b508351156128c5565b60405162461bcd60e51b815260206004820152601f60248201527f5661756c747320616e642066656573206c656e677468206d69736d61746368006044820152606490fd5b60208091612bbf8461338e565b815201910190612886565b8580fd5b823561ffff81168103612be95781526020928301920161282d565b8680fd5b5060a03660031901126105ca57612c05600435614b02565b612c106084356153ea565b6001600160801b03612c20614833565b16156105ca5760043581526011602052604081206001810154906001600160801b03612c4a614833565b168260801c106108e8576001600160a01b03612c6e6001600160501b038416614982565b16916004358452601260205260408420805490612cb9612ca68460801c8560681c60020b8660501c60020b63ffffffff87168a613f74565b602084901c6001600160801b0316613d56565b608084901c6001600160801b038216111561308857508260801c915b6001600160a01b0319164263ffffffff161790556001600160801b038116612ec2575b612e6a90612e0d612d9494612d0b614833565b6001600160801b03612d2185608089901c614926565b166001600160801b039091161115612eb2576001612d42848760801c614926565b955b612def612d5f888360681c60020b8460501c60020b8d615925565b99909a6044358c101580612ea6575b612d779061493f565b8360801c908460681c60020b908560501c60020b90309089613d6f565b60048601918254908d878060801b0391888060801b0391898060801b03160116878060801b038316011690868060801b03191617808355858060801b0391868060801b03908d888060801b031601169060801c011690613c68565b84828060801b039188848060801b039160801c031603169101613c68565b604080516001600160801b0385811682528316602082015290810186905260608101859052600435907f5e41cd741a4f79d713bd0c5670fae681a19f07bb5eca4955e68e322e9e15287290608090a26001600160801b0392613d56565b16600160ff1b8114612e9257612e869060409403600435614c6b565b82519182526020820152f35b634e487b7160e01b84526011600452602484fd5b506064358b1015612d6e565b6001612ebc614833565b95612d44565b612eda818360681c60020b8460501c60020b87615925565b858793929352600e602052612ef460016040892001613b7c565b87815115600014612f99575050600b54604080516309e3d67b60e31b815294909285928392612f52926001600160801b039081169291169060688a901c600290810b9160508c901c90910b906001600160a01b0316600487016148ea565b038189895af18015611e3957612d9494612e6a93612e0d92612f7b575b505b9450509050612cf8565b612f939060403d6040116104c3576104a6818361343d565b50612f6f565b909394919692815b85518110156130705761ffff6020612fb983896148a1565b510151169060406001600160a01b03612fd2838a6148a1565b515116928b6103e86130018c82612ff08660018060801b0393613f61565b0416936001600160801b0393613f61565b041693613031835195869384936309e3d67b60e31b85528b60681c60020b908c60501c60020b90600487016148ea565b0381878a5af19182156119525761304d92613052575b50614875565b612fa1565b61306a9060403d6040116104c3576104a6818361343d565b50613047565b50929650509250612e6a9150612e0d612d9494612f71565b91612cd5565b50346105ca5760403660031901126105ca576130a861334c565b6024356001600160a01b03806130bd836135d4565b16809184161461316d5780331490811561314c575b50156130e1576105f891614d94565b60405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c0000006064820152608490fd5b9050835260056020526040832033845260205260ff604084205416386130d2565b60405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608490fd5b50346105ca5760203660031901126105ca576020611c3f600435614ad8565b50346105ca57806003193601126105ca576040519080805491600183811c92818516948515613273575b60209586861081146114cd578588528794939291879082156114ab57505060011461323857505061145c9250038361343d565b908592508180528282205b85831061325b57505061145c9350820101388061144e565b80548389018501528794508693909201918101613243565b93607f1693613205565b9050346108e45760203660031901126108e45760043563ffffffff60e01b81168091036108e8576020925063780e9d6360e01b81149081156132c1575b5015158152f35b6380ac58cd60e01b8114915081156132f3575b81156132e2575b50386132ba565b6301ffc9a760e01b149050386132db565b635b5e139f60e01b811491506132d4565b60005b8381106133175750506000910152565b8181015183820152602001613307565b9060209161334081518092818552858086019101613304565b601f01601f1916010190565b600435906001600160a01b03821682036105a457565b602435906001600160a01b03821682036105a457565b604435906001600160a01b03821682036105a457565b35906001600160a01b03821682036105a457565b604081019081106001600160401b0382111761121357604052565b61012081019081106001600160401b0382111761121357604052565b6001600160401b03811161121357604052565b608081019081106001600160401b0382111761121357604052565b602081019081106001600160401b0382111761121357604052565b60c081019081106001600160401b0382111761121357604052565b601f909101601f19168101906001600160401b0382119082101761121357604052565b6001600160401b0381116112135760051b60200190565b60609060031901126105a4576001600160a01b039060043582811681036105a4579160243590811681036105a4579060443590565b60c09060031901126105a4576004356001600160a01b03811681036105a45790602435906044359060643560ff811681036105a457906084359060a43590565b6024359081151582036105a457565b6001600160401b03811161121357601f01601f191660200190565b6001600160a01b0316801561353657600052600360205260406000205490565b60405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608490fd5b1561359457565b60405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606490fd5b6000908152600260205260409020546001600160a01b03166135f781151561358d565b90565b1561360157565b60405162461bcd60e51b815260206004820152602d60248201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560448201526c1c881bdc88185c1c1c9bdd9959609a1b6064820152608490fd5b9061368093929161367061258c84336136f7565b61367b8383836137bf565b613a81565b1561368757565b60405162461bcd60e51b8152806136a0600482016136a4565b0390fd5b60809060208152603260208201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b60608201520190565b906001600160a01b03808061370b846135d4565b1693169183831493841561373e575b508315613728575b50505090565b61373491929350614ad8565b1614388080613722565b909350600052600560205260406000208260005260205260ff60406000205416923861371a565b1561376c57565b60405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608490fd5b6137e3916137cc846135d4565b6001600160a01b0393848416939185168414613765565b8382169384156139e0578391821580156139a4575b156138eb575060085460008781526009602052604090208190559150600160401b821015611213576138529261383987612072856001899701600855613b4b565b8286036138b8575b5061384b866135d4565b1614613765565b600080516020615b35833981519152600084815260046020526040812060018060a01b03199081815416905583825260036020526040822060001981540190558482526040822060018154019055858252600260205284604083209182541617905580a4565b6138c190613516565b60406000878152600660205281812083825260205288828220558881526007602052205538613841565b8583036138fd575b5061385292613839565b613908919250613516565b60001981019190821161398e576138529284926000908882526020906007825260409182842054828103613957575b508a845283838120558684526006815282842091845252812055926138f3565b8785526006825283852083865282528385205488865260068352848620828752835280858720558552600782528385205538613937565b634e487b7160e01b600052601160045260246000fd5b60008881526011602090815260408083208054600160581b600160f81b0319169055600c909152902080546001600160a01b03191690556137f8565b60405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b908160209103126105a457516001600160e01b0319811681036105a45790565b3d15613a7c573d90613a62826134fb565b91613a70604051938461343d565b82523d6000602084013e565b606090565b9192813b15613b4257602091613ad3916000604051958680958194630a85bd0160e11b9a8b845233600485015260018060a01b0380951660248501526044840152608060648401526084830190613327565b0393165af160009181613b22575b50613b1457613aee613a51565b80519081613b0f5760405162461bcd60e51b8152806136a0600482016136a4565b602001fd5b6001600160e01b0319161490565b613b3b91925060203d81116118c4576118b6818361343d565b9038613ae1565b50505050600190565b600854811015613b6657600860005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b908154613b8881613460565b92604093613b988551918261343d565b828152809460208092019260005281600020906000935b858510613bbe57505050505050565b60018481928451613bce816133a2565b61ffff8754858060a01b038116835260a01c1683820152815201930194019391613baf565b6004356001600160a01b03811681036105a45790565b6024356001600160a01b03811681036105a45790565b6044358060020b81036105a45790565b6064358060020b81036105a45790565b8054600160581b600160f81b03191660589290921b600160581b600160f81b0316919091179055565b80546001600160801b031660809290921b6001600160801b031916919091179055565b8054600160201b600160a01b03191660209290921b600160201b600160a01b0316919091179055565b6001600160801b03918216815291166020820152604081019190915260608101919091526001600160a01b03909116608082015260a00190565b15613cf557565b60405162461bcd60e51b815260206004820152601c60248201527b115490cdcc8c4e881d1bdad95b88185b1c9958591e481b5a5b9d195960221b6044820152606490fd5b6000908152600260205260409020546001600160a01b0316151590565b6001600160801b03918216908216019190821161398e57565b959391613d7c93916157ac565b50509150926002850193613da6613db36003875484039460018060801b0393848092168097613db9565b1698019384548603613db9565b16945555565b8181029190600019828209918380841093039183830393600160801b93858511156105a45714613df6570990828211900360801b910360801c1790565b5050505060801c90565b8181029190600019828209918380841093039183830393600160601b93858511156105a45714613e3d570990828211900360a01b910360601c1790565b5050505060601c90565b90606082901b90600160601b600019818509938380861095039480860395868511156105a45714613ec4579082910981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b505091500490565b9181830291600019818509938380861095039480860395868511156105a45714613ec4579082910981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b908160209103126105a457516001600160a01b03811681036105a45790565b8181029291811591840414171561398e57565b90949291946000946000600160a01b6001900380941690818152602092600e845260409081832096825193613fa8856133ec565b885493600160401b6001900394858116875285808a8901988184861c168a528481019d8e61ffff809660801c169052600101613fe390613b7c565b606082015251169751169a511698861595861580976144d3575b806144ca575b61401a575b50505050505050505050505050909150565b63ffffffff809216824216038281116144b65782169889156144a257835163ef01df4f60e01b815260049b9291839082908e9082905afa90811561449857908791879161447b575b5016801561446657845193606085018581108482111761445257918c8e96928994895260028452868401918936843761409a85614884565b52846140a585614891565b528851978894639d3a524160e01b86528860248701928701525180915260448501929186905b8983831061443257505050505082809103915afa93841561442957859461431a575b505050506141046140fd82614891565b5191614884565b5160060b9060060b0396667fffffffffffff19667fffffffffffff8913818a1217614307578760060b9860060b89156142f4576000199181148a8314166142e15789810560020b9984821291826142d2575b505061429f575b505061417761417161417f9b9c9d9e6144dc565b9b6144dc565b998a976144dc565b8b9188938d8180849c16911611614294575b8281169084811682116142595750505050906141ad9291615666565b905b61421d575b5050836141cb575b808080808080808e9d9c614008565b61420361420b9593640757b12c006141fd6142119a9b9997956141f86103e89660018060801b0398613f61565b613f61565b04613f61565b04169161563d565b90613d56565b903880808080806141bc565b8299916103e861424887640757b12c006141fd61420b966141f86142519a60018060801b0398613f61565b041687896155f1565b9638806141b4565b90919296995084939594161160001461428957509261427d82614283949583615666565b936156cb565b936141af565b9350614283926156cb565b8d94508c9350614191565b909d97627fffff1981146142bf57979d509096019561417761417161415d565b634e487b7160e01b835260118f52602483fd5b0760060b151590503880614156565b634e487b7160e01b845260118352602484fd5b634e487b7160e01b845260128352602484fd5b634e487b7160e01b835260118252602483fd5b90919293503d8086863e61432e818661343d565b8401918185840312612bca578451818111612be95785019483601f87011215612be95785519561435d87613460565b9661436a8551988961343d565b808852868089019160051b83010191868311614425578701905b8282106144085750505084810151918211612be9570182601f82011215612bca5783808251936143bf6143b686613460565b9151918261343d565b848152019260051b820101928311612bca578301905b8282106143e95750505050388080806140ed565b81516001600160581b0381168103612be95781529083019083016143d5565b81518060060b8103614421578152908701908701614384565b8a80fd5b8980fd5b513d86823e3d90fd5b8451821686528d98508b97509485019493909301926001909101906140cb565b50634e487b7160e01b875260418d52602487fd5b50505050509a50505050505050505050915090565b6144929150843d8611611de257611dd3818361343d565b38614062565b85513d88823e3d90fd5b505050509a50505050505050505050915090565b634e487b7160e01b85526011600452602485fd5b508a1515614003565b508b1515613ffd565b8060020b908160171d60020b80910160020b189062ffffff8216620d89e8811161482157600160801b9260018116614809575b600281166147ed575b600481166147d1575b600881166147b5575b60108116614799575b6020811661477d575b60408116614761575b608091828216614746575b610100821661472b575b6102008216614710575b61040082166146f5575b61080082166146da575b61100082166146bf575b61200082166146a4575b6140008216614689575b618000821661466e575b620100008216614653575b620200008216614639575b62040000809110156145ec575b5050506000126145e3575b63ffffffff0160201c6001600160a01b031690565b600019046145ce565b811661461f575b6208000016614604575b80806145c3565b6b048a170391f7dc42444e8fa26000929302901c91906145fd565b6d2216e584f5fa1ea926041bedfe98909302811c926145f3565b936e5d6af8dedb81196699c329225ee60402821c936145b6565b936f09aa508b5b7a84e1c677de54f3e99bc902821c936145ab565b936f31be135f97d08fd981231505542fcfa602821c936145a0565b936f70d869a156d2a1b890bb3df62baf32f702821c93614596565b936fa9f746462d870fdf8a65dc1f90e061e502821c9361458c565b936fd097f3bdfd2022b8845ad8f792aa582502821c93614582565b936fe7159475a2c29b7443b29c7fa6e889d902821c93614578565b936ff3392b0822b70005940c7a398e4b70f302821c9361456e565b936ff987a7253ac413176f2b074cf7815e5402821c93614564565b936ffcbe86c7900a88aedcffc83b479aa3a402821c9361455a565b936ffe5dee046a99a2a811c461f1969c305302821c93614550565b926fff2ea16466c96a3843ec78b326b528610260801c92614545565b926fff973b41fa98c081472e6896dfb254c00260801c9261453c565b926fffcb9843d60f6159c9db58835c9266440260801c92614533565b926fffe5caca7e10e4e61c3624eaa0941cd00260801c9261452a565b926ffff2e50f5f656932ef12357cf3c7fdcc0260801c92614521565b926ffff97272373d413259a46990580e213a0260801c92614518565b6ffffcb933bd6fad37aa2d162d1a594001935061450f565b604051633c10250f60e01b8152600490fd5b6024356001600160801b03811681036105a45790565b6044356001600160801b03811681036105a45790565b6064356001600160801b03811681036105a45790565b600019811461398e5760010190565b805115613b665760200190565b805160011015613b665760400190565b8051821015613b665760209160051b010190565b51906001600160801b03821682036105a457565b91908260409103126105a4576135f760206148e3846148b5565b93016148b5565b6001600160a01b039091168152600291820b602082015291900b60408201526001600160801b0391821660608201529116608082015260a00190565b6001600160801b03918216908216039190821161398e57565b1561494657565b60405162461bcd60e51b8152602060048201526014602482015273507269636520736c69707061676520636865636b60601b6044820152606490fd5b60018060501b031660005260106020526135f76040600020604051906149a7826133a2565b80546001600160a01b0390811683526001909101541660208201527f00000000000000000000000000000000000000000000000000000000000000006156fd565b919082549060031b91821b91600019901b1916179055565b805461ffff60a01b191660a09290921b61ffff60a01b16919091179055565b818114614ad457815491600160401b8311611213578154838355808410614aab575b506000526020600020906000526020600020906000905b838210614a655750505050565b806001918403614a7e575b928101929181019101614a58565b818060a01b03815416828060a01b0319855416178455614aa661ffff825460a01c1685614a00565b614a70565b6000838152846020822092830192015b828110614ac9575050614a41565b818155600101614abb565b5050565b614ae46107ef82613d39565b60009081526011602052604090205460581c6001600160a01b031690565b614b0c90336136f7565b15614b1357565b60405162461bcd60e51b815260206004820152600c60248201526b139bdd08185c1c1c9bdd995960a21b6044820152606490fd5b519081151582036105a457565b60405163e8ae2b6960e01b8152600080516020615ad583398151915260048201523360248201526020816044817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9081156105b057600091614bc4575b50156105a457565b906020823d8211614bf5575b81614bdd6020938361343d565b810103126105ca5750614bef90614b47565b38614bbc565b3d9150614bd0565b600060443d106135f757604051600319913d83016004833e81516001600160401b03918282113d602484011117614c5a57818401948551938411614c62573d85010160208487010111614c5a57506135f79291016020019061343d565b949350505050565b50949350505050565b6000818152600d602052604081205490926001600160a01b03918216918215614d8d57600a5416918215614d8d578214614ca6575b50505050565b813b156109fa578391604483926040519485938492626e65c960e41b845288600485015260248401525af19081614d7a575b50614d73576001908260033d11614d63575b806308c379a014614d5a57634e487b7114614d10575b506108ec57505b38808080614ca0565b8260233d11614d4c575b15614d00578291507f4f27462fbdc9bce16bb573a06acba6b27394e151da96ce8098d8e29a6dc8d64b8280a238614d00565b5060206004843e6001614d1a565b50614d1a614bfd565b50600483803e825160e01c614cea565b5050614d07565b614d86909391936133d9565b9138614cd8565b5050505050565b816000526011602052614dab816040600020613c3f565b6001600160a01b0380614dbd846135d4565b169116907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600080a4565b307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03161480614ed9575b15614e43577f000000000000000000000000000000000000000000000000000000000000000090565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f000000000000000000000000000000000000000000000000000000000000000060408201527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260a08152614ed381613422565b51902090565b507f00000000000000000000000000000000000000000000000000000000000000004614614e1a565b8051602082015160405193916001600160a01b039182169116614f24856133a2565b8452602084019081526001600160a01b03614f5f857f00000000000000000000000000000000000000000000000000000000000000006156fd565b166060614f6b82615871565b81860161507e614f7e825160020b6144dc565b926080890193614f91855160020b6144dc565b60a08b015160c08c015190929082826001600160a01b0380831690821611615172575b50506001600160a01b03858116959083168611615116575050614fd793506155f1565b985b8960018060a01b0360408b015116935160020b945160020b976020604051615000816133a2565b8481523391019081526040805194516001600160a01b0390811660208701529251831690850152511686830152858252615039826133ec565b60405197889586956302abf8a760e61b875233600488015260248701526044860152606485015260018060801b0316608484015260c060a484015260c4830190613327565b03816000855af19283156105b057600093849385916150c7575b506150b59095848660e0830151111591826150b7575b505061493f565b565b61010001511115905038806150ae565b94919350506060843d60601161510e575b816150e56060938361343d565b810103126105ca57508251916150b56151056040602087015196016148b5565b93949390615098565b3d91506150d8565b919490939192906001600160a01b038216111561516657829161513d9161514395946155f1565b9361563d565b6001600160801b03818116908316101561515f57505b98614fd9565b9050615159565b9150506151599261563d565b935091503880614fb4565b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa9081156105b0576000916151b8575090565b906020823d82116151de575b816151d16020938361343d565b810103126105ca57505190565b3d91506151c4565b6001600160a01b039091168152602081019190915260400190565b9293926001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116929091908282168414806153e0575b1561530057505050803b156105a457604051630d0e30db60e41b815293600091828660048185855af1958615611bd45761529a95966152ee575b50829360209360405180978195829463a9059cbb60e01b8452600484016151e6565b03925af180156152e1576152ac575050565b6020823d82116152d9575b816152c46020938361343d565b810103126105ca57506152d690614b47565b50565b3d91506152b7565b50604051903d90823e3d90fd5b926152fa6020946133d9565b92615278565b9495948216949392509030850361531c57506150b593506159dc565b604093919293519360208501956323b872dd60e01b8752602486015216604484015260648301526064825260a082019282841060018060401b03851117611213576000809493819460405251925af1615373613a51565b816153a9575b506150b55760405162461bcd60e51b815260206004820152600360248201526229aa2360e91b6044820152606490fd5b80518015925082156153be575b505038615379565b81925090602091810103126105a45760206153d99101614b47565b38806153b6565b508647101561523e565b42116153f257565b60405162461bcd60e51b8152602060048201526013602482015272151c985b9cd858dd1a5bdb881d1bdbc81bdb19606a1b6044820152606490fd5b1561543457565b60405162461bcd60e51b8152602060048201526017602482015276496e76616c6964206f72646572206f6620746f6b656e7360481b6044820152606490fd5b6001600160a01b0391821681529116602082015260400190565b6001600160a01b039081169190823b156105a457602460009283604051958694859363f637731d60e01b85521660048401525af180156105b0576154ce5750565b6150b5906133d9565b92946001600160a01b0390931693919291843b156105a45760009460e493869260ff604051998a98899763d505accf60e01b89523360048a01523060248a01526044890152606488015216608486015260a485015260c48401525af180156105b0576154ce5750565b92946001600160a01b0390931693919291843b156105a45760009461010493869260ff604051998a9889976323f2ebc360e21b89523360048a01523060248a015260448901526064880152600160848801521660a486015260c485015260e48401525af180156105b0576154ce5750565b60206040518092636eb1769f60e11b825281806155d2303360048401615473565b03916001600160a01b03165afa9081156105b0576000916151b8575090565b6156239291906001600160a01b039081831682821611615637575b61561a828416838316613e00565b92031691613ecc565b6001600160801b0381169081036105a45790565b9161560c565b61562392916001600160a01b03919082811683831611615660575b031690613e47565b90615658565b916001600160a01b039190828216838516116156c3575b6156a091838116919085900384169060601b600160601b600160e01b0316613ecc565b91169081156156ad570490565b634e487b7160e01b600052601260045260246000fd5b90929061567d565b6135f792916001600160a01b039190828116838316116156f7575b0316906001600160801b0316613e00565b906156e6565b60018060a01b039161573a615748848080855116946157246020820196838851161161542d565b5116935116604051928391602083019586615473565b03601f19810183528261343d565b51902060405190602082019260ff60f81b845260018060601b03199060601b16602183015260358201527ff96d2474815c32e070cd63233f06af5413efc5dcb430aee4ff18cc29007c562d6055820152605581526157a5816133ec565b5190201690565b60a09293602491604051958694859363514ea4bf60e01b855262ffffff80911692169060181b1760181b176004830152600180861b03165afa9081156105b05760009182938380938193615803575b509493929190565b9450925093505060a0823d821161585a575b8161582260a0938361343d565b810103126105ca5750805160208201516040830151936158506080615849606087016148b5565b95016148b5565b91949392386157fb565b3d9150615815565b519061ffff821682036105a457565b6040516339db007960e21b8152906001600160a01b039060c0908390600490829085165afa9182156105b0576000926158a957505090565b909160c0823d821161591d575b816158c360c0938361343d565b810103126105ca57815192831683036105ca5760208201518060020b036105ca576158f060408301615862565b50606082015160ff8116036105ca575060a08161591260806159199401615862565b5001614b47565b5090565b3d91506158b6565b9392604092835192631d9de38760e11b845260020b600484015260020b602483015260018060801b0316604482015260806064820152600360848201526203078360ec1b60a4820152818160c4816000809860018060a01b03165af19384156159d15780928195615998575b5050509190565b919450915083813d81116159ca575b6159b1818361343d565b810103126105ca57506020825192015191388080615991565b503d6159a7565b8251903d90823e3d90fd5b600092918361573a615a078295604051928391602083019663a9059cbb60e01b8852602484016151e6565b51925af1615a13613a51565b81615a4b575b5015615a2157565b60405162461bcd60e51b815260206004820152600260248201526114d560f21b6044820152606490fd5b8051801592508215615a60575b505038615a19565b81925090602091810103126105a4576020615a7b9101614b47565b3880615a58565b6000808093819382604051615a9681613407565b525af1615aa1613a51565b5015615aa957565b60405162461bcd60e51b815260206004820152600360248201526253544560e81b6044820152606490fdfeff0e0466f109fcf4f5660899d8847c592e1e8dea30ffbe040704b23ad381d7628a82de7fe9b33e0e6bca0e26f5bd14a74f1164ffe236d50e0a36c3ea70f2b81449ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9adddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa164736f6c6343000814000a290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf60000000000000000000000004eb881885fe22d895ff299f6cda6e0a8e00e66a0000000000000000000000000845e4145f7de2822d16fe233ecd0181c61f1d65f0000000000000000000000006d63b39017f379bfd0301293022581c6ef237a19000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a000000000000000000000000045362763166cfed6174d312fa1449ea1fc37988a

Deployed Bytecode

0x6080806040526004361015610085575b50361561001b57600080fd5b7f000000000000000000000000845e4145f7de2822d16fe233ecd0181c61f1d65f6001600160a01b0316330361004d57005b60405162461bcd60e51b815260206004820152601060248201526f2737ba102ba730ba34bb32aa37b5b2b760811b6044820152606490fd5b600090813560e01c90816301ffc9a71461327d5750806306fdde03146131db578063081812fc146131bc578063095ea7b31461308e5780630c49ccbe14612bed578063135e53e0146127bc57806318160ddd1461279e578063219f5d171461259657806323b872dd1461256c5780632d0b22de146125395780632f745c591461248c57806330adf81f146124635780633119049a1461241e5780633644e515146124035780633dd657c51461228a578063418652701461226c57806342842e0e1461224457806342966c6814611f9b578063430c208114611f5d5780634659a49414611f445780634d10862d14611ed65780634f6ccce714611e4457806351246d6e14611cc05780636301727b14611c515780636352211e14611c2057806369bc35b214611b235780637022751514611a1457806370a08231146119e85780637ac2ff7b146116ff578063832f630a1461168157806385535cc5146116395780638692bd7d146115305780638af3ac85146114eb57806395d89b41146113fd57806399fbab88146112f25780639cc1a28314610d4b578063a22cb46514610c7d578063a4a78f0c14610c51578063aa7e1abd14610bb2578063ac9650d814610a27578063b227aa79146109fe578063b88d4fde14610971578063c2e3140a1461093d578063c45a0155146108f8578063c87b56dd146107cd578063d73792a9146107b0578063dba5281f14610787578063dd56e5d81461075e578063df2ab5bb146106db578063e7ce18a3146106a8578063e985e9c514610654578063f143536d146105fb578063f3995c67146105df5763fc6f78650361000f5760803660031901126105ca576102f7600435614b02565b6001600160801b039081610309614849565b16158015906105cd575b156105ca576001600160a01b03610328613c09565b166105bc5730915b60043582526011602052604082206001810154936001600160a01b0361035e6001600160501b038716614982565b16946004830154958487169660801c938260801c806104f5575b50610381614849565b88871690871611156104e5578788925b61039961485f565b87891690891611156104d55786998a955b876040519c8d9384936309e3d67b60e31b85528060681c60020b9060501c60020b60048601946103d9956148ea565b03818b5a94604095f19586156104ca576040998997610479575b50916004888587969461040e83809a81990316858701613c68565b9390920180546001600160801b031916929093031617905588516001600160a01b0390951685521660208401521681860152600435907f40d0efd1a53d60ecbf40971b9daf7dc90178c3aadc7aab1765632738fa8b8f0190606090a281845193168352166020820152f35b859950888096958195939950809461040e838f6004966104ae913d6040116104c3575b6104a6818361343d565b8101906148c9565b9f909f9d9799505050509450959650506103f3565b503d61049c565b6040513d8a823e3d90fd5b6104dd61485f565b998a956103aa565b6104ed614849565b978892610391565b90949760405191631d9de38760e11b83528460501c60020b8060048501528560681c60020b908160248601526000604486015260806064860152600360848601526203078360ec1b60a486015260408560c48160008a5af19485156105b0578a95610578575b509161056b91859330888c613d6f565b9201169801169338610378565b60408092939496503d83116105a9575b610592818361343d565b810103126105a457908893913861055b565b600080fd5b503d610588565b6040513d6000823e3d90fd5b6105c4613c09565b91610330565b80fd5b50816105d761485f565b161515610313565b506105f86105ec366134ac565b949390939291926154d7565b80f35b50346105ca5760203660031901126105ca57604080916004358152601260205220602082519161062a836133a2565b5463ffffffff811680845290821c6001600160801b03169190920181905282519182526020820152f35b50346105ca5760403660031901126105ca5761066e61334c565b6040610678613362565b9260018060a01b0380931681526005602052209116600052602052602060ff604060002054166040519015158152f35b50346105ca5760203660031901126105ca576020906004358152600d8252604060018060a01b0391205416604051908152f35b5060603660031901126105ca576106f061334c565b6106f8613378565b6107018261517d565b9060243582106107245781610714578380f35b61071d926159dc565b3880808380f35b60405162461bcd60e51b815260206004820152601260248201527124b739bab33334b1b4b2b73a103a37b5b2b760711b6044820152606490fd5b50346105ca57806003193601126105ca57600a546040516001600160a01b039091168152602090f35b50346105ca57806003193601126105ca57600b546040516001600160a01b039091168152602090f35b50346105ca57806003193601126105ca5760206040516103e88152f35b50346105ca576020806003193601126108e4576004356107f46107ef82613d39565b61358d565b60405163e9dc637560e01b8152306004820152602481019190915282816044817f0000000000000000000000006d63b39017f379bfd0301293022581c6ef237a196001600160a01b03165afa9283156108ec578093610868575b5050610864604051928284938452830190613327565b0390f35b909192503d8082843e61087b818461343d565b82019183818403126108e4578051906001600160401b0382116108e8570182601f820112156108e4578051916108b0836134fb565b936108be604051958661343d565b8385528584840101116105ca5750906108dc91848085019101613304565b90388061084e565b5080fd5b8280fd5b604051903d90823e3d90fd5b50346105ca57806003193601126105ca576040517f0000000000000000000000004eb881885fe22d895ff299f6cda6e0a8e00e66a06001600160a01b03168152602090f35b50610947366134ac565b9380610955879593956155b1565b1061095e578680f35b610967956154d7565b3880808080808680f35b50346105ca5760803660031901126105ca5761098b61334c565b610993613362565b90606435906001600160401b0382116109fa57366023830112156109fa57816004013592846109c1856134fb565b936109cf604051958661343d565b85855236602487830101116108e457856105f89660246020930183880137850101526044359161365c565b8380fd5b50346105ca57806003193601126105ca576020604051600080516020615ad58339815191528152f35b506020806003193601126108e4576001600160401b0391600435908382116105ca57366023830112156105ca578160040135918483116108e45760059460243685881b84018201116109fa57610a7e859395613460565b94610a8c604051968761343d565b838652601f19610a9b85613460565b0187865b828110610ba257505050368190036042190190855b858110610b1b575050505050506040519280840190808552835180925280604083818801981b870101940192955b828710610aef5785850386f35b909192938280610b0b600193603f198a82030186528851613327565b9601920196019592919092610ae2565b83818b1b8301013583811215610b9e5782018481013590868211610b9a576044018136038113610b9a57818992918392604051928392833781018381520390305af4610b65613a51565b9015610b8b5790600191610b79828b6148a1565b52610b84818a6148a1565b5001610ab4565b8051908a8983156105ca575001fd5b8880fd5b8780fd5b6060898201830152899101610a9f565b50346105ca5760603660031901126105ca57610bcc61334c565b6001600160401b0360243581811692908390036105a4576044359182168083036105a457610bf8614b54565b6103e8808511159182610c46575b5050156109fa576001600160a01b03168352600e602052604080842080546001600160801b03191690931791901b600160401b600160801b031617905580f35b111590503880610c06565b50610c5b366134ac565b93909290600019610c6b876155b1565b10610c74578680f35b61096795615540565b50346105ca5760403660031901126105ca57610c9761334c565b610c9f6134ec565b6001600160a01b0390911690338214610d0a573383526005602052604083208260005260205260406000209015159060ff1981541660ff83161790556040519081527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a380f35b60405162461bcd60e51b815260206004820152601960248201527822a9219b99189d1030b8383937bb32903a379031b0b63632b960391b6044820152606490fd5b506101403660031901126105ca57610d65610124356153ea565b610de5610d70613bf3565b610d78613c09565b610d80613c1f565b610d88613c2f565b9160405193610d96856133bd565b6001600160a01b039081168552166020840152306040840152600290810b60608401520b608082015260843560a082015260a43560c082015260c43560e082015260e435610100820152614f02565b909290610104356001600160a01b03811690036105a457601380546001600160b01b031981166001600160b01b03808316600101161790915594610104356001600160a01b0316156112ae57610e4c610e466001600160b01b038816613d39565b15613cee565b6008546001600160b01b0387166000908152600960205260409020819055600160401b81101561121357610e89816001610e999301600855613b4b565b6001600160b01b038916916149e8565b610ea561010435613516565b610104356001600160a01b0316600090815260066020908152604080832084845282528083206001600160b01b038b1690819055808452600790925290912091909155610ef590610e4690613d39565b610104356001600160a01b0316808852600360209081526040808a20805460010190556001600160b01b038916808b526002909252892080546001600160a01b031916831790559088600080516020615b358339815191528180a4610f6b610f5b613c1f565b610f63613c2f565b9030856157ac565b505098915091610f79613bf3565b91610f82613c09565b60405193610f8f856133a2565b6001600160a01b0390811685529081166020808601919091529086168252600f90526040812080546001600160501b0316938415611229575b5050610fd2613c1f565b90610fdb613c2f565b6040519094906001600160401b03610140820190811190821117611213576101408101604090815283825260208083018581526001600160501b0390941682840152600295860b60608401529690940b6080828101919091526001600160801b038a1660a083015260c082019790975260e081019c909c526101008c018290526101208c018290526001600160b01b038b16825260119094529081208a5181546001600160581b0319166001600160581b039190911617815592519399600080516020615af5833981519152946111ea946111c0939261116a926110c8906001600160a01b031683613c3f565b6004600183019261112b60018060501b0360408501511694805495606086015160501b96608087015160681b62ffffff60681b16916080600180911b0319809962ffffff60501b16921617171781556080600180911b0360a08601511690613c68565b60c0830151600282015560e08301516003820155019160018f81901b03610100830151169083541617825561012060018f81901b039101511690613c68565b60405190611177826133a2565b4263ffffffff908116835260208084018381526001600160b01b038e168452601290915260409092209251835463ffffffff191691161782555160001960018d1b011690613c8b565b6040516001600160b01b038916949092839290916001600160a01b03169089908990899086613cb4565b0390a26040519360018060b01b03168452600180861b0316602084015260408301526060820152f35b634e487b7160e01b600052604160045260246000fd5b601380546001600160b01b038116600160b092831c81810190931b6001600160b01b0319169190911790925583546001600160501b03191681179093558284526010602090815260408520835181546001600160a01b03199081166001600160a01b039283161783559290940151920180549091169190921617905592503880610fc8565b606460405162461bcd60e51b815260206004820152602060248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152fd5b50346105ca5760203660031901126105ca57600435815260116020526040812060018101546001600160501b03811680156113c5578360409161016095526010602052209180549260018060a01b0392836001818454169301541660028401549260046003860154950154956040519760018060581b038116895260581c166020880152604087015260608601528060501c60020b60808601528060681c60020b60a086015260801c60c085015260e084015261010083015260018060801b03811661012083015260801c610140820152f35b60405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a59081d1bdad95b88125160821b6044820152606490fd5b50346105ca57806003193601126105ca57604051908060019182549283811c928185169485156114e1575b60209586861081146114cd578588528794939291879082156114ab575050600114611470575b505061145c9250038361343d565b610864604051928284938452830190613327565b908592508082528282205b85831061149357505061145c9350820101388061144e565b8054838901850152879450869390920191810161147b565b925093505061145c94915060ff191682840152151560051b820101388061144e565b634e487b7160e01b83526022600452602483fd5b93607f1693611428565b50346105ca57806003193601126105ca576040517f000000000000000000000000845e4145f7de2822d16fe233ecd0181c61f1d65f6001600160a01b03168152602090f35b50346105ca57602090816003193601126105ca5761154c61334c565b9060608060405161155c816133ec565b8381528386820152836040820152015260018060a01b038092168152600e8352604081209060405161158d816133ec565b82549460018060401b0394858716835281830195808860401c168752604084019761ffff9889809260801c1681526115c86001809901613b7c565b926060870193845260405199868b528160a08c01985116878c0152511660408a015251166060880152519660808088015287518094528260c08801980194915b8483106116155787890388f35b8551805182168a528401518216848a01526040909801979483019491860191611608565b50346105ca5760203660031901126105ca5761165361334c565b61165b614b54565b6001600160a01b031680156108e457600b80546001600160a01b03191691909117905580f35b5060603660031901126105ca576004356116996134ec565b906116a2613378565b6116ab82614b02565b83926116de575b508252600c6020526040822080546001600160a01b0319166001600160a01b0390921691909117905580f35b600a54919250906001600160a01b03908116908216036108e85790386116b2565b50611709366134ac565b90839296959342116119b25761171d614de8565b85875260209760118952604088209182549260018060581b03938481169460018601169060018060581b0319161790556040518a810190600080516020615b15833981519152825260018060a01b0397888a16958660408401528b6060840152608083015260a082015260a0815261179481613422565b519020604051908b82019261190160f01b845260228301526042820152604281526117be816133ec565b519020936117cb886135d4565b86811680941461195d578a94939291908a903b156118d6575061183d9596506040519385850152604084015260ff60f81b9060f81b16606083015260418252611813826133ec565b6040518080958194630b135d3f60e11b988984526004840152604060248401526044830190613327565b03915afa9081156118cb57859161189e575b506001600160e01b0319160361186a576105f8929350614d94565b60405162461bcd60e51b815260048101859052600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606490fd5b6118be9150863d88116118c4575b6118b6818361343d565b810190613a31565b3861184f565b503d6118ac565b6040513d87823e3d90fd5b9360ff60809498979360405194855216868401526040830152606082015282805260015afa15611952578451168015611919570361186a576105f8929350614d94565b60405162461bcd60e51b8152600481018790526011602482015270496e76616c6964207369676e617475726560781b6044820152606490fd5b6040513d86823e3d90fd5b60405162461bcd60e51b8152600481018c9052602760248201527f4552433732315065726d69743a20617070726f76616c20746f2063757272656e6044820152663a1037bbb732b960c91b6064820152608490fd5b60405162461bcd60e51b815260206004820152600e60248201526d14195c9b5a5d08195e1c1a5c995960921b6044820152606490fd5b50346105ca5760203660031901126105ca576020611a0c611a0761334c565b613516565b604051908152f35b50346105ca5760403660031901126105ca57600435611a316134ec565b600a546001600160a01b03908116338114939192859015611b045750818552600c602052808360408720541603611ac457925b15611a8a578352600d6020526040832080546001600160a01b0319169190921617905580f35b60405162461bcd60e51b815260206004820152601260248201527127b7363c902330b936b4b733a1b2b73a32b960711b6044820152606490fd5b60405162461bcd60e51b81526020600482015260186024820152774e6f7420617070726f76656420666f72206661726d696e6760401b6044820152606490fd5b93905080611a645750808452600d602052816040852054163314611a64565b5060403660031901126105ca57611b38613362565b907f000000000000000000000000845e4145f7de2822d16fe233ecd0181c61f1d65f611b638161517d565b906004358210611bdf5781611b76578280f35b6001600160a01b0316803b156108e857828091602460405180948193632e1a7d4d60e01b83528760048401525af18015611bd457611bc1575b50611bba9192615a82565b8038808280f35b91611bce611bba936133d9565b91611baf565b6040513d85823e3d90fd5b60405162461bcd60e51b815260206004820152601960248201527824b739bab33334b1b4b2b73a102ba730ba34bb32aa37b5b2b760391b6044820152606490fd5b50346105ca5760203660031901126105ca576020611c3f6004356135d4565b6040516001600160a01b039091168152f35b50346105ca5760403660031901126105ca57611c6b61334c565b6024359061ffff82168083036109fa576103e890611c87614b54565b116108e8576001600160a01b03168252600e60205260408220805461ffff60801b191660809290921b61ffff60801b1691909117905580f35b5060603660031901126105ca57611cd561334c565b90611cde613362565b906001600160a01b0360443581811681036108e857611d028285168387161061542d565b817f0000000000000000000000004eb881885fe22d895ff299f6cda6e0a8e00e66a016936040519463d9a641e160e01b8652602096878780611d48868560048401615473565b0381855afa968715611e395790889392918798611e1a575b508786811680611de957505086611d91959697985060405180968195829463e343361560e01b845260048401615473565b03925af19384156108ec5793611db6575b50611dad908361548d565b60405191168152f35b611dad919350611ddb90853d8711611de2575b611dd3818361343d565b810190613f42565b9290611da2565b503d611dc9565b925095965050859250611dfc9150615871565b1615611e0a575b5050611dad565b611e139161548d565b3880611e03565b611e32919850843d8611611de257611dd3818361343d565b9638611d60565b6040513d88823e3d90fd5b50346105ca5760203660031901126105ca57600435600854811015611e7c57611e6e602091613b4b565b90546040519160031b1c8152f35b60405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608490fd5b50346105ca5760203660031901126105ca577f29f9e1ebeee07596f3165f3e42cb9d4d8d22b0481e968d6c74be3dd037c15d9b6020611f1361334c565b611f1b614b54565b600a80546001600160a01b0319166001600160a01b03929092169182179055604051908152a180f35b506105f8611f51366134ac565b94939093929192615540565b50346105ca5760403660031901126105ca576020611f91611f7c61334c565b60243590611f8c6107ef83613d39565b6136f7565b6040519015158152f35b506020806003193601126108e45760043590611fb682614b02565b81835260118152826040812060018101908154916004820192835460018060801b0391828260801c92169060801c1717166109fa578382558390556002810183905560030182905555600d81526040832080546001600160a01b0319908116909155612021836135d4565b6001600160a01b03929083811690811580159081612216575b1561217e5750505060085484865260098252806040872055600160401b81101561216a57846120728260016120789401600855613b4b565b906149e8565b6008546000199390848101908111612156578587526009835261209f604088205491613b4b565b90549060031b1c6120b38161207284613b4b565b8752600983526040872055848652856040812055600854801561214257916002918588969594016120e381613b4b565b8782549160031b1b191690556008556120fb876135d4565b8787526004835260408720858154169055169384865260038252604086209081540190558585525260408320908154169055600080516020615b358339815191528280a480f35b634e487b7160e01b87526031600452602487fd5b634e487b7160e01b87526011600452602487fd5b634e487b7160e01b86526041600452602486fd5b61218a575b5050612078565b61219390613516565b600019810191908211612156578587526007835260408720548281036121da575b508587528660408120558652600682526040862090865281528460408120553880612183565b8188526006845260408820838952845260408820548289526006855260408920828a5285528060408a20558852600784526040882055386121b4565b878952601185526040808a208054600160581b600160f81b0319169055600c8652892080548716905561203a565b50346105ca576105f861225636613477565b906040519261226484613407565b85845261365c565b50806003193601126105ca57476122805780f35b6105f84733615a82565b50346105ca5760603660031901126105ca576004356024356044356001600160401b038082116123ff57366023830112156123ff5781600401359081116123ff5781013660248201116123ff5781900392606084126123ff5760408051946122f1866133a2565b126123ff5761236d9061233460646040519461230c866133a2565b6123186024820161338e565b86526123266044820161338e565b60208701528588520161338e565b60208601908152926001600160a01b039283917f000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a06156fd565b1633036123bd57806123a2575b5082612384578480f35b80602061239a9551015116903392511690615201565b388080808480f35b6123b790828651511633908486511690615201565b3861237a565b60405162461bcd60e51b815260206004820152601a602482015279496e76616c69642063616c6c6572206f662063616c6c6261636b60301b6044820152606490fd5b8480fd5b50346105ca57806003193601126105ca576020611a0c614de8565b50346105ca57806003193601126105ca576040517f000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a06001600160a01b03168152602090f35b50346105ca57806003193601126105ca576020604051600080516020615b158339815191528152f35b50346105ca5760403660031901126105ca576124a661334c565b602435916124b382613516565b8310156124e05760209260409260018060a01b031682526006845282822090825283522054604051908152f35b60405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608490fd5b50346105ca5760203660031901126105ca576020906004358152600c8252604060018060a01b0391205416604051908152f35b50346105ca576105f861257e36613477565b9161259161258c84336136f7565b6135fa565b6137bf565b5060c03660031901126105ca576126b76060916125b460a4356153ea565b6004358152601160205260408120906040600080516020615af5833981519152612731600185015460018060501b0381168552601060205261271e61271861266486882060018060a01b03815416906001808060a01b039101541688519161261b836133bd565b8252602082015230888201528460501c60020b8c8201528460681c60020b608082015260243560a082015260443560c082015260643560e0820152608435610100820152614f02565b949399929a919c909b61268a8860801c8960681c60020b8a60501c60020b308a86613d6f565b908082176001600160801b031661275c575b5050608088901c8c016001600160801b031690600101613c68565b60043581526012602052209160018060a01b03169382546126f363ffffffff928060801c908060681c60020b9060501c60020b8585168a613f74565b63ffffffff19909116429092169190911780845560201c6001600160801b0316613d56565b90613c8b565b6040519182918789886004359886613cb4565b0390a26001600160801b03169161274a83600435614c6b565b60405192835260208301526040820152f35b6004830180546001600160801b038082169390930183166001600160801b0319909116178082556127979360809190911c0190911690613c68565b388061269c565b50346105ca57806003193601126105ca576020600854604051908152f35b50346105ca5760603660031901126105ca576127d661334c565b906024356001600160401b038082116108e857366023830112156108e857816004013561280281613460565b92612810604051948561343d565b8184526024602085019260051b82010190368211612bca57602401915b818310612bce575050506044359081116108e857366023820112156108e85780600401359061285b82613460565b91612869604051938461343d565b8083526024602084019160051b83010191368311612bca57602401905b828210612bb257505050612898614b54565b8260018060a01b0385168152600e60205260016040822001938251845103612b6d57845415801590612b64575b612b1b575b81905b8451821015612a7e576001600160a01b036128e883866148a1565b511615612a3d576001600160a01b0361290183866148a1565b511661ffff61291084886148a1565b51166040519161291f836133a2565b825260208201528654600160401b811015612a295760018101808955811015612a15579061ffff6020612975938a8852818820019260018060a01b0381511660018060a01b031985541617845501511690614a00565b61ffff8061298384886148a1565b511691160161ffff8111612a0157906129fb907fff5b7ae049a1a9fb20442c9c2abaa248c078a294b476cb51c8951028b775e46e60606001600160a01b036129cb84896148a1565b511661ffff6129da858b6148a1565b51166040519160018060a01b038d16835260208301526040820152a1614875565b906128cd565b634e487b7160e01b83526011600452602483fd5b634e487b7160e01b85526032600452602485fd5b634e487b7160e01b85526041600452602485fd5b60405162461bcd60e51b815260206004820152601960248201527805661756c7420616464726573732063616e6e6f74206265203603c1b6044820152606490fd5b868684928751612a8c578380f35b61ffff6103e8911603612ac3576001600160a01b039091168252600e60205260408220612abc9190600101614a1f565b8180808380f35b60405162461bcd60e51b815260206004820152602a60248201527f546f74616c20666565206d75737420626520657175616c20746f204645455f4460448201526922a727a6a4a720aa27a960b11b6064820152608490fd5b6001600160a01b0386168252600e6020526040822060010180548382559081612b46575b50506128ca565b835260208320908101905b81811015612b3f57838155600101612b51565b508351156128c5565b60405162461bcd60e51b815260206004820152601f60248201527f5661756c747320616e642066656573206c656e677468206d69736d61746368006044820152606490fd5b60208091612bbf8461338e565b815201910190612886565b8580fd5b823561ffff81168103612be95781526020928301920161282d565b8680fd5b5060a03660031901126105ca57612c05600435614b02565b612c106084356153ea565b6001600160801b03612c20614833565b16156105ca5760043581526011602052604081206001810154906001600160801b03612c4a614833565b168260801c106108e8576001600160a01b03612c6e6001600160501b038416614982565b16916004358452601260205260408420805490612cb9612ca68460801c8560681c60020b8660501c60020b63ffffffff87168a613f74565b602084901c6001600160801b0316613d56565b608084901c6001600160801b038216111561308857508260801c915b6001600160a01b0319164263ffffffff161790556001600160801b038116612ec2575b612e6a90612e0d612d9494612d0b614833565b6001600160801b03612d2185608089901c614926565b166001600160801b039091161115612eb2576001612d42848760801c614926565b955b612def612d5f888360681c60020b8460501c60020b8d615925565b99909a6044358c101580612ea6575b612d779061493f565b8360801c908460681c60020b908560501c60020b90309089613d6f565b60048601918254908d878060801b0391888060801b0391898060801b03160116878060801b038316011690868060801b03191617808355858060801b0391868060801b03908d888060801b031601169060801c011690613c68565b84828060801b039188848060801b039160801c031603169101613c68565b604080516001600160801b0385811682528316602082015290810186905260608101859052600435907f5e41cd741a4f79d713bd0c5670fae681a19f07bb5eca4955e68e322e9e15287290608090a26001600160801b0392613d56565b16600160ff1b8114612e9257612e869060409403600435614c6b565b82519182526020820152f35b634e487b7160e01b84526011600452602484fd5b506064358b1015612d6e565b6001612ebc614833565b95612d44565b612eda818360681c60020b8460501c60020b87615925565b858793929352600e602052612ef460016040892001613b7c565b87815115600014612f99575050600b54604080516309e3d67b60e31b815294909285928392612f52926001600160801b039081169291169060688a901c600290810b9160508c901c90910b906001600160a01b0316600487016148ea565b038189895af18015611e3957612d9494612e6a93612e0d92612f7b575b505b9450509050612cf8565b612f939060403d6040116104c3576104a6818361343d565b50612f6f565b909394919692815b85518110156130705761ffff6020612fb983896148a1565b510151169060406001600160a01b03612fd2838a6148a1565b515116928b6103e86130018c82612ff08660018060801b0393613f61565b0416936001600160801b0393613f61565b041693613031835195869384936309e3d67b60e31b85528b60681c60020b908c60501c60020b90600487016148ea565b0381878a5af19182156119525761304d92613052575b50614875565b612fa1565b61306a9060403d6040116104c3576104a6818361343d565b50613047565b50929650509250612e6a9150612e0d612d9494612f71565b91612cd5565b50346105ca5760403660031901126105ca576130a861334c565b6024356001600160a01b03806130bd836135d4565b16809184161461316d5780331490811561314c575b50156130e1576105f891614d94565b60405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c0000006064820152608490fd5b9050835260056020526040832033845260205260ff604084205416386130d2565b60405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608490fd5b50346105ca5760203660031901126105ca576020611c3f600435614ad8565b50346105ca57806003193601126105ca576040519080805491600183811c92818516948515613273575b60209586861081146114cd578588528794939291879082156114ab57505060011461323857505061145c9250038361343d565b908592508180528282205b85831061325b57505061145c9350820101388061144e565b80548389018501528794508693909201918101613243565b93607f1693613205565b9050346108e45760203660031901126108e45760043563ffffffff60e01b81168091036108e8576020925063780e9d6360e01b81149081156132c1575b5015158152f35b6380ac58cd60e01b8114915081156132f3575b81156132e2575b50386132ba565b6301ffc9a760e01b149050386132db565b635b5e139f60e01b811491506132d4565b60005b8381106133175750506000910152565b8181015183820152602001613307565b9060209161334081518092818552858086019101613304565b601f01601f1916010190565b600435906001600160a01b03821682036105a457565b602435906001600160a01b03821682036105a457565b604435906001600160a01b03821682036105a457565b35906001600160a01b03821682036105a457565b604081019081106001600160401b0382111761121357604052565b61012081019081106001600160401b0382111761121357604052565b6001600160401b03811161121357604052565b608081019081106001600160401b0382111761121357604052565b602081019081106001600160401b0382111761121357604052565b60c081019081106001600160401b0382111761121357604052565b601f909101601f19168101906001600160401b0382119082101761121357604052565b6001600160401b0381116112135760051b60200190565b60609060031901126105a4576001600160a01b039060043582811681036105a4579160243590811681036105a4579060443590565b60c09060031901126105a4576004356001600160a01b03811681036105a45790602435906044359060643560ff811681036105a457906084359060a43590565b6024359081151582036105a457565b6001600160401b03811161121357601f01601f191660200190565b6001600160a01b0316801561353657600052600360205260406000205490565b60405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608490fd5b1561359457565b60405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606490fd5b6000908152600260205260409020546001600160a01b03166135f781151561358d565b90565b1561360157565b60405162461bcd60e51b815260206004820152602d60248201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560448201526c1c881bdc88185c1c1c9bdd9959609a1b6064820152608490fd5b9061368093929161367061258c84336136f7565b61367b8383836137bf565b613a81565b1561368757565b60405162461bcd60e51b8152806136a0600482016136a4565b0390fd5b60809060208152603260208201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b60608201520190565b906001600160a01b03808061370b846135d4565b1693169183831493841561373e575b508315613728575b50505090565b61373491929350614ad8565b1614388080613722565b909350600052600560205260406000208260005260205260ff60406000205416923861371a565b1561376c57565b60405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608490fd5b6137e3916137cc846135d4565b6001600160a01b0393848416939185168414613765565b8382169384156139e0578391821580156139a4575b156138eb575060085460008781526009602052604090208190559150600160401b821015611213576138529261383987612072856001899701600855613b4b565b8286036138b8575b5061384b866135d4565b1614613765565b600080516020615b35833981519152600084815260046020526040812060018060a01b03199081815416905583825260036020526040822060001981540190558482526040822060018154019055858252600260205284604083209182541617905580a4565b6138c190613516565b60406000878152600660205281812083825260205288828220558881526007602052205538613841565b8583036138fd575b5061385292613839565b613908919250613516565b60001981019190821161398e576138529284926000908882526020906007825260409182842054828103613957575b508a845283838120558684526006815282842091845252812055926138f3565b8785526006825283852083865282528385205488865260068352848620828752835280858720558552600782528385205538613937565b634e487b7160e01b600052601160045260246000fd5b60008881526011602090815260408083208054600160581b600160f81b0319169055600c909152902080546001600160a01b03191690556137f8565b60405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b908160209103126105a457516001600160e01b0319811681036105a45790565b3d15613a7c573d90613a62826134fb565b91613a70604051938461343d565b82523d6000602084013e565b606090565b9192813b15613b4257602091613ad3916000604051958680958194630a85bd0160e11b9a8b845233600485015260018060a01b0380951660248501526044840152608060648401526084830190613327565b0393165af160009181613b22575b50613b1457613aee613a51565b80519081613b0f5760405162461bcd60e51b8152806136a0600482016136a4565b602001fd5b6001600160e01b0319161490565b613b3b91925060203d81116118c4576118b6818361343d565b9038613ae1565b50505050600190565b600854811015613b6657600860005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b908154613b8881613460565b92604093613b988551918261343d565b828152809460208092019260005281600020906000935b858510613bbe57505050505050565b60018481928451613bce816133a2565b61ffff8754858060a01b038116835260a01c1683820152815201930194019391613baf565b6004356001600160a01b03811681036105a45790565b6024356001600160a01b03811681036105a45790565b6044358060020b81036105a45790565b6064358060020b81036105a45790565b8054600160581b600160f81b03191660589290921b600160581b600160f81b0316919091179055565b80546001600160801b031660809290921b6001600160801b031916919091179055565b8054600160201b600160a01b03191660209290921b600160201b600160a01b0316919091179055565b6001600160801b03918216815291166020820152604081019190915260608101919091526001600160a01b03909116608082015260a00190565b15613cf557565b60405162461bcd60e51b815260206004820152601c60248201527b115490cdcc8c4e881d1bdad95b88185b1c9958591e481b5a5b9d195960221b6044820152606490fd5b6000908152600260205260409020546001600160a01b0316151590565b6001600160801b03918216908216019190821161398e57565b959391613d7c93916157ac565b50509150926002850193613da6613db36003875484039460018060801b0393848092168097613db9565b1698019384548603613db9565b16945555565b8181029190600019828209918380841093039183830393600160801b93858511156105a45714613df6570990828211900360801b910360801c1790565b5050505060801c90565b8181029190600019828209918380841093039183830393600160601b93858511156105a45714613e3d570990828211900360a01b910360601c1790565b5050505060601c90565b90606082901b90600160601b600019818509938380861095039480860395868511156105a45714613ec4579082910981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b505091500490565b9181830291600019818509938380861095039480860395868511156105a45714613ec4579082910981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b908160209103126105a457516001600160a01b03811681036105a45790565b8181029291811591840414171561398e57565b90949291946000946000600160a01b6001900380941690818152602092600e845260409081832096825193613fa8856133ec565b885493600160401b6001900394858116875285808a8901988184861c168a528481019d8e61ffff809660801c169052600101613fe390613b7c565b606082015251169751169a511698861595861580976144d3575b806144ca575b61401a575b50505050505050505050505050909150565b63ffffffff809216824216038281116144b65782169889156144a257835163ef01df4f60e01b815260049b9291839082908e9082905afa90811561449857908791879161447b575b5016801561446657845193606085018581108482111761445257918c8e96928994895260028452868401918936843761409a85614884565b52846140a585614891565b528851978894639d3a524160e01b86528860248701928701525180915260448501929186905b8983831061443257505050505082809103915afa93841561442957859461431a575b505050506141046140fd82614891565b5191614884565b5160060b9060060b0396667fffffffffffff19667fffffffffffff8913818a1217614307578760060b9860060b89156142f4576000199181148a8314166142e15789810560020b9984821291826142d2575b505061429f575b505061417761417161417f9b9c9d9e6144dc565b9b6144dc565b998a976144dc565b8b9188938d8180849c16911611614294575b8281169084811682116142595750505050906141ad9291615666565b905b61421d575b5050836141cb575b808080808080808e9d9c614008565b61420361420b9593640757b12c006141fd6142119a9b9997956141f86103e89660018060801b0398613f61565b613f61565b04613f61565b04169161563d565b90613d56565b903880808080806141bc565b8299916103e861424887640757b12c006141fd61420b966141f86142519a60018060801b0398613f61565b041687896155f1565b9638806141b4565b90919296995084939594161160001461428957509261427d82614283949583615666565b936156cb565b936141af565b9350614283926156cb565b8d94508c9350614191565b909d97627fffff1981146142bf57979d509096019561417761417161415d565b634e487b7160e01b835260118f52602483fd5b0760060b151590503880614156565b634e487b7160e01b845260118352602484fd5b634e487b7160e01b845260128352602484fd5b634e487b7160e01b835260118252602483fd5b90919293503d8086863e61432e818661343d565b8401918185840312612bca578451818111612be95785019483601f87011215612be95785519561435d87613460565b9661436a8551988961343d565b808852868089019160051b83010191868311614425578701905b8282106144085750505084810151918211612be9570182601f82011215612bca5783808251936143bf6143b686613460565b9151918261343d565b848152019260051b820101928311612bca578301905b8282106143e95750505050388080806140ed565b81516001600160581b0381168103612be95781529083019083016143d5565b81518060060b8103614421578152908701908701614384565b8a80fd5b8980fd5b513d86823e3d90fd5b8451821686528d98508b97509485019493909301926001909101906140cb565b50634e487b7160e01b875260418d52602487fd5b50505050509a50505050505050505050915090565b6144929150843d8611611de257611dd3818361343d565b38614062565b85513d88823e3d90fd5b505050509a50505050505050505050915090565b634e487b7160e01b85526011600452602485fd5b508a1515614003565b508b1515613ffd565b8060020b908160171d60020b80910160020b189062ffffff8216620d89e8811161482157600160801b9260018116614809575b600281166147ed575b600481166147d1575b600881166147b5575b60108116614799575b6020811661477d575b60408116614761575b608091828216614746575b610100821661472b575b6102008216614710575b61040082166146f5575b61080082166146da575b61100082166146bf575b61200082166146a4575b6140008216614689575b618000821661466e575b620100008216614653575b620200008216614639575b62040000809110156145ec575b5050506000126145e3575b63ffffffff0160201c6001600160a01b031690565b600019046145ce565b811661461f575b6208000016614604575b80806145c3565b6b048a170391f7dc42444e8fa26000929302901c91906145fd565b6d2216e584f5fa1ea926041bedfe98909302811c926145f3565b936e5d6af8dedb81196699c329225ee60402821c936145b6565b936f09aa508b5b7a84e1c677de54f3e99bc902821c936145ab565b936f31be135f97d08fd981231505542fcfa602821c936145a0565b936f70d869a156d2a1b890bb3df62baf32f702821c93614596565b936fa9f746462d870fdf8a65dc1f90e061e502821c9361458c565b936fd097f3bdfd2022b8845ad8f792aa582502821c93614582565b936fe7159475a2c29b7443b29c7fa6e889d902821c93614578565b936ff3392b0822b70005940c7a398e4b70f302821c9361456e565b936ff987a7253ac413176f2b074cf7815e5402821c93614564565b936ffcbe86c7900a88aedcffc83b479aa3a402821c9361455a565b936ffe5dee046a99a2a811c461f1969c305302821c93614550565b926fff2ea16466c96a3843ec78b326b528610260801c92614545565b926fff973b41fa98c081472e6896dfb254c00260801c9261453c565b926fffcb9843d60f6159c9db58835c9266440260801c92614533565b926fffe5caca7e10e4e61c3624eaa0941cd00260801c9261452a565b926ffff2e50f5f656932ef12357cf3c7fdcc0260801c92614521565b926ffff97272373d413259a46990580e213a0260801c92614518565b6ffffcb933bd6fad37aa2d162d1a594001935061450f565b604051633c10250f60e01b8152600490fd5b6024356001600160801b03811681036105a45790565b6044356001600160801b03811681036105a45790565b6064356001600160801b03811681036105a45790565b600019811461398e5760010190565b805115613b665760200190565b805160011015613b665760400190565b8051821015613b665760209160051b010190565b51906001600160801b03821682036105a457565b91908260409103126105a4576135f760206148e3846148b5565b93016148b5565b6001600160a01b039091168152600291820b602082015291900b60408201526001600160801b0391821660608201529116608082015260a00190565b6001600160801b03918216908216039190821161398e57565b1561494657565b60405162461bcd60e51b8152602060048201526014602482015273507269636520736c69707061676520636865636b60601b6044820152606490fd5b60018060501b031660005260106020526135f76040600020604051906149a7826133a2565b80546001600160a01b0390811683526001909101541660208201527f000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a06156fd565b919082549060031b91821b91600019901b1916179055565b805461ffff60a01b191660a09290921b61ffff60a01b16919091179055565b818114614ad457815491600160401b8311611213578154838355808410614aab575b506000526020600020906000526020600020906000905b838210614a655750505050565b806001918403614a7e575b928101929181019101614a58565b818060a01b03815416828060a01b0319855416178455614aa661ffff825460a01c1685614a00565b614a70565b6000838152846020822092830192015b828110614ac9575050614a41565b818155600101614abb565b5050565b614ae46107ef82613d39565b60009081526011602052604090205460581c6001600160a01b031690565b614b0c90336136f7565b15614b1357565b60405162461bcd60e51b815260206004820152600c60248201526b139bdd08185c1c1c9bdd995960a21b6044820152606490fd5b519081151582036105a457565b60405163e8ae2b6960e01b8152600080516020615ad583398151915260048201523360248201526020816044817f0000000000000000000000004eb881885fe22d895ff299f6cda6e0a8e00e66a06001600160a01b03165afa9081156105b057600091614bc4575b50156105a457565b906020823d8211614bf5575b81614bdd6020938361343d565b810103126105ca5750614bef90614b47565b38614bbc565b3d9150614bd0565b600060443d106135f757604051600319913d83016004833e81516001600160401b03918282113d602484011117614c5a57818401948551938411614c62573d85010160208487010111614c5a57506135f79291016020019061343d565b949350505050565b50949350505050565b6000818152600d602052604081205490926001600160a01b03918216918215614d8d57600a5416918215614d8d578214614ca6575b50505050565b813b156109fa578391604483926040519485938492626e65c960e41b845288600485015260248401525af19081614d7a575b50614d73576001908260033d11614d63575b806308c379a014614d5a57634e487b7114614d10575b506108ec57505b38808080614ca0565b8260233d11614d4c575b15614d00578291507f4f27462fbdc9bce16bb573a06acba6b27394e151da96ce8098d8e29a6dc8d64b8280a238614d00565b5060206004843e6001614d1a565b50614d1a614bfd565b50600483803e825160e01c614cea565b5050614d07565b614d86909391936133d9565b9138614cd8565b5050505050565b816000526011602052614dab816040600020613c3f565b6001600160a01b0380614dbd846135d4565b169116907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600080a4565b307f0000000000000000000000001c4cbb62e18cf9c137c5d85096b5bc78190826916001600160a01b03161480614ed9575b15614e43577f31a83b6c956a91e5d24b696d31d7edfdfc3001b91421e596fe859041a4f05bb490565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f17c93d93526d3bfa00a29c0aa0af2abb9197e14a1e5273df18858d2d357d726860408201527fad7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a560608201524660808201523060a082015260a08152614ed381613422565b51902090565b507f000000000000000000000000000000000000000000000000000000000000dede4614614e1a565b8051602082015160405193916001600160a01b039182169116614f24856133a2565b8452602084019081526001600160a01b03614f5f857f000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a06156fd565b166060614f6b82615871565b81860161507e614f7e825160020b6144dc565b926080890193614f91855160020b6144dc565b60a08b015160c08c015190929082826001600160a01b0380831690821611615172575b50506001600160a01b03858116959083168611615116575050614fd793506155f1565b985b8960018060a01b0360408b015116935160020b945160020b976020604051615000816133a2565b8481523391019081526040805194516001600160a01b0390811660208701529251831690850152511686830152858252615039826133ec565b60405197889586956302abf8a760e61b875233600488015260248701526044860152606485015260018060801b0316608484015260c060a484015260c4830190613327565b03816000855af19283156105b057600093849385916150c7575b506150b59095848660e0830151111591826150b7575b505061493f565b565b61010001511115905038806150ae565b94919350506060843d60601161510e575b816150e56060938361343d565b810103126105ca57508251916150b56151056040602087015196016148b5565b93949390615098565b3d91506150d8565b919490939192906001600160a01b038216111561516657829161513d9161514395946155f1565b9361563d565b6001600160801b03818116908316101561515f57505b98614fd9565b9050615159565b9150506151599261563d565b935091503880614fb4565b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa9081156105b0576000916151b8575090565b906020823d82116151de575b816151d16020938361343d565b810103126105ca57505190565b3d91506151c4565b6001600160a01b039091168152602081019190915260400190565b9293926001600160a01b037f000000000000000000000000845e4145f7de2822d16fe233ecd0181c61f1d65f8116929091908282168414806153e0575b1561530057505050803b156105a457604051630d0e30db60e41b815293600091828660048185855af1958615611bd45761529a95966152ee575b50829360209360405180978195829463a9059cbb60e01b8452600484016151e6565b03925af180156152e1576152ac575050565b6020823d82116152d9575b816152c46020938361343d565b810103126105ca57506152d690614b47565b50565b3d91506152b7565b50604051903d90823e3d90fd5b926152fa6020946133d9565b92615278565b9495948216949392509030850361531c57506150b593506159dc565b604093919293519360208501956323b872dd60e01b8752602486015216604484015260648301526064825260a082019282841060018060401b03851117611213576000809493819460405251925af1615373613a51565b816153a9575b506150b55760405162461bcd60e51b815260206004820152600360248201526229aa2360e91b6044820152606490fd5b80518015925082156153be575b505038615379565b81925090602091810103126105a45760206153d99101614b47565b38806153b6565b508647101561523e565b42116153f257565b60405162461bcd60e51b8152602060048201526013602482015272151c985b9cd858dd1a5bdb881d1bdbc81bdb19606a1b6044820152606490fd5b1561543457565b60405162461bcd60e51b8152602060048201526017602482015276496e76616c6964206f72646572206f6620746f6b656e7360481b6044820152606490fd5b6001600160a01b0391821681529116602082015260400190565b6001600160a01b039081169190823b156105a457602460009283604051958694859363f637731d60e01b85521660048401525af180156105b0576154ce5750565b6150b5906133d9565b92946001600160a01b0390931693919291843b156105a45760009460e493869260ff604051998a98899763d505accf60e01b89523360048a01523060248a01526044890152606488015216608486015260a485015260c48401525af180156105b0576154ce5750565b92946001600160a01b0390931693919291843b156105a45760009461010493869260ff604051998a9889976323f2ebc360e21b89523360048a01523060248a015260448901526064880152600160848801521660a486015260c485015260e48401525af180156105b0576154ce5750565b60206040518092636eb1769f60e11b825281806155d2303360048401615473565b03916001600160a01b03165afa9081156105b0576000916151b8575090565b6156239291906001600160a01b039081831682821611615637575b61561a828416838316613e00565b92031691613ecc565b6001600160801b0381169081036105a45790565b9161560c565b61562392916001600160a01b03919082811683831611615660575b031690613e47565b90615658565b916001600160a01b039190828216838516116156c3575b6156a091838116919085900384169060601b600160601b600160e01b0316613ecc565b91169081156156ad570490565b634e487b7160e01b600052601260045260246000fd5b90929061567d565b6135f792916001600160a01b039190828116838316116156f7575b0316906001600160801b0316613e00565b906156e6565b60018060a01b039161573a615748848080855116946157246020820196838851161161542d565b5116935116604051928391602083019586615473565b03601f19810183528261343d565b51902060405190602082019260ff60f81b845260018060601b03199060601b16602183015260358201527ff96d2474815c32e070cd63233f06af5413efc5dcb430aee4ff18cc29007c562d6055820152605581526157a5816133ec565b5190201690565b60a09293602491604051958694859363514ea4bf60e01b855262ffffff80911692169060181b1760181b176004830152600180861b03165afa9081156105b05760009182938380938193615803575b509493929190565b9450925093505060a0823d821161585a575b8161582260a0938361343d565b810103126105ca5750805160208201516040830151936158506080615849606087016148b5565b95016148b5565b91949392386157fb565b3d9150615815565b519061ffff821682036105a457565b6040516339db007960e21b8152906001600160a01b039060c0908390600490829085165afa9182156105b0576000926158a957505090565b909160c0823d821161591d575b816158c360c0938361343d565b810103126105ca57815192831683036105ca5760208201518060020b036105ca576158f060408301615862565b50606082015160ff8116036105ca575060a08161591260806159199401615862565b5001614b47565b5090565b3d91506158b6565b9392604092835192631d9de38760e11b845260020b600484015260020b602483015260018060801b0316604482015260806064820152600360848201526203078360ec1b60a4820152818160c4816000809860018060a01b03165af19384156159d15780928195615998575b5050509190565b919450915083813d81116159ca575b6159b1818361343d565b810103126105ca57506020825192015191388080615991565b503d6159a7565b8251903d90823e3d90fd5b600092918361573a615a078295604051928391602083019663a9059cbb60e01b8852602484016151e6565b51925af1615a13613a51565b81615a4b575b5015615a2157565b60405162461bcd60e51b815260206004820152600260248201526114d560f21b6044820152606490fd5b8051801592508215615a60575b505038615a19565b81925090602091810103126105a4576020615a7b9101614b47565b3880615a58565b6000808093819382604051615a9681613407565b525af1615aa1613a51565b5015615aa957565b60405162461bcd60e51b815260206004820152600360248201526253544560e81b6044820152606490fdfeff0e0466f109fcf4f5660899d8847c592e1e8dea30ffbe040704b23ad381d7628a82de7fe9b33e0e6bca0e26f5bd14a74f1164ffe236d50e0a36c3ea70f2b81449ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9adddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa164736f6c6343000814000a

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

0000000000000000000000004eb881885fe22d895ff299f6cda6e0a8e00e66a0000000000000000000000000845e4145f7de2822d16fe233ecd0181c61f1d65f0000000000000000000000006d63b39017f379bfd0301293022581c6ef237a19000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a000000000000000000000000045362763166cfed6174d312fa1449ea1fc37988a

-----Decoded View---------------
Arg [0] : _factory (address): 0x4Eb881885FE22D895Ff299f6cdA6e0A8E00E66A0
Arg [1] : _WNativeToken (address): 0x845e4145F7de2822d16FE233Ecd0181c61f1d65F
Arg [2] : _tokenDescriptor_ (address): 0x6d63b39017F379bfd0301293022581C6EF237a19
Arg [3] : _poolDeployer (address): 0xf03875b5Ec5eAc83cab83A6c2ab17844304AA7a0
Arg [4] : _vault (address): 0x45362763166CfED6174d312Fa1449EA1FC37988a

-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 0000000000000000000000004eb881885fe22d895ff299f6cda6e0a8e00e66a0
Arg [1] : 000000000000000000000000845e4145f7de2822d16fe233ecd0181c61f1d65f
Arg [2] : 0000000000000000000000006d63b39017f379bfd0301293022581c6ef237a19
Arg [3] : 000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a0
Arg [4] : 00000000000000000000000045362763166cfed6174d312fa1449ea1fc37988a


[ Download: CSV Export  ]
[ Download: CSV Export  ]

A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.