POL Price: $0.316783 (+2.06%)
 

Overview

POL Balance

Polygon PoS Chain LogoPolygon PoS Chain LogoPolygon PoS Chain Logo0 POL

POL Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

1 Internal Transaction found.

Latest 1 internal transaction

Parent Transaction Hash Block From To
436424332023-06-07 16:33:28616 days ago1686155608
0x839F3578...f5a19b39C
0 POL
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Vault

Compiler Version
v0.8.15+commit.e14f2714

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 53 : Vault.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity 0.8.15;

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/Multicall.sol";
import {INonfungiblePositionManager} from "@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol";
import "@zkbob/proxy/EIP1967Admin.sol";
import "./interfaces/oracles/IOracle.sol";
import "./interfaces/external/univ3/INonfungiblePositionLoader.sol";
import {IBobToken} from "./interfaces/IBobToken.sol";
import "./interfaces/IVaultRegistry.sol";
import "./interfaces/oracles/INFTOracle.sol";
import "./interfaces/ICDP.sol";
import "./libraries/UniswapV3FeesCalculation.sol";
import "./utils/VaultAccessControl.sol";
import "./interfaces/ITreasury.sol";
import "./interfaces/IMinter.sol";

/// @notice Contract of the system vault manager
contract Vault is EIP1967Admin, VaultAccessControl, IERC721Receiver, ICDP, Multicall, ReentrancyGuard {
    using SafeERC20 for IERC20;

    /// @notice Thrown when a vault is private and a depositor is not allowed
    error AllowList();

    /// @notice Thrown when a value of a deposited NFT is less than min single nft capital (protocolParams.minSingleNftCollateral)
    error CollateralUnderflow();

    /// @notice Thrown when a vault has already been initialized
    error Initialized();

    /// @notice Thrown when a pool of NFT is not in the whitelist
    error InvalidPool();

    /// @notice Thrown when NFT's width is too small
    error TooNarrowNFT();

    /// @notice Thrown when a value of a stabilization fee is incorrect
    error InvalidValue();

    /// @notice Thrown when a vault id does not exist
    error InvalidVault();

    /// @notice Thrown when liquidations are private and a liquidator is not allowed
    error LiquidatorsAllowList();

    /// @notice Thrown when the nft limit for one vault would have been exceeded after the deposit
    error NFTLimitExceeded();

    /// @notice Thrown when the system is paused
    error Paused();

    /// @notice Thrown when a position is healthy
    error PositionHealthy();

    /// @notice Thrown when a position is unhealthy
    error PositionUnhealthy();

    /// @notice Thrown when a tick deviation is out of limit
    error TickDeviation();

    /// @notice Thrown when a value is incorrectly equal to zero
    error ValueZero();

    /// @notice Thrown when a vault is tried to be closed and debt has not been paid yet
    error UnpaidDebt();

    /// @notice Thrown when a vault is tried to be closed and debt has not been paid yet
    error VaultNonEmpty();

    /// @notice Thrown when the vault debt limit (protocolParams.maxDebtPerVault) would been exceeded after a deposit
    error DebtLimitExceeded();

    using EnumerableSet for EnumerableSet.AddressSet;

    uint256 public constant DENOMINATOR = 10**9;
    uint256 public constant DEBT_DENOMINATOR = 10**18;
    uint256 public constant YEAR = 365 * 24 * 3600;

    /// @notice Collateral position manager
    INonfungiblePositionManager public immutable positionManager;

    /// @notice Oracle for price estimations
    INFTOracle public immutable oracle;

    /// @notice Bob Stable Token
    IBobToken public immutable token;

    /// @notice Minter Contract
    IMinter public immutable minter;

    /// @notice Vault fees treasury address
    ITreasury public immutable treasury;

    /// @notice Vault Registry
    IVaultRegistry public immutable vaultRegistry;

    /// @notice State variable, which shows if Vault is initialized or not
    bool public isInitialized;

    /// @notice State variable, which shows if Vault is paused or not
    bool public isPaused;

    /// @notice State variable, which shows if Vault is public or not
    bool public isPublic;

    /// @notice State variable, which shows if liquidating is public or not
    bool public isLiquidatingPublic;

    /// @notice Protocol params
    ICDP.ProtocolParams private _protocolParams;

    /// @notice Address set, containing only accounts, which are allowed to make deposits when system is private
    EnumerableSet.AddressSet private _depositorsAllowlist;

    /// @notice Address set, containing only accounts, which are allowed to liquidate when liquidations are private
    EnumerableSet.AddressSet private _liquidatorsAllowlist;

    /// @notice Whitelisted pool params
    mapping(address => ICDP.PoolParams) private _poolParams;

    /// @notice Mapping, returning set of all nfts, managed by vault
    mapping(uint256 => uint256[]) private _vaultNfts;

    /// @notice Mapping, returning normalized debt by vault id (in BOB weis)
    mapping(uint256 => uint256) public vaultNormalizedDebt;

    /// @notice Mapping, returning sum of all outstanding vault debt mints
    mapping(uint256 => uint256) public vaultMintedDebt;

    /// @notice Mapping, returning owed by vault id (in BOB weis)
    mapping(uint256 => uint256) public vaultOwed;

    /// @notice Mapping, returning id of a vault, that storing specific nft
    mapping(uint256 => uint256) public vaultIdByNft;

    /// @notice State variable, constantly increasing debt normalization rate, accounting for all accumulated stability fees
    uint216 public normalizationRate;

    /// @notice State variable, returning latest normalization rate update timestamp
    uint40 public normalizationRateUpdateTimestamp;

    /// @notice State variable, returning current stabilisation fee per second (multiplied by DEBT_DENOMINATOR)
    uint256 public stabilisationFeeRateD18;

    /// @notice State variable, meaning normalized total protocol debt
    uint256 public normalizedGlobalDebt;

    /// @notice Creates a new contract
    /// @param positionManager_ Collateral position manager
    /// @param oracle_ Oracle
    /// @param treasury_ Vault fees treasury
    /// @param token_ Address of token
    /// @param minter_ Address of minter contract
    /// @param vaultRegistry_ Address of vault registry
    constructor(
        INonfungiblePositionManager positionManager_,
        INFTOracle oracle_,
        address treasury_,
        address token_,
        address minter_,
        address vaultRegistry_
    ) {
        if (
            address(positionManager_) == address(0) ||
            address(oracle_) == address(0) ||
            address(treasury_) == address(0) ||
            address(token_) == address(0) ||
            address(minter_) == address(0) ||
            address(vaultRegistry_) == address(0)
        ) {
            revert AddressZero();
        }

        positionManager = positionManager_;
        oracle = oracle_;
        treasury = ITreasury(treasury_);
        token = IBobToken(token_);
        minter = IMinter(minter_);
        vaultRegistry = IVaultRegistry(vaultRegistry_);
        isInitialized = true;
    }

    /// @notice Initialized a new contract.
    /// @param admin Protocol admin
    /// @param stabilisationFee_ BOB initial stabilisation fee
    /// @param maxDebtPerVault Initial max possible debt to a one vault (nominated in BOB weis)
    function initialize(
        address admin,
        uint256 stabilisationFee_,
        uint256 maxDebtPerVault
    ) external {
        if (isInitialized) {
            revert Initialized();
        }

        if (admin == address(0)) {
            revert AddressZero();
        }

        if (stabilisationFee_ > DEBT_DENOMINATOR / YEAR) {
            revert InvalidValue();
        }

        _setupRole(OPERATOR, admin);
        _setupRole(ADMIN_ROLE, admin);

        _setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE);
        _setRoleAdmin(ADMIN_DELEGATE_ROLE, ADMIN_ROLE);
        _setRoleAdmin(OPERATOR, ADMIN_DELEGATE_ROLE);

        // initial value
        normalizationRate = uint216(DEBT_DENOMINATOR);
        stabilisationFeeRateD18 = stabilisationFee_;
        normalizationRateUpdateTimestamp = uint40(block.timestamp);
        _protocolParams.maxDebtPerVault = maxDebtPerVault;
        isInitialized = true;

        // initial approve to minter
        token.approve(address(minter), type(uint256).max);
    }

    // -------------------   PUBLIC, VIEW   -------------------

    /// @inheritdoc IERC165
    function supportsInterface(bytes4 interfaceId)
        public
        view
        virtual
        override(AccessControlEnumerable)
        returns (bool)
    {
        return super.supportsInterface(interfaceId) || type(IERC721Receiver).interfaceId == interfaceId;
    }

    /// @inheritdoc ICDP
    function poolParams(address pool) external view returns (PoolParams memory) {
        return _poolParams[pool];
    }

    /// @inheritdoc ICDP
    function calculateVaultCollateral(uint256 vaultId)
        external
        view
        returns (
            uint256 total,
            uint256 liquidationLimit,
            uint256 borrowLimit
        )
    {
        (total, liquidationLimit, ) = _calculateVaultCollateral(vaultId, 0, LIQUIDATION_LIMIT);
        (, borrowLimit, ) = _calculateVaultCollateral(vaultId, 0, BORROW_LIMIT);
    }

    /// @inheritdoc ICDP
    function getOverallDebt(uint256 vaultId) public view returns (uint256) {
        uint256 updateTimestamp = normalizationRateUpdateTimestamp;
        uint256 globalRate = normalizationRate;

        if (block.timestamp > updateTimestamp) {
            globalRate += FullMath.mulDiv(
                stabilisationFeeRateD18 * (block.timestamp - updateTimestamp),
                globalRate,
                DEBT_DENOMINATOR
            );
        }

        return _getOverallDebt(vaultId, globalRate);
    }

    // -------------------  PUBLIC, MUTATING   -------------------

    /// @notice Recalculate normalizationRate and increase unrealized interest accordingly
    function updateNormalizationRate() public returns (uint256 updatedNormalizationRate) {
        uint256 currentNormalizationRate = normalizationRate;
        uint256 updateTimestamp = normalizationRateUpdateTimestamp;

        if (block.timestamp == updateTimestamp) {
            return currentNormalizationRate;
        }

        uint256 normalizationRateDelta = FullMath.mulDiv(
            stabilisationFeeRateD18 * (block.timestamp - updateTimestamp),
            currentNormalizationRate,
            DEBT_DENOMINATOR
        );
        uint256 unrealizedInterestToIncrease = FullMath.mulDiv(
            normalizedGlobalDebt,
            normalizationRateDelta,
            DEBT_DENOMINATOR
        );

        if (unrealizedInterestToIncrease > 0) {
            // Increasing unrealized interest
            treasury.add(unrealizedInterestToIncrease);
        }

        updatedNormalizationRate = currentNormalizationRate + normalizationRateDelta;
        normalizationRate = uint216(updatedNormalizationRate);
        normalizationRateUpdateTimestamp = uint40(block.timestamp);

        emit NormalizationRateUpdated(updatedNormalizationRate);
    }

    // -------------------  EXTERNAL, VIEW  -------------------

    /// @notice Get all NFTs, managed by vault with given id
    /// @param vaultId Id of the vault
    /// @return uint256[] Array of NFTs, managed by vault
    function vaultNftsById(uint256 vaultId) external view returns (uint256[] memory) {
        return _vaultNfts[vaultId];
    }

    /// @notice Get all verified depositors
    /// @return address[] Array of verified depositors
    function depositorsAllowlist() external view returns (address[] memory) {
        return _depositorsAllowlist.values();
    }

    /// @notice Get all verified liquidators
    /// @return address[] Array of verified liquidators
    function liquidatorsAllowlist() external view returns (address[] memory) {
        return _liquidatorsAllowlist.values();
    }

    /// @inheritdoc ICDP
    function protocolParams() external view returns (ProtocolParams memory) {
        return _protocolParams;
    }

    // -------------------  EXTERNAL, MUTATING  -------------------

    /// @notice Open a new Vault
    /// @return vaultId Id of the new vault
    function openVault() public onlyUnpaused nonReentrant returns (uint256 vaultId) {
        if (!isPublic && !_depositorsAllowlist.contains(msg.sender)) {
            revert AllowList();
        }

        vaultId = vaultRegistry.mint(msg.sender);

        emit VaultOpened(msg.sender, vaultId);
    }

    /// @notice Close a vault
    /// @param vaultId Id of the vault
    /// @param collateralRecipient The address of collateral recipient
    function closeVault(uint256 vaultId, address collateralRecipient) external onlyUnpaused nonReentrant {
        _requireVaultAuth(vaultId);

        if (vaultNormalizedDebt[vaultId] != 0) {
            revert UnpaidDebt();
        }

        _closeVault(vaultId, collateralRecipient);

        emit VaultClosed(msg.sender, vaultId);
    }

    /// @notice Burns a vault NFT
    /// @param vaultId id of the vault NFT to burn
    function burnVault(uint256 vaultId) external onlyUnpaused nonReentrant {
        _requireVaultAuth(vaultId);

        if (vaultOwed[vaultId] != 0 || _vaultNfts[vaultId].length != 0) {
            revert VaultNonEmpty();
        }

        vaultRegistry.burn(vaultId);
    }

    /// @notice Deposit collateral to a given vault
    /// @param vaultId Id of the vault
    /// @param nft Collateral NFT to be deposited
    function depositCollateral(uint256 vaultId, uint256 nft) public nonReentrant {
        positionManager.safeTransferFrom(msg.sender, address(this), nft, abi.encode(vaultId));
    }

    /// @notice Withdraw collateral from a given vault
    /// @param nft Collateral NFT to be withdrawn
    function withdrawCollateral(uint256 nft) external nonReentrant {
        uint256 currentNormalizationRate = updateNormalizationRate();

        uint256 vaultId = vaultIdByNft[nft];
        _requireVaultAuth(vaultId);

        uint256[] storage vaultNfts = _vaultNfts[vaultId];
        uint256 nftsCount = vaultNfts.length;
        for (uint256 i = 0; i < nftsCount; ++i) {
            if (vaultNfts[i] == nft) {
                if (i < nftsCount - 1) {
                    vaultNfts[i] = vaultNfts[nftsCount - 1];
                }
                vaultNfts.pop();
                break;
            }
        }
        delete vaultIdByNft[nft];

        positionManager.transferFrom(address(this), msg.sender, nft);

        // checking that health factor is more or equal than 1
        (, uint256 borrowLimit, ) = _calculateVaultCollateral(vaultId, 0, SAFE_BORROW_LIMIT);
        if (borrowLimit < _getOverallDebt(vaultId, currentNormalizationRate)) {
            revert PositionUnhealthy();
        }

        emit CollateralWithdrew(msg.sender, vaultId, nft);
    }

    /// @notice Mint debt on a given vault
    /// @param vaultId Id of the vault
    /// @param amount The debt amount to be mited
    function mintDebt(uint256 vaultId, uint256 amount) public nonReentrant onlyUnpaused {
        _requireVaultAuth(vaultId);
        uint256 currentNormalizationRate = updateNormalizationRate();

        uint256 normalizedDebtDelta = FullMath.mulDivRoundingUp(amount, DEBT_DENOMINATOR, currentNormalizationRate);
        vaultNormalizedDebt[vaultId] += normalizedDebtDelta;
        vaultMintedDebt[vaultId] += amount;
        normalizedGlobalDebt += normalizedDebtDelta;

        uint256 overallVaultDebt = _getOverallDebt(vaultId, currentNormalizationRate);

        (, uint256 borrowLimit, ) = _calculateVaultCollateral(vaultId, 0, SAFE_BORROW_LIMIT);
        if (borrowLimit < overallVaultDebt) {
            revert PositionUnhealthy();
        }

        if (_protocolParams.maxDebtPerVault < overallVaultDebt) {
            revert DebtLimitExceeded();
        }

        minter.mint(msg.sender, amount);

        emit DebtMinted(msg.sender, vaultId, amount);
    }

    /// @notice Burn debt on a given vault
    /// @param vaultId Id of the vault
    /// @param amount The debt amount to be burned
    function burnDebt(uint256 vaultId, uint256 amount) external nonReentrant {
        uint256 currentNormalizationRate = updateNormalizationRate();

        uint256 overallDebt = _getOverallDebt(vaultId, currentNormalizationRate);
        amount = (overallDebt < amount) ? overallDebt : amount;

        token.transferFrom(msg.sender, address(this), amount);

        uint256 mintedDebt = vaultMintedDebt[vaultId];
        uint256 tokensToBurn = FullMath.mulDiv(mintedDebt, amount, overallDebt);

        uint256 normalizedDebtToBurn = FullMath.mulDivRoundingUp(amount, DEBT_DENOMINATOR, currentNormalizationRate);

        vaultNormalizedDebt[vaultId] -= normalizedDebtToBurn;
        normalizedGlobalDebt -= normalizedDebtToBurn;
        vaultMintedDebt[vaultId] = mintedDebt - tokensToBurn;

        token.transferAndCall(address(treasury), amount - tokensToBurn, "");
        minter.burnFrom(address(this), tokensToBurn);

        emit DebtBurned(msg.sender, vaultId, amount);
    }

    /// @inheritdoc ICDP
    function liquidate(uint256 vaultId) external nonReentrant {
        if (!isLiquidatingPublic && !_liquidatorsAllowlist.contains(msg.sender)) {
            revert LiquidatorsAllowList();
        }
        uint256 currentNormalizationRate = updateNormalizationRate();
        uint256 currentNormalizedDebt = vaultNormalizedDebt[vaultId];
        normalizedGlobalDebt -= currentNormalizedDebt;
        uint256 overallDebt = FullMath.mulDiv(currentNormalizedDebt, currentNormalizationRate, DEBT_DENOMINATOR);
        (uint256 vaultAmount, uint256 liquidationLimit, ) = _calculateVaultCollateral(vaultId, 0, LIQUIDATION_LIMIT);
        if (liquidationLimit >= overallDebt) {
            revert PositionHealthy();
        }

        uint256 returnAmount = FullMath.mulDiv(
            DENOMINATOR - _protocolParams.liquidationPremiumD,
            vaultAmount,
            DENOMINATOR
        );

        if (returnAmount < overallDebt) {
            returnAmount = overallDebt;
        }

        token.transferFrom(msg.sender, address(this), returnAmount);

        uint256 tokensToBurn = vaultMintedDebt[vaultId];

        minter.burnFrom(address(this), tokensToBurn);

        uint256 liquidationFeeAmount = FullMath.mulDiv(vaultAmount, _protocolParams.liquidationFeeD, DENOMINATOR);
        if (liquidationFeeAmount >= returnAmount - overallDebt) {
            liquidationFeeAmount = returnAmount - overallDebt;
        } else {
            vaultOwed[vaultId] += returnAmount - overallDebt - liquidationFeeAmount;
        }

        token.transferAndCall(
            address(treasury),
            overallDebt - tokensToBurn + liquidationFeeAmount,
            abi.encode(overallDebt - tokensToBurn)
        );
        delete vaultNormalizedDebt[vaultId];
        delete vaultMintedDebt[vaultId];
        _closeVault(vaultId, msg.sender);

        emit VaultLiquidated(msg.sender, vaultId);
    }

    /// @inheritdoc ICDP
    function withdrawOwed(
        uint256 vaultId,
        address to,
        uint256 maxAmount
    ) external nonReentrant returns (uint256 withdrawnAmount) {
        _requireVaultAuth(vaultId);

        uint256 owed = vaultOwed[vaultId];
        withdrawnAmount = maxAmount > owed ? owed : maxAmount;

        token.transfer(to, withdrawnAmount);

        vaultOwed[vaultId] -= withdrawnAmount;
    }

    function mintDebtFromScratch(uint256 nft, uint256 amount) external returns (uint256 vaultId) {
        vaultId = openVault();
        depositCollateral(vaultId, nft);
        mintDebt(vaultId, amount);
    }

    /// @inheritdoc IERC721Receiver
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external onlyUnpaused returns (bytes4) {
        if (msg.sender != address(positionManager)) {
            revert Forbidden();
        }
        uint256 vaultId = abi.decode(data, (uint256));

        _depositCollateral(from, vaultId, tokenId);

        return this.onERC721Received.selector;
    }

    function decreaseLiquidity(INonfungiblePositionManager.DecreaseLiquidityParams calldata params)
        external
        nonReentrant
        returns (uint256 amount0, uint256 amount1)
    {
        uint256 tokenId = params.tokenId;
        uint256 vaultId = vaultIdByNft[tokenId];
        _requireVaultAuth(vaultId);

        (amount0, amount1) = positionManager.decreaseLiquidity(params);

        _checkHealthOfVaultAndPosition(vaultId, tokenId);
    }

    function collect(INonfungiblePositionManager.CollectParams calldata params)
        external
        nonReentrant
        returns (uint256 amount0, uint256 amount1)
    {
        uint256 tokenId = params.tokenId;
        uint256 vaultId = vaultIdByNft[tokenId];
        _requireVaultAuth(vaultId);

        (amount0, amount1) = positionManager.collect(params);

        _checkHealthOfVaultAndPosition(vaultId, tokenId);
    }

    function collectAndIncreaseAmount(
        INonfungiblePositionManager.CollectParams calldata collectParams,
        INonfungiblePositionManager.IncreaseLiquidityParams calldata increaseLiquidityParams
    )
        external
        nonReentrant
        returns (
            uint256 depositedLiquidity,
            uint256 depositedAmount0,
            uint256 depositedAmount1,
            uint256 returnAmount0,
            uint256 returnAmount1
        )
    {
        uint256 tokenId = collectParams.tokenId;
        uint256 vaultId = vaultIdByNft[tokenId];
        _requireVaultAuth(vaultId);

        if (tokenId != increaseLiquidityParams.tokenId) {
            revert InvalidValue();
        }

        (returnAmount0, returnAmount1) = positionManager.collect(collectParams);

        (address token0, address token1) = oracle.getPositionTokens(increaseLiquidityParams.tokenId);

        IERC20(token0).transferFrom(msg.sender, address(this), increaseLiquidityParams.amount0Desired);
        IERC20(token1).transferFrom(msg.sender, address(this), increaseLiquidityParams.amount1Desired);

        IERC20(token0).forceApprove(address(positionManager), increaseLiquidityParams.amount0Desired);
        IERC20(token1).forceApprove(address(positionManager), increaseLiquidityParams.amount1Desired);

        (depositedLiquidity, depositedAmount0, depositedAmount1) = positionManager.increaseLiquidity(
            increaseLiquidityParams
        );

        if (depositedAmount0 < increaseLiquidityParams.amount0Desired) {
            IERC20(token0).transfer(msg.sender, increaseLiquidityParams.amount0Desired - depositedAmount0);
        }

        if (depositedAmount1 < increaseLiquidityParams.amount1Desired) {
            IERC20(token1).transfer(msg.sender, increaseLiquidityParams.amount1Desired - depositedAmount1);
        }

        _checkHealthOfVaultAndPosition(vaultId, tokenId);
    }

    /// @inheritdoc ICDP
    function changeLiquidationFee(uint32 liquidationFeeD) external onlyVaultAdmin {
        if (liquidationFeeD > DENOMINATOR) {
            revert InvalidValue();
        }
        _protocolParams.liquidationFeeD = liquidationFeeD;
        emit LiquidationFeeChanged(msg.sender, liquidationFeeD);
    }

    /// @inheritdoc ICDP
    function changeLiquidationPremium(uint32 liquidationPremiumD) external onlyVaultAdmin {
        if (liquidationPremiumD > DENOMINATOR) {
            revert InvalidValue();
        }
        _protocolParams.liquidationPremiumD = liquidationPremiumD;
        emit LiquidationPremiumChanged(msg.sender, liquidationPremiumD);
    }

    /// @inheritdoc ICDP
    function changeMaxDebtPerVault(uint256 maxDebtPerVault) external onlyVaultAdmin {
        _protocolParams.maxDebtPerVault = maxDebtPerVault;
        emit MaxDebtPerVaultChanged(msg.sender, maxDebtPerVault);
    }

    /// @inheritdoc ICDP
    function changeMinSingleNftCollateral(uint256 minSingleNftCollateral) external onlyVaultAdmin {
        _protocolParams.minSingleNftCollateral = minSingleNftCollateral;
        emit MinSingleNftCollateralChanged(msg.sender, minSingleNftCollateral);
    }

    /// @inheritdoc ICDP
    function changeMaxNftsPerVault(uint8 maxNftsPerVault) external onlyVaultAdmin {
        _protocolParams.maxNftsPerVault = maxNftsPerVault;
        emit MaxNftsPerVaultChanged(msg.sender, maxNftsPerVault);
    }

    /// @inheritdoc ICDP
    function setPoolParams(address pool, ICDP.PoolParams calldata params) external onlyVaultAdmin {
        if (pool == address(0)) {
            revert AddressZero();
        }
        if (params.liquidationThresholdD > DENOMINATOR) {
            revert InvalidValue();
        }
        if (params.borrowThresholdD > DENOMINATOR) {
            revert InvalidValue();
        }
        if (params.borrowThresholdD > params.liquidationThresholdD) {
            revert InvalidValue();
        }

        _poolParams[pool] = params;
        emit LiquidationThresholdChanged(msg.sender, pool, params.liquidationThresholdD);
        emit BorrowThresholdChanged(msg.sender, pool, params.borrowThresholdD);
        emit MinWidthChanged(msg.sender, pool, params.minWidth);
    }

    /// @notice Pause the system
    function pause() external onlyAtLeastOperator {
        isPaused = true;

        emit SystemPaused(msg.sender);
    }

    /// @notice Unpause the system
    function unpause() external onlyVaultAdmin {
        isPaused = false;

        emit SystemUnpaused(msg.sender);
    }

    /// @notice Make the system private
    function makePrivate() external onlyVaultAdmin {
        isPublic = false;

        emit SystemPrivate(msg.sender);
    }

    /// @notice Make the system public
    function makePublic() external onlyVaultAdmin {
        isPublic = true;

        emit SystemPublic(msg.sender);
    }

    /// @notice Make liquidations private
    function makeLiquidationsPrivate() external onlyVaultAdmin {
        isLiquidatingPublic = false;

        emit LiquidationsPrivate(msg.sender);
    }

    /// @notice Make liquidations public
    function makeLiquidationsPublic() external onlyVaultAdmin {
        isLiquidatingPublic = true;

        emit LiquidationsPublic(msg.sender);
    }

    /// @notice Add an array of new depositors to the allow list
    /// @param depositors Array of new depositors
    function addDepositorsToAllowlist(address[] calldata depositors) external onlyVaultAdmin {
        for (uint256 i = 0; i < depositors.length; ++i) {
            _depositorsAllowlist.add(depositors[i]);
        }
    }

    /// @notice Remove an array of depositors from the allow list
    /// @param depositors Array of new depositors
    function removeDepositorsFromAllowlist(address[] calldata depositors) external onlyVaultAdmin {
        for (uint256 i = 0; i < depositors.length; ++i) {
            _depositorsAllowlist.remove(depositors[i]);
        }
    }

    /// @notice Add an array of new liquidators to the allow list
    /// @param liquidators Array of new liquidators
    function addLiquidatorsToAllowlist(address[] calldata liquidators) external onlyVaultAdmin {
        for (uint256 i = 0; i < liquidators.length; ++i) {
            _liquidatorsAllowlist.add(liquidators[i]);
        }
    }

    /// @notice Remove an array of liquidators from the allow list
    /// @param liquidators Array of new liquidators
    function removeLiquidatorsFromAllowlist(address[] calldata liquidators) external onlyVaultAdmin {
        for (uint256 i = 0; i < liquidators.length; ++i) {
            _liquidatorsAllowlist.remove(liquidators[i]);
        }
    }

    /// @notice Update stabilisation fee (multiplied by DEBT_DENOMINATOR) and calculate global stabilisation fee per USD up to current timestamp using previous stabilisation fee
    /// @param stabilisationFeeRateD18_ New stabilisation fee multiplied by DEBT_DENOMINATOR
    function updateStabilisationFeeRate(uint256 stabilisationFeeRateD18_) external onlyVaultAdmin {
        if (stabilisationFeeRateD18_ > DEBT_DENOMINATOR / YEAR) {
            revert InvalidValue();
        }

        updateNormalizationRate();

        stabilisationFeeRateD18 = stabilisationFeeRateD18_;

        emit StabilisationFeeUpdated(msg.sender, stabilisationFeeRateD18_);
    }

    // -------------------  INTERNAL, VIEW  -----------------------

    /// @notice Get total debt for a given vault by id (including fees) with given normalization rate
    /// @param vaultId Id of the vault
    /// @param normalizationRate_ Given Normalization Rate
    /// @return uint256 Total debt value (in BOB weis)
    function _getOverallDebt(uint256 vaultId, uint256 normalizationRate_) internal view returns (uint256) {
        return FullMath.mulDiv(vaultNormalizedDebt[vaultId], normalizationRate_, DEBT_DENOMINATOR);
    }

    /// @notice Check if the caller is authorized to manage the vault
    /// @param vaultId Vault id
    function _requireVaultAuth(uint256 vaultId) internal view {
        if (!vaultRegistry.isAuthorized(vaultId, msg.sender)) {
            revert Forbidden();
        }
    }

    /// @notice Check if the system is unpaused
    function _requireUnpaused() internal view {
        if (isPaused) {
            revert Paused();
        }
    }

    uint256 private constant BORROW_LIMIT = 0x0;
    uint256 private constant LIQUIDATION_LIMIT = 0x1;
    uint256 private constant SAFE_BORROW_LIMIT = 0x2;

    /// @notice Calculate overall collateral and adjusted collateral for a given vault (token capitals of each specific collateral in the vault in BOB weis) and price of tokenId if it contains in vault
    /// @param vaultId Id of the vault
    /// @param tokenId Id of the token
    /// @param limitType Type of limit to return
    /// @return total Vault collateral value
    /// @return limit Requested debt limit
    /// @return positionValue Price of tokenId if it contains in vault, 0 otherwise
    function _calculateVaultCollateral(
        uint256 vaultId,
        uint256 tokenId,
        uint256 limitType
    )
        internal
        view
        returns (
            uint256 total,
            uint256 limit,
            uint256 positionValue
        )
    {
        uint256[] storage vaultNfts = _vaultNfts[vaultId];
        uint256 nftsCount = vaultNfts.length;

        total = 0;
        limit = 0;
        positionValue = 0;

        for (uint256 i = 0; i < nftsCount; ++i) {
            uint256 nft = vaultNfts[i];
            (bool deviationSafety, uint256 price, , address poolAddr) = oracle.price(nft);

            ICDP.PoolParams memory pool = _poolParams[poolAddr];

            total += price;
            if (limitType == LIQUIDATION_LIMIT) {
                limit += FullMath.mulDiv(price, pool.liquidationThresholdD, DENOMINATOR);
            } else {
                limit += FullMath.mulDiv(price, pool.borrowThresholdD, DENOMINATOR);

                if (limitType == SAFE_BORROW_LIMIT && !deviationSafety) {
                    revert TickDeviation();
                }

                if (nft == tokenId) {
                    positionValue = price;
                }
            }
        }
    }

    /// @notice Checking health of specific vault and position
    /// @param vaultId Id of the vault
    /// @param tokenId Id of the token
    function _checkHealthOfVaultAndPosition(uint256 vaultId, uint256 tokenId) internal {
        uint256 currentNormalizationRate = updateNormalizationRate();

        // checking that health factor is more or equal than 1
        (, uint256 borrowLimit, uint256 positionAmount) = _calculateVaultCollateral(
            vaultId,
            tokenId,
            SAFE_BORROW_LIMIT
        );
        if (borrowLimit < _getOverallDebt(vaultId, currentNormalizationRate)) {
            revert PositionUnhealthy();
        }

        if (positionAmount < _protocolParams.minSingleNftCollateral) {
            revert CollateralUnderflow();
        }
    }

    // -------------------  INTERNAL, MUTATING  -------------------

    /// @notice Completes deposit of a collateral to vault
    /// @param caller Caller address
    /// @param vaultId Id of the vault
    /// @param nft Collateral NFT to be deposited
    function _depositCollateral(
        address caller,
        uint256 vaultId,
        uint256 nft
    ) internal {
        if (!isPublic && !_depositorsAllowlist.contains(caller)) {
            revert AllowList();
        }

        uint256[] storage vaultNfts = _vaultNfts[vaultId];
        if (_protocolParams.maxNftsPerVault <= vaultNfts.length) {
            revert NFTLimitExceeded();
        }

        // revert if vault NFT was burnt or is being managed by another minter
        if (vaultNfts.length == 0 && vaultRegistry.minterOf(vaultId) != address(this)) {
            revert InvalidVault();
        }

        (, uint256 positionAmount, uint24 width, address poolAddr) = oracle.price(nft);

        ICDP.PoolParams memory pool = _poolParams[poolAddr];

        if (pool.borrowThresholdD == 0) {
            revert InvalidPool();
        }

        if (width < pool.minWidth) {
            revert TooNarrowNFT();
        }

        if (positionAmount < _protocolParams.minSingleNftCollateral) {
            revert CollateralUnderflow();
        }

        vaultIdByNft[nft] = vaultId;
        vaultNfts.push(nft);

        emit CollateralDeposited(caller, vaultId, nft);
    }

    /// @notice Closes a vault (internal)
    /// @param vaultId Id of the vault
    /// @param nftsRecipient Address to receive nft of the positions in the closed vault
    function _closeVault(uint256 vaultId, address nftsRecipient) internal {
        uint256[] storage vaultNfts = _vaultNfts[vaultId];
        uint256 nftsCount = vaultNfts.length;

        for (uint256 i = 0; i < nftsCount; ++i) {
            uint256 nft = vaultNfts[i];
            delete vaultIdByNft[nft];

            positionManager.transferFrom(address(this), nftsRecipient, nft);
        }

        delete _vaultNfts[vaultId];
    }

    // -----------------------  MODIFIERS  --------------------------

    // @notice Checks that caller is vault admin
    modifier onlyVaultAdmin() {
        _requireAdmin();
        _;
    }

    // @notice Checks that caller is vault operator or admin
    modifier onlyAtLeastOperator() {
        _requireAtLeastOperator();
        _;
    }

    // @notice Checks that system is unpaused
    modifier onlyUnpaused() {
        _requireUnpaused();
        _;
    }

    // --------------------------  EVENTS  --------------------------

    /// @notice Emitted when a new vault is opened
    /// @param sender Sender of the call (msg.sender)
    /// @param vaultId Id of the vault
    event VaultOpened(address indexed sender, uint256 indexed vaultId);

    /// @notice Emitted when a vault is liquidated
    /// @param sender Sender of the call (msg.sender)
    /// @param vaultId Id of the vault
    event VaultLiquidated(address indexed sender, uint256 indexed vaultId);

    /// @notice Emitted when a vault is closed
    /// @param sender Sender of the call (msg.sender)
    /// @param vaultId Id of the vault
    event VaultClosed(address indexed sender, uint256 indexed vaultId);

    /// @notice Emitted when a collateral is deposited
    /// @param sender Sender of the call (msg.sender)
    /// @param vaultId Id of the vault
    /// @param tokenId Id of the token
    event CollateralDeposited(address indexed sender, uint256 indexed vaultId, uint256 tokenId);

    /// @notice Emitted when a collateral is withdrawn
    /// @param sender Sender of the call (msg.sender)
    /// @param vaultId Id of the vault
    /// @param tokenId Id of the token
    event CollateralWithdrew(address indexed sender, uint256 indexed vaultId, uint256 tokenId);

    /// @notice Emitted when a debt is minted
    /// @param sender Sender of the call (msg.sender)
    /// @param vaultId Id of the vault
    /// @param amount Debt amount
    event DebtMinted(address indexed sender, uint256 indexed vaultId, uint256 amount);

    /// @notice Emitted when a debt is burnt
    /// @param sender Sender of the call (msg.sender)
    /// @param vaultId Id of the vault
    /// @param amount Debt amount
    event DebtBurned(address indexed sender, uint256 indexed vaultId, uint256 amount);

    /// @notice Emitted when the stabilisation fee is updated
    /// @param sender Sender of the call (msg.sender)
    /// @param stabilisationFee New stabilisation fee
    event StabilisationFeeUpdated(address indexed sender, uint256 stabilisationFee);

    /// @notice Emitted when the normalization rate is updated
    /// @param normalizationRate New normalization rate
    event NormalizationRateUpdated(uint256 normalizationRate);

    /// @notice Emitted when the system is set to paused
    /// @param sender Sender of the call (msg.sender)
    event SystemPaused(address indexed sender);

    /// @notice Emitted when the system is set to unpaused
    /// @param sender Sender of the call (msg.sender)
    event SystemUnpaused(address indexed sender);

    /// @notice Emitted when the system is set to private
    /// @param sender Sender of the call (msg.sender)
    event SystemPrivate(address indexed sender);

    /// @notice Emitted when the system is set to public
    /// @param sender Sender of the call (msg.sender)
    event SystemPublic(address indexed sender);

    /// @notice Emitted when liquidations is set to private
    /// @param sender Sender of the call (msg.sender)
    event LiquidationsPrivate(address indexed sender);

    /// @notice Emitted when liquidations is set to public
    /// @param sender Sender of the call (msg.sender)
    event LiquidationsPublic(address indexed sender);

    /// @notice Emitted when liquidation fee is updated
    /// @param sender Sender of the call (msg.sender)
    /// @param liquidationFeeD The new liquidation fee (multiplied by DENOMINATOR)
    event LiquidationFeeChanged(address indexed sender, uint32 liquidationFeeD);

    /// @notice Emitted when liquidation premium is updated
    /// @param sender Sender of the call (msg.sender)
    /// @param liquidationPremiumD The new liquidation premium (multiplied by DENOMINATOR)
    event LiquidationPremiumChanged(address indexed sender, uint32 liquidationPremiumD);

    /// @notice Emitted when max debt per vault is updated
    /// @param sender Sender of the call (msg.sender)
    /// @param maxDebtPerVault The new max debt per vault (nominated in BOB weis)
    event MaxDebtPerVaultChanged(address indexed sender, uint256 maxDebtPerVault);

    /// @notice Emitted when min nft collateral is updated
    /// @param sender Sender of the call (msg.sender)
    /// @param minSingleNftCollateral The new min nft collateral (nominated in BOB weis)
    event MinSingleNftCollateralChanged(address indexed sender, uint256 minSingleNftCollateral);

    /// @notice Emitted when min nft collateral is updated
    /// @param sender Sender of the call (msg.sender)
    /// @param maxNftsPerVault The new max possible amount of NFTs for one vault
    event MaxNftsPerVaultChanged(address indexed sender, uint8 maxNftsPerVault);

    /// @notice Emitted when liquidation threshold for a specific pool is updated
    /// @param sender Sender of the call (msg.sender)
    /// @param pool The given pool
    /// @param liquidationThresholdD The new liquidation threshold (multiplied by DENOMINATOR)
    event LiquidationThresholdChanged(address indexed sender, address indexed pool, uint32 liquidationThresholdD);

    /// @notice Emitted when borrow threshold for a specific pool is updated
    /// @param sender Sender of the call (msg.sender)
    /// @param pool The given pool
    /// @param borrowThresholdD The new liquidation threshold (multiplied by DENOMINATOR)
    event BorrowThresholdChanged(address indexed sender, address indexed pool, uint32 borrowThresholdD);

    /// @notice Emitted when the min position's width for the pool is updated
    /// @param sender Sender of the call (msg.sender)
    /// @param pool The address of the pool
    /// @param minWidth The new minimal position's width
    event MinWidthChanged(address indexed sender, address indexed pool, uint24 minWidth);
}

File 2 of 53 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

File 3 of 53 : 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 4 of 53 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.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 5 of 53 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

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

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

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

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

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

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

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
     * 0 before setting it to a non-zero value.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

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

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

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

File 6 of 53 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 7 of 53 : Multicall.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Multicall.sol)

pragma solidity ^0.8.0;

import "./Address.sol";

/**
 * @dev Provides a function to batch together multiple calls in a single external call.
 *
 * _Available since v4.1._
 */
abstract contract Multicall {
    /**
     * @dev Receives and executes a batch of function calls on this contract.
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function multicall(bytes[] calldata data) external virtual returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            results[i] = Address.functionDelegateCall(address(this), data[i]);
        }
        return results;
    }
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 9 of 53 : EIP1967Admin.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity 0.8.15;

/**
 * @title EIP1967Admin
 * @dev Upgradeable proxy pattern implementation according to minimalistic EIP1967.
 */
contract EIP1967Admin {
    // EIP 1967
    // bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)
    uint256 internal constant EIP1967_ADMIN_STORAGE = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    modifier onlyAdmin() {
        require(msg.sender == _admin(), "EIP1967Admin: not an admin");
        _;
    }

    function _admin() internal view returns (address res) {
        assembly {
            res := sload(EIP1967_ADMIN_STORAGE)
        }
    }
}

File 10 of 53 : IOracle.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.0;

interface IOracle {
    /// @notice Oracle price for token.
    /// @param token Reference to token
    /// @return success True if call to an external oracle was successful, false otherwise
    /// @return priceX96 Price that satisfy token
    function price(address token) external view returns (bool success, uint256 priceX96);

    /// @notice Returns if an oracle was approved for a token
    /// @param token A given token address
    /// @return bool True if an oracle was approved for a token, else - false
    function hasOracle(address token) external view returns (bool);
}

File 11 of 53 : INonfungiblePositionLoader.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.0;

interface INonfungiblePositionLoader {
    struct PositionInfo {
        uint96 nonce;
        address operator;
        address token0;
        address token1;
        uint24 fee;
        int24 tickLower;
        int24 tickUpper;
        uint128 liquidity;
        uint256 feeGrowthInside0LastX128;
        uint256 feeGrowthInside1LastX128;
        uint128 tokensOwed0;
        uint128 tokensOwed1;
    }

    function positions(uint256 tokenId) external view returns (PositionInfo memory);
}

File 12 of 53 : IBobToken.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@zkbob/interfaces/IBurnableERC20.sol";
import "@zkbob/interfaces/IMintableERC20.sol";
import "@zkbob/interfaces/IERC20Permit.sol";
import "@zkbob/interfaces/IERC677.sol";

interface IBobToken is IERC20Permit, IMintableERC20, IBurnableERC20, IERC20, IERC677 {}

File 13 of 53 : IVaultRegistry.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.0;

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

interface IVaultRegistry is IERC721Enumerable {
    /// @notice Checks if user is authorized to manage specific token id
    /// Only token owner or approved operators are allowed to manage a specific token id
    /// @param tokenId Id of a token
    /// @param user Address of the manager
    /// @return true if user is authorized, false otherwise
    function isAuthorized(uint256 tokenId, address user) external view returns (bool);

    /// @notice Mints a new token
    /// @param to Token receiver
    /// @return minted token id
    function mint(address to) external returns (uint256);

    /// @notice Burns an existent token
    /// Only the minter of the specified token id is allowed to burn it
    /// @param tokenId Id of a token
    function burn(uint256 tokenId) external;

    /// @notice Returns a minter of a token
    /// @param tokenId Id of a token
    /// @return Address of a minter
    function minterOf(uint256 tokenId) external view returns (address);
}

File 14 of 53 : INFTOracle.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.0;

interface INFTOracle {
    /// @notice Calculates the price of NFT position
    /// @param nft The token id of the position
    /// @return deviationSafety True if price deviation is safe, False otherwise
    /// @return positionAmount The value of the given position
    /// @return width The width of the position (in ticks)
    /// @return pool Address of the position's pool
    function price(uint256 nft)
        external
        view
        returns (
            bool deviationSafety,
            uint256 positionAmount,
            uint24 width,
            address pool
        );

    /// @notice Returns tokens for the NFT position
    /// @param nft The token id of the position
    /// @return token0 The token0 of the position
    /// @return token1 The token1 of the position
    function getPositionTokens(uint256 nft) external view returns (address token0, address token1);
}

File 15 of 53 : ICDP.sol
// SPDX-License-Identifer: MIT
pragma solidity ^0.8.0;

interface ICDP {
    /// @notice Global protocol params
    /// @param maxDebtPerVault Max possible debt for one vault (nominated in BOB weis)
    /// @param minSingleNftCapital Min possible BOB NFT value allowed to deposit (nominated in BOB weis)
    /// @param liquidationFee Share of the BOB value of assets of a vault, due to be transferred to the Protocol Treasury after a liquidation (multiplied by DENOMINATOR)
    /// @param liquidationPremium Share of the BOB value of assets of a vault, due to be awarded to a liquidator after a liquidation (multiplied by DENOMINATOR)
    /// @param maxNftsPerVault Max possible amount of NFTs for one vault
    struct ProtocolParams {
        uint256 maxDebtPerVault;
        uint256 minSingleNftCollateral;
        uint32 liquidationFeeD;
        uint32 liquidationPremiumD;
        uint8 maxNftsPerVault;
    }

    /// @notice Collateral pool params
    /// @param liquidationThresholdD collateral liquidation threshold (9 decimals)
    /// @param borrowThresholdD maximum borrow threshold, should be less than or equal to liquidationThresholdD (9 decimals)
    /// @param minWidth min allowed position width in collateral ticks
    struct PoolParams {
        uint32 liquidationThresholdD;
        uint32 borrowThresholdD;
        uint24 minWidth;
    }

    // -------------------  EXTERNAL, VIEW  -------------------

    /// @notice Get all NFTs, managed by vault with given id
    /// @param vaultId Id of the vault
    /// @return uint256[] Array of NFTs, managed by vault
    function vaultNftsById(uint256 vaultId) external view returns (uint256[] memory);

    /// @notice Global protocol params
    /// @return ProtocolParams Protocol params struct
    function protocolParams() external view returns (ProtocolParams memory);

    /// @notice Tells pool collateral params.
    /// @param pool address of collateral pool.
    /// @return pool params struct
    function poolParams(address pool) external view returns (PoolParams memory);

    /// @notice Get total debt for a given vault by id (including fees)
    /// @param vaultId Id of the vault
    /// @return uint256 Total debt value (in BOB weis)
    function getOverallDebt(uint256 vaultId) external view returns (uint256);

    // -------------------  EXTERNAL, MUTATING  -------------------

    /// @notice Change liquidation fee (multiplied by DENOMINATOR) to a given value
    /// @param liquidationFeeD The new liquidation fee (multiplied by DENOMINATOR)
    function changeLiquidationFee(uint32 liquidationFeeD) external;

    /// @notice Change liquidation premium (multiplied by DENOMINATOR) to a given value
    /// @param liquidationPremiumD The new liquidation premium (multiplied by DENOMINATOR)
    function changeLiquidationPremium(uint32 liquidationPremiumD) external;

    /// @notice Change max debt per vault (nominated in BOB weis) to a given value
    /// @param maxDebtPerVault The new max possible debt per vault (nominated in BOB weis)
    function changeMaxDebtPerVault(uint256 maxDebtPerVault) external;

    /// @notice Change min single nft collateral to a given value (nominated in BOB weis)
    /// @param minSingleNftCollateral The new min possible nft collateral (nominated in BOB weis)
    function changeMinSingleNftCollateral(uint256 minSingleNftCollateral) external;

    /// @notice Change max possible amount of NFTs for one vault
    /// @param maxNftsPerVault The new max possible amount of NFTs for one vault
    function changeMaxNftsPerVault(uint8 maxNftsPerVault) external;

    /// @notice Change whitelisted pool parameters
    /// @param pool address of the pool contract to change params for
    /// @param params new collateral params
    function setPoolParams(address pool, ICDP.PoolParams calldata params) external;

    /// @notice Liquidate a vault
    /// @param vaultId Id of the vault subject to liquidation
    function liquidate(uint256 vaultId) external;

    /// @notice Withdraws vault owed tokens, left after liquidation
    /// @param vaultId id of the liquidated vault
    /// @param to address where to sent withdrawn tokens
    /// @param maxAmount max amount of tokens to withdraw
    /// @return withdrawnAmount final amount of withdrawn tokens
    function withdrawOwed(
        uint256 vaultId,
        address to,
        uint256 maxAmount
    ) external returns (uint256 withdrawnAmount);

    /// @notice Calculate adjusted collateral for a given vault (token capitals of each specific collateral in the vault in BOB weis)
    /// @param vaultId Id of the vault
    /// @return total Total vault collateral value
    /// @return borrowLimit Borrow limit
    /// @return liquidationLimit Debt liquidation limit
    function calculateVaultCollateral(uint256 vaultId)
        external
        view
        returns (
            uint256 total,
            uint256 borrowLimit,
            uint256 liquidationLimit
        );
}

File 16 of 53 : UniswapV3FeesCalculation.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity 0.8.15;

import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import "@uniswap/v3-core/contracts/libraries/FullMath.sol";
import "../interfaces/external/univ3/INonfungiblePositionLoader.sol";

/// @title Math library for computing fees for uniswap v3 positions
library UniswapV3FeesCalculation {
    uint256 public constant Q128 = 2**128;

    /// @notice Calculate Uniswap token fees for the position with a given nft
    /// @param pool UniswapV3 pool
    /// @param tick The current tick for the position's pool
    /// @param positionInfo Additional position info
    /// @return actualTokensOwed0 The fees of the position in token0, actualTokensOwed1 The fees of the position in token1
    function _calculateUniswapFees(
        IUniswapV3Pool pool,
        int24 tick,
        INonfungiblePositionLoader.PositionInfo memory positionInfo
    ) internal view returns (uint128 actualTokensOwed0, uint128 actualTokensOwed1) {
        actualTokensOwed0 = positionInfo.tokensOwed0;
        actualTokensOwed1 = positionInfo.tokensOwed1;

        if (positionInfo.liquidity == 0) {
            return (actualTokensOwed0, actualTokensOwed1);
        }

        uint256 feeGrowthGlobal0X128 = pool.feeGrowthGlobal0X128();
        uint256 feeGrowthGlobal1X128 = pool.feeGrowthGlobal1X128();

        (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) = _getUniswapFeeGrowthInside(
            pool,
            positionInfo.tickLower,
            positionInfo.tickUpper,
            tick,
            feeGrowthGlobal0X128,
            feeGrowthGlobal1X128
        );

        uint256 feeGrowthInside0DeltaX128;
        uint256 feeGrowthInside1DeltaX128;
        unchecked {
            feeGrowthInside0DeltaX128 = feeGrowthInside0X128 - positionInfo.feeGrowthInside0LastX128;
            feeGrowthInside1DeltaX128 = feeGrowthInside1X128 - positionInfo.feeGrowthInside1LastX128;
        }

        actualTokensOwed0 += uint128(FullMath.mulDiv(feeGrowthInside0DeltaX128, positionInfo.liquidity, Q128));
        actualTokensOwed1 += uint128(FullMath.mulDiv(feeGrowthInside1DeltaX128, positionInfo.liquidity, Q128));
    }

    /// @notice Get fee growth inside position from the tickLower to tickUpper since the pool has been initialised
    /// @param pool UniswapV3 pool
    /// @param tickLower UniswapV3 lower tick
    /// @param tickUpper UniswapV3 upper tick
    /// @param tickCurrent UniswapV3 current tick
    /// @param feeGrowthGlobal0X128 UniswapV3 fees of token0 collected per unit of liquidity for the entire life of the pool
    /// @param feeGrowthGlobal1X128 UniswapV3 fees of token1 collected per unit of liquidity for the entire life of the pool
    /// @return feeGrowthInside0X128 The all-time fee growth in token0, per unit of liquidity, inside the position's tick boundaries, feeGrowthInside1X128 The all-time fee growth in token1, per unit of liquidity, inside the position's tick boundaries
    function _getUniswapFeeGrowthInside(
        IUniswapV3Pool pool,
        int24 tickLower,
        int24 tickUpper,
        int24 tickCurrent,
        uint256 feeGrowthGlobal0X128,
        uint256 feeGrowthGlobal1X128
    ) internal view returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) {
        unchecked {
            (, , uint256 lowerFeeGrowthOutside0X128, uint256 lowerFeeGrowthOutside1X128, , , , ) = pool.ticks(
                tickLower
            );
            (, , uint256 upperFeeGrowthOutside0X128, uint256 upperFeeGrowthOutside1X128, , , , ) = pool.ticks(
                tickUpper
            );

            // calculate fee growth below
            uint256 feeGrowthBelow0X128;
            uint256 feeGrowthBelow1X128;
            if (tickCurrent >= tickLower) {
                feeGrowthBelow0X128 = lowerFeeGrowthOutside0X128;
                feeGrowthBelow1X128 = lowerFeeGrowthOutside1X128;
            } else {
                feeGrowthBelow0X128 = feeGrowthGlobal0X128 - lowerFeeGrowthOutside0X128;
                feeGrowthBelow1X128 = feeGrowthGlobal1X128 - lowerFeeGrowthOutside1X128;
            }

            // calculate fee growth above
            uint256 feeGrowthAbove0X128;
            uint256 feeGrowthAbove1X128;
            if (tickCurrent < tickUpper) {
                feeGrowthAbove0X128 = upperFeeGrowthOutside0X128;
                feeGrowthAbove1X128 = upperFeeGrowthOutside1X128;
            } else {
                feeGrowthAbove0X128 = feeGrowthGlobal0X128 - upperFeeGrowthOutside0X128;
                feeGrowthAbove1X128 = feeGrowthGlobal1X128 - upperFeeGrowthOutside1X128;
            }

            feeGrowthInside0X128 = feeGrowthGlobal0X128 - feeGrowthBelow0X128 - feeGrowthAbove0X128;
            feeGrowthInside1X128 = feeGrowthGlobal1X128 - feeGrowthBelow1X128 - feeGrowthAbove1X128;
        }
    }
}

File 17 of 53 : VaultAccessControl.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity 0.8.15;

import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "../interfaces/utils/IDefaultAccessControl.sol";

/// @notice This is a default access control with 3 roles:
///
/// - ADMIN: allowed to do anything
/// - ADMIN_DELEGATE: allowed to do anything except assigning ADMIN and ADMIN_DELEGATE roles
/// - OPERATOR: low-privileged role, generally keeper or some other bot
contract VaultAccessControl is IDefaultAccessControl, AccessControlEnumerable {
    error AddressZero();
    error Forbidden();

    bytes32 public constant OPERATOR = keccak256("operator");
    bytes32 public constant ADMIN_ROLE = keccak256("admin");
    bytes32 public constant ADMIN_DELEGATE_ROLE = keccak256("admin_delegate");

    // -------------------------  EXTERNAL, VIEW  ------------------------------

    /// @inheritdoc IDefaultAccessControl
    function isAdmin(address sender) public view returns (bool) {
        return hasRole(ADMIN_ROLE, sender) || hasRole(ADMIN_DELEGATE_ROLE, sender);
    }

    /// @inheritdoc IDefaultAccessControl
    function isOperator(address sender) public view returns (bool) {
        return hasRole(OPERATOR, sender);
    }

    // -------------------------  INTERNAL, VIEW  ------------------------------

    function _requireAdmin() internal view {
        if (!isAdmin(msg.sender)) {
            revert Forbidden();
        }
    }

    function _requireAtLeastOperator() internal view {
        if (!isAdmin(msg.sender) && !isOperator(msg.sender)) {
            revert Forbidden();
        }
    }
}

File 18 of 53 : ITreasury.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.0;

interface ITreasury {
    /**
     * @dev Records potential unrealized surplus.
     * Callable only by the pre-approved surplus minter.
     * Once unrealized surplus is realized, it should be transferred to this contract via transferAndCall.
     * @param _surplus unrealized surplus to add.
     */
    function add(uint256 _surplus) external;

    /// @notice Returns current unrealized interest
    /// @return uint256 unrealized interest
    function surplus() external view returns (uint256);
}

File 19 of 53 : IMinter.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.0;

import "@zkbob/interfaces/IBurnableERC20.sol";
import "@zkbob/interfaces/IMintableERC20.sol";

interface IMinter is IMintableERC20, IBurnableERC20 {}

File 20 of 53 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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 21 of 53 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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 22 of 53 : 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 53 : 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 24 of 53 : IPoolInitializer.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

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

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

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

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

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

    /// @notice Approve of a specific token ID for spending by spender via signature
    /// @param spender The account that is being approved
    /// @param tokenId The ID of the token that is being approved for spending
    /// @param deadline The deadline timestamp by which the call must be mined for the approve to work
    /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
    /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
    /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
    function permit(
        address spender,
        uint256 tokenId,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable;
}

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

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

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

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

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

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

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

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

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

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

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

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

File 29 of 53 : IBurnableERC20.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity 0.8.15;

interface IBurnableERC20 {
    function burn(uint256 amount) external;
    function burnFrom(address user, uint256 amount) external;
}

File 30 of 53 : IMintableERC20.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity 0.8.15;

interface IMintableERC20 {
    function mint(address to, uint256 amount) external;
}

File 31 of 53 : IERC20Permit.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity 0.8.15;

interface IERC20Permit {
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    )
        external;

    function nonces(address owner) external view returns (uint256);

    function DOMAIN_SEPARATOR() external view returns (bytes32);

    function PERMIT_TYPEHASH() external view returns (bytes32);

    function SALTED_PERMIT_TYPEHASH() external view returns (bytes32);

    function receiveWithPermit(
        address _holder,
        uint256 _value,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    )
        external;

    function receiveWithSaltedPermit(
        address _holder,
        uint256 _value,
        uint256 _deadline,
        bytes32 _salt,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    )
        external;
}

File 32 of 53 : IERC677.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity 0.8.15;

interface IERC677 {
    function transferAndCall(address to, uint256 amount, bytes calldata data) external;
}

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

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

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

}

File 34 of 53 : 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; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(a, b, not(0))
                prod0 := mul(a, b)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

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

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

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

            // Make division exact by subtracting the remainder from [prod1 prod0]
            // Compute remainder using mulmod
            uint256 remainder;
            assembly {
                remainder := mulmod(a, b, denominator)
            }
            // Subtract 256 bit number from 512 bit number
            assembly {
                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 precoditions guarantee
            // that the outcome is less than 2**256, this is the final result.
            // We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inv;
            return result;
        }
    }

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

File 35 of 53 : AccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControlEnumerable.sol";
import "./AccessControl.sol";
import "../utils/structs/EnumerableSet.sol";

/**
 * @dev Extension of {AccessControl} that allows enumerating the members of each role.
 */
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
    using EnumerableSet for EnumerableSet.AddressSet;

    mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;

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

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
        return _roleMembers[role].at(index);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
        return _roleMembers[role].length();
    }

    /**
     * @dev Overload {_grantRole} to track enumerable memberships
     */
    function _grantRole(bytes32 role, address account) internal virtual override {
        super._grantRole(role, account);
        _roleMembers[role].add(account);
    }

    /**
     * @dev Overload {_revokeRole} to track enumerable memberships
     */
    function _revokeRole(bytes32 role, address account) internal virtual override {
        super._revokeRole(role, account);
        _roleMembers[role].remove(account);
    }
}

File 36 of 53 : IDefaultAccessControl.sol
// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.0;

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

interface IDefaultAccessControl is IAccessControlEnumerable {
    /// @notice Checks that the address is contract admin.
    /// @param who Address to check
    /// @return `true` if who is admin, `false` otherwise
    function isAdmin(address who) external view returns (bool);

    /// @notice Checks that the address is contract admin.
    /// @param who Address to check
    /// @return `true` if who is operator, `false` otherwise
    function isOperator(address who) external view returns (bool);
}

File 37 of 53 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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 38 of 53 : IUniswapV3PoolImmutables.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /// @notice Emitted by the pool for any swaps between token0 and token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the output of the swap
    /// @param amount0 The delta of the token0 balance of the pool
    /// @param amount1 The delta of the token1 balance of the pool
    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
    /// @param liquidity The liquidity of the pool after the swap
    /// @param tick The log base 1.0001 of price of the pool after the swap
    event Swap(
        address indexed sender,
        address indexed recipient,
        int256 amount0,
        int256 amount1,
        uint160 sqrtPriceX96,
        uint128 liquidity,
        int24 tick
    );

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

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

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

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

File 45 of 53 : IAccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";

/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerable is IAccessControl {
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

File 46 of 53 : AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

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

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(account),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

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

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

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

File 47 of 53 : 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 48 of 53 : IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

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

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

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

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

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

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

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

File 49 of 53 : 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 50 of 53 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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 51 of 53 : 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 52 of 53 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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 53 of 53 : 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);
        }
    }
}

Settings
{
  "remappings": [
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@quickswap/=lib/@quickswap/contracts/",
    "@uniswap/=lib/@uniswap/",
    "@zkbob/=lib/zkbob-contracts/src/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "forge-std/=lib/forge-std/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200,
    "details": {
      "yul": true,
      "yulDetails": {
        "stackAllocation": true
      }
    }
  },
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract INonfungiblePositionManager","name":"positionManager_","type":"address"},{"internalType":"contract INFTOracle","name":"oracle_","type":"address"},{"internalType":"address","name":"treasury_","type":"address"},{"internalType":"address","name":"token_","type":"address"},{"internalType":"address","name":"minter_","type":"address"},{"internalType":"address","name":"vaultRegistry_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AddressZero","type":"error"},{"inputs":[],"name":"AllowList","type":"error"},{"inputs":[],"name":"CollateralUnderflow","type":"error"},{"inputs":[],"name":"DebtLimitExceeded","type":"error"},{"inputs":[],"name":"Forbidden","type":"error"},{"inputs":[],"name":"Initialized","type":"error"},{"inputs":[],"name":"InvalidPool","type":"error"},{"inputs":[],"name":"InvalidValue","type":"error"},{"inputs":[],"name":"InvalidVault","type":"error"},{"inputs":[],"name":"LiquidatorsAllowList","type":"error"},{"inputs":[],"name":"NFTLimitExceeded","type":"error"},{"inputs":[],"name":"Paused","type":"error"},{"inputs":[],"name":"PositionHealthy","type":"error"},{"inputs":[],"name":"PositionUnhealthy","type":"error"},{"inputs":[],"name":"TickDeviation","type":"error"},{"inputs":[],"name":"TooNarrowNFT","type":"error"},{"inputs":[],"name":"UnpaidDebt","type":"error"},{"inputs":[],"name":"ValueZero","type":"error"},{"inputs":[],"name":"VaultNonEmpty","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"uint32","name":"borrowThresholdD","type":"uint32"}],"name":"BorrowThresholdChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"vaultId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"CollateralDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"vaultId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"CollateralWithdrew","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"vaultId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DebtBurned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"vaultId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DebtMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint32","name":"liquidationFeeD","type":"uint32"}],"name":"LiquidationFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint32","name":"liquidationPremiumD","type":"uint32"}],"name":"LiquidationPremiumChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"uint32","name":"liquidationThresholdD","type":"uint32"}],"name":"LiquidationThresholdChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"LiquidationsPrivate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"LiquidationsPublic","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"maxDebtPerVault","type":"uint256"}],"name":"MaxDebtPerVaultChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint8","name":"maxNftsPerVault","type":"uint8"}],"name":"MaxNftsPerVaultChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"minSingleNftCollateral","type":"uint256"}],"name":"MinSingleNftCollateralChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"uint24","name":"minWidth","type":"uint24"}],"name":"MinWidthChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"normalizationRate","type":"uint256"}],"name":"NormalizationRateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"stabilisationFee","type":"uint256"}],"name":"StabilisationFeeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"SystemPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"SystemPrivate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"SystemPublic","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"SystemUnpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"vaultId","type":"uint256"}],"name":"VaultClosed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"vaultId","type":"uint256"}],"name":"VaultLiquidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"vaultId","type":"uint256"}],"name":"VaultOpened","type":"event"},{"inputs":[],"name":"ADMIN_DELEGATE_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEBT_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OPERATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"YEAR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"depositors","type":"address[]"}],"name":"addDepositorsToAllowlist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"liquidators","type":"address[]"}],"name":"addLiquidatorsToAllowlist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burnDebt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"}],"name":"burnVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"}],"name":"calculateVaultCollateral","outputs":[{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256","name":"liquidationLimit","type":"uint256"},{"internalType":"uint256","name":"borrowLimit","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"liquidationFeeD","type":"uint32"}],"name":"changeLiquidationFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"liquidationPremiumD","type":"uint32"}],"name":"changeLiquidationPremium","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"maxDebtPerVault","type":"uint256"}],"name":"changeMaxDebtPerVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"maxNftsPerVault","type":"uint8"}],"name":"changeMaxNftsPerVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minSingleNftCollateral","type":"uint256"}],"name":"changeMinSingleNftCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"},{"internalType":"address","name":"collateralRecipient","type":"address"}],"name":"closeVault","outputs":[],"stateMutability":"nonpayable","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":"nonpayable","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":"collectParams","type":"tuple"},{"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":"increaseLiquidityParams","type":"tuple"}],"name":"collectAndIncreaseAmount","outputs":[{"internalType":"uint256","name":"depositedLiquidity","type":"uint256"},{"internalType":"uint256","name":"depositedAmount0","type":"uint256"},{"internalType":"uint256","name":"depositedAmount1","type":"uint256"},{"internalType":"uint256","name":"returnAmount0","type":"uint256"},{"internalType":"uint256","name":"returnAmount1","type":"uint256"}],"stateMutability":"nonpayable","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":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"},{"internalType":"uint256","name":"nft","type":"uint256"}],"name":"depositCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositorsAllowlist","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"}],"name":"getOverallDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"admin","type":"address"},{"internalType":"uint256","name":"stabilisationFee_","type":"uint256"},{"internalType":"uint256","name":"maxDebtPerVault","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"isAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isLiquidatingPublic","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPublic","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"}],"name":"liquidate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liquidatorsAllowlist","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"makeLiquidationsPrivate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"makeLiquidationsPublic","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"makePrivate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"makePublic","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mintDebt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nft","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mintDebtFromScratch","outputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"minter","outputs":[{"internalType":"contract IMinter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"normalizationRate","outputs":[{"internalType":"uint216","name":"","type":"uint216"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"normalizationRateUpdateTimestamp","outputs":[{"internalType":"uint40","name":"","type":"uint40"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"normalizedGlobalDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"openVault","outputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"oracle","outputs":[{"internalType":"contract INFTOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"poolParams","outputs":[{"components":[{"internalType":"uint32","name":"liquidationThresholdD","type":"uint32"},{"internalType":"uint32","name":"borrowThresholdD","type":"uint32"},{"internalType":"uint24","name":"minWidth","type":"uint24"}],"internalType":"struct ICDP.PoolParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionManager","outputs":[{"internalType":"contract INonfungiblePositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolParams","outputs":[{"components":[{"internalType":"uint256","name":"maxDebtPerVault","type":"uint256"},{"internalType":"uint256","name":"minSingleNftCollateral","type":"uint256"},{"internalType":"uint32","name":"liquidationFeeD","type":"uint32"},{"internalType":"uint32","name":"liquidationPremiumD","type":"uint32"},{"internalType":"uint8","name":"maxNftsPerVault","type":"uint8"}],"internalType":"struct ICDP.ProtocolParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"depositors","type":"address[]"}],"name":"removeDepositorsFromAllowlist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"liquidators","type":"address[]"}],"name":"removeLiquidatorsFromAllowlist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"components":[{"internalType":"uint32","name":"liquidationThresholdD","type":"uint32"},{"internalType":"uint32","name":"borrowThresholdD","type":"uint32"},{"internalType":"uint24","name":"minWidth","type":"uint24"}],"internalType":"struct ICDP.PoolParams","name":"params","type":"tuple"}],"name":"setPoolParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stabilisationFeeRateD18","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"contract IBobToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"contract ITreasury","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateNormalizationRate","outputs":[{"internalType":"uint256","name":"updatedNormalizationRate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"stabilisationFeeRateD18_","type":"uint256"}],"name":"updateStabilisationFeeRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"vaultIdByNft","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"vaultMintedDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"}],"name":"vaultNftsById","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"vaultNormalizedDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"vaultOwed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vaultRegistry","outputs":[{"internalType":"contract IVaultRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nft","type":"uint256"}],"name":"withdrawCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultId","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"maxAmount","type":"uint256"}],"name":"withdrawOwed","outputs":[{"internalType":"uint256","name":"withdrawnAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

6101406040523480156200001257600080fd5b50604051620051f0380380620051f0833981016040819052620000359162000119565b60016002556001600160a01b03861615806200005857506001600160a01b038516155b806200006b57506001600160a01b038416155b806200007e57506001600160a01b038316155b806200009157506001600160a01b038216155b80620000a457506001600160a01b038116155b15620000c357604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b0395861660805293851660a05291841661010052831660c052821660e05216610120526003805460ff19166001179055620001ad565b6001600160a01b03811681146200011657600080fd5b50565b60008060008060008060c087890312156200013357600080fd5b8651620001408162000100565b6020880151909650620001538162000100565b6040880151909550620001668162000100565b6060880151909450620001798162000100565b60808801519093506200018c8162000100565b60a08801519092506200019f8162000100565b809150509295509295509295565b60805160a05160c05160e0516101005161012051614f21620002cf60003960008181610b72015281816120f801528181612d390152818161314b015261331e0152600081816106d00152818161181801528181611cc30152612a340152600081816104860152818161170b01528181611f30015281816126480152612ae3015260008181610c3a01528181611662015281816117f101528181611f03015281816127de015281816128f70152612a0d0152600081816107a901528181610ff6015281816133ba01526137ee01526000818161076701528181610cd701528181610d8301528181610f5f0152818161116b015281816111a30152818161121401528181611b4601528181612f4f0152818161307e01526139eb0152614f216000f3fe608060405234801561001057600080fd5b50600436106104545760003560e01c80638f1006e811610241578063b187bd261161013b578063d547741f116100c3578063ece1373211610087578063ece1373214610c0b578063fbe8287314610c1e578063fc018c0514610c2d578063fc0c546a14610c35578063fc6f786514610c5c57600080fd5b8063d547741f14610b94578063da65693614610ba7578063dc9a153514610bd2578063e273d23e14610be5578063e9f43bfe14610bf857600080fd5b8063bf0e05bd1161010a578063bf0e05bd14610b2c578063bf183d5414610b3f578063ca15c87314610b52578063cc3d812d14610b65578063cdd7b38a14610b6d57600080fd5b8063b187bd2614610a54578063ba66c0c314610a66578063ba98daa114610b0f578063baa6d73b14610b2357600080fd5b80639b52d8c8116101c9578063a39e4f6d1161018d578063a39e4f6d146109c0578063a5db40d3146109ee578063a8406ea314610a0e578063ac9650d814610a21578063ad88de4514610a4157600080fd5b80639b52d8c8146109775780639cd161981461098a578063a09eb0e71461099d578063a0fff598146109a5578063a217fddf146109b857600080fd5b806391d148541161021057806391d148541461085d57806393aab9d51461087057806394bf512d1461093c578063983d27371461094f57806398e35b721461096457600080fd5b80638f1006e8146108195780639010d07c1461082c578063918f86741461083f57806391b7ab471461084a57600080fd5b80634f7fe8181161035257806378a2d732116102da5780637dc63bd91161029e5780637dc63bd9146107cb57806383914540146107de5780638456cb59146107e957806386f54712146107f157806389ea841a146107f957600080fd5b806378a2d73214610742578063791b98bc146107625780637a1ac61e146107895780637c84b40c1461079c5780637dc0d1d0146107a457600080fd5b806361d027b31161032157806361d027b3146106cb57806368b35b1a146106f25780636cf80f07146106fa5780636d70f7ae1461071a57806375b238fc1461072d57600080fd5b80634f7fe818146106705780635412abbc146106855780635d2bb997146106985780636112fe2e146106b857600080fd5b80632c357f7f116103e057806336568abe116103a457806336568abe1461062c578063392e53cd1461063f5780633f4ba83a1461064c578063415f1240146106545780634643db3d1461066757600080fd5b80632c357f7f146105a55780632d922369146105b85780632e8dc029146105cb5780632f2ff15d1461060657806334ccc93b1461061957600080fd5b8063150b7a0211610427578063150b7a021461050b57806317733aa414610537578063243d9ee814610541578063248a9ca31461056f57806324d7806c1461059257600080fd5b806301ffc9a71461045957806307546172146104815780630952ff54146104c05780630c49ccbe146104e3575b600080fd5b61046c610467366004614474565b610c6f565b60405190151581526020015b60405180910390f35b6104a87f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610478565b6104d5600080516020614e6583398151915281565b604051908152602001610478565b6104f66104f136600461449e565b610c9b565b60408051928352602083019190915201610478565b61051e6105193660046144cb565b610d6e565b6040516001600160e01b03199091168152602001610478565b61053f610def565b005b60115461055990600160d81b900464ffffffffff1681565b60405164ffffffffff9091168152602001610478565b6104d561057d36600461456a565b60009081526020819052604090206001015490565b61046c6105a0366004614583565b610e37565b6104d56105b33660046145a0565b610e6f565b6104d56105c636600461456a565b610e8f565b6105de6105d93660046145d4565b610efd565b604080519586526020860194909452928401919091526060830152608082015260a001610478565b61053f610614366004614615565b6113f2565b61053f610627366004614645565b61141c565b61053f61063a366004614615565b611480565b60035461046c9060ff1681565b61053f611503565b61053f61066236600461456a565b611543565b6104d560135481565b61067861192f565b6040516104789190614668565b61053f6106933660046146c7565b611940565b6106ab6106a636600461456a565b6119bd565b60405161047891906146e4565b61053f6106c636600461456a565b611a1f565b6104a87f000000000000000000000000000000000000000000000000000000000000000081565b6104d5611c34565b6104d561070836600461456a565b600d6020526000908152604090205481565b61046c610728366004614583565b611d8b565b6104d5600080516020614e8583398151915281565b6104d561075036600461456a565b600f6020526000908152604090205481565b6104a87f000000000000000000000000000000000000000000000000000000000000000081565b61053f61079736600461471c565b611da5565b61053f611fb7565b6104a87f000000000000000000000000000000000000000000000000000000000000000081565b61053f6107d936600461479d565b611ff8565b6104d56301e1338081565b61053f61204e565b6104d5612092565b6104d561080736600461456a565b60106020526000908152604090205481565b61053f61082736600461479d565b6121aa565b6104a861083a3660046145a0565b612200565b6104d5633b9aca0081565b61053f61085836600461479d565b61221f565b61046c61086b366004614615565b612275565b6108eb6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152506040805160a0810182526004548152600554602082015260065463ffffffff8082169383019390935264010000000081049092166060820152600160401b90910460ff16608082015290565b6040516104789190600060a0820190508251825260208301516020830152604083015163ffffffff8082166040850152806060860151166060850152505060ff608084015116608083015292915050565b61053f61094a36600461456a565b61229e565b6104d5600080516020614ea583398151915281565b61053f6109723660046147df565b61231c565b61053f6109853660046145a0565b612526565b61053f610998366004614615565b6126f1565b610678612778565b6104d56109b3366004614820565b612784565b6104d5600081565b6109d36109ce36600461456a565b61287e565b60408051938452602084019290925290820152606001610478565b6104d56109fc36600461456a565b600e6020526000908152604090205481565b61053f610a1c3660046145a0565b6128ac565b610a34610a2f36600461479d565b612b8f565b60405161047891906148b0565b61053f610a4f36600461456a565b612c84565b60035461046c90610100900460ff1681565b610add610a74366004614583565b6040805160608082018352600080835260208084018290529284018190526001600160a01b03949094168452600b825292829020825193840183525463ffffffff808216855264010000000082041691840191909152600160401b900462ffffff169082015290565b60408051825163ffffffff9081168252602080850151909116908201529181015162ffffff1690820152606001610478565b60035461046c906301000000900460ff1681565b6104d560125481565b61053f610b3a36600461456a565b612cc3565b61053f610b4d36600461456a565b612da7565b6104d5610b6036600461456a565b612de6565b61053f612dfd565b6104a87f000000000000000000000000000000000000000000000000000000000000000081565b61053f610ba2366004614615565b612e3f565b601154610bba906001600160d81b031681565b6040516001600160d81b039091168152602001610478565b60035461046c9062010000900460ff1681565b61053f610bf336600461479d565b612e64565b61053f610c063660046146c7565b612eba565b61053f610c193660046145a0565b612f45565b6104d5670de0b6b3a764000081565b61053f612ffc565b6104a87f000000000000000000000000000000000000000000000000000000000000000081565b6104f6610c6a366004614912565b613042565b6000610c7a826130b3565b80610c955750630a85bd0160e11b6001600160e01b03198316145b92915050565b600080610ca66130d8565b8235600081815260106020526040902054610cc08161312f565b604051630624e65f60e11b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690630c49ccbe90610d0c908890600401614943565b60408051808303816000875af1158015610d2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4e919061498d565b9094509250610d5d81836131db565b5050610d696001600255565b915091565b6000610d7861324f565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610dc157604051631dd2188d60e31b815260040160405180910390fd5b6000610dcf8385018561456a565b9050610ddc86828761327a565b50630a85bd0160e11b9695505050505050565b610df761358a565b6003805463ff0000001916630100000017905560405133907fef5e493c2e7348f4fd959bcf6e71d301b624326b6250845cbe59c8d0fcebe82a90600090a2565b6000610e51600080516020614e8583398151915283612275565b80610c955750610c95600080516020614e6583398151915283612275565b6000610e79612092565b9050610e858184612f45565b610c958183612526565b60115460009064ffffffffff600160d81b820416906001600160d81b031642821015610eeb57610ede610ec283426149c7565b601254610ecf91906149de565b82670de0b6b3a76400006135b0565b610ee890826149fd565b90505b610ef58482613662565b949350505050565b6000806000806000610f0d6130d8565b8635600081815260106020526040902054610f278161312f565b87358214610f4857604051632a9ffab760e21b815260040160405180910390fd5b60405163fc6f786560e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063fc6f786590610f94908c90600401614a15565b60408051808303816000875af1158015610fb2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fd6919061498d565b604051630a8d58d560e11b81528a356004820152919550935060009081907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063151ab1aa906024016040805180830381865afa158015611044573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110689190614a76565b91509150816001600160a01b03166323b872dd33308d602001356040518463ffffffff1660e01b81526004016110a093929190614aa5565b6020604051808303816000875af11580156110bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e39190614ade565b50806001600160a01b03166323b872dd33308d604001356040518463ffffffff1660e01b815260040161111893929190614aa5565b6020604051808303816000875af1158015611137573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061115b9190614ade565b506111946001600160a01b0383167f000000000000000000000000000000000000000000000000000000000000000060208d0135613684565b6111cc6001600160a01b0382167f000000000000000000000000000000000000000000000000000000000000000060408d0135613684565b6040805163219f5d1760e01b81528b35600482015260208c01356024820152908b0135604482015260608b0135606482015260808b0135608482015260a08b013560a48201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063219f5d179060c4016060604051808303816000875af1158015611265573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112899190614af9565b6001600160801b039092169a509850965060208a0135881015611335576001600160a01b03821663a9059cbb336112c48b60208f01356149c7565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af115801561130f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113339190614ade565b505b89604001358710156113d0576001600160a01b03811663a9059cbb3361135f8a60408f01356149c7565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af11580156113aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113ce9190614ade565b505b6113da83856131db565b505050506113e86001600255565b9295509295909350565b60008281526020819052604090206001015461140d81613738565b6114178383613742565b505050565b61142461358a565b6006805468ff00000000000000001916600160401b60ff84169081029190911790915560405190815233907f93ebd95cae780a1d30f508000644b08880ede14a9f7c0a15d0cc3688c8bb9e32906020015b60405180910390a250565b6001600160a01b03811633146114f55760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b6114ff8282613764565b5050565b61150b61358a565b6003805461ff001916905560405133907f92414512bd79c80103975d8bef2f4e78aa5930c2869b4bd6139d98836ba8d91890600090a2565b61154b6130d8565b6003546301000000900460ff1615801561156d575061156b600933613786565b155b1561158b57604051633e53754760e01b815260040160405180910390fd5b6000611595611c34565b6000838152600d60205260408120546013805493945090928392906115bb9084906149c7565b90915550600090506115d68284670de0b6b3a76400006135b0565b90506000806115e886600060016137a8565b509150915082811061160d57604051630879983f60e21b815260040160405180910390fd5b60065460009061163e9061163390640100000000900463ffffffff16633b9aca006149c7565b84633b9aca006135b0565b90508381101561164b5750825b6040516323b872dd60e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906323b872dd9061169b90339030908690600401614aa5565b6020604051808303816000875af11580156116ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116de9190614ade565b506000878152600e60205260409081902054905163079cc67960e41b8152306004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906379cc679090604401600060405180830381600087803b15801561175757600080fd5b505af115801561176b573d6000803e3d6000fd5b50506006546000925061178b9150869063ffffffff16633b9aca006135b0565b905061179786846149c7565b81106117ae576117a786846149c7565b90506117e7565b806117b987856149c7565b6117c391906149c7565b60008a8152600f6020526040812080549091906117e19084906149fd565b90915550505b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016634000aea07f000000000000000000000000000000000000000000000000000000000000000083611842868b6149c7565b61184c91906149fd565b611856868b6149c7565b60405160200161186891815260200190565b6040516020818303038152906040526040518463ffffffff1660e01b815260040161189593929190614b30565b600060405180830381600087803b1580156118af57600080fd5b505af11580156118c3573d6000803e3d6000fd5b50505060008a8152600d60209081526040808320839055600e909152812055506118ed8933613996565b604051899033907f54047e1fbd97c7c3a1208df001f1b5c6c3e64e726907d2f8342f6b3946f4b83f90600090a3505050505050505061192c6001600255565b50565b606061193b6009613a95565b905090565b61194861358a565b633b9aca008163ffffffff16111561197357604051632a9ffab760e21b815260040160405180910390fd5b6006805463ffffffff191663ffffffff831690811790915560405190815233907fdab104cd183eaceea39a326133021af670c87a36ddd5f18a314a2f4ab2797a3290602001611475565b6000818152600c6020908152604091829020805483518184028101840190945280845260609392830182828015611a1357602002820191906000526020600020905b8154815260200190600101908083116119ff575b50505050509050919050565b611a276130d8565b6000611a31611c34565b600083815260106020526040902054909150611a4c8161312f565b6000818152600c60205260408120805490915b81811015611b1d5785838281548110611a7a57611a7a614b57565b906000526020600020015403611b0d57611a956001836149c7565b811015611ae25782611aa86001846149c7565b81548110611ab857611ab8614b57565b9060005260206000200154838281548110611ad557611ad5614b57565b6000918252602090912001555b82805480611af257611af2614b6d565b60019003818190600052602060002001600090559055611b1d565b611b1681614b83565b9050611a5f565b5060008581526010602052604080822091909155516323b872dd60e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906323b872dd90611b7f90309033908a90600401614aa5565b600060405180830381600087803b158015611b9957600080fd5b505af1158015611bad573d6000803e3d6000fd5b505050506000611bc084600060026137a8565b50915050611bce8486613662565b811015611bee57604051631d9d79c160e01b815260040160405180910390fd5b604051868152849033907f7203614e0f504976b0818798e50fe583523edfc0a9ee31bfa30fcf095d8e2d2c9060200160405180910390a3505050505061192c6001600255565b6011546000906001600160d81b03811690600160d81b900464ffffffffff1642819003611c615750919050565b6000611c8c611c7083426149c7565b601254611c7d91906149de565b84670de0b6b3a76400006135b0565b90506000611ca560135483670de0b6b3a76400006135b0565b90508015611d2857604051630801f16960e11b8152600481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690631003e2d290602401600060405180830381600087803b158015611d0f57600080fd5b505af1158015611d23573d6000803e3d6000fd5b505050505b611d3282856149fd565b6001600160d81b038116600160d81b4264ffffffffff1602176011556040518181529095507f8dada0f2db7e541d4a72a5ea7e60c61ba7e29c06f89144d9493fba9f59ea48d19060200160405180910390a15050505090565b6000610c95600080516020614ea583398151915283612275565b60035460ff1615611dc9576040516302ed543d60e51b815260040160405180910390fd5b6001600160a01b038316611df057604051639fabe1c160e01b815260040160405180910390fd5b611e066301e13380670de0b6b3a7640000614bb2565b821115611e2657604051632a9ffab760e21b815260040160405180910390fd5b611e3e600080516020614ea583398151915284613aa2565b611e56600080516020614e8583398151915284613aa2565b611e6e600080516020614e8583398151915280613aac565b611e94600080516020614e65833981519152600080516020614e85833981519152613aac565b611eba600080516020614ea5833981519152600080516020614e65833981519152613aac565b601282905564ffffffffff4216600160d81b02670de0b6b3a76400001760115560048181556003805460ff1916600117905560405163095ea7b360e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163095ea7b391611f6e917f00000000000000000000000000000000000000000000000000000000000000009160001991016001600160a01b03929092168252602082015260400190565b6020604051808303816000875af1158015611f8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fb19190614ade565b50505050565b611fbf61358a565b6003805462ff00001916905560405133907fccc348a419242e49e3259210e9a529e07bdb57cd751a519adcff1819f28fa52390600090a2565b61200061358a565b60005b818110156114175761203d83838381811061202057612020614b57565b90506020020160208101906120359190614583565b600990613af7565b5061204781614b83565b9050612003565b612056613b0c565b6003805461ff00191661010017905560405133907f0e453e53649b13b8c30ef82dd7bce6c745cfcc7a1dc95170b4750764194f19b290600090a2565b600061209c61324f565b6120a46130d8565b60035462010000900460ff161580156120c557506120c3600733613786565b155b156120e3576040516351caf8cd60e01b815260040160405180910390fd5b6040516335313c2160e11b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636a627842906024016020604051808303816000875af1158015612149573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061216d9190614bd4565b604051909150819033907f1774e23245eedaa4541d7c6aafe9840fbea9a6dc740c21dfbe2ecf3162789cb790600090a36121a76001600255565b90565b6121b261358a565b60005b81811015611417576121ef8383838181106121d2576121d2614b57565b90506020020160208101906121e79190614583565b600990613b46565b506121f981614b83565b90506121b5565b60008281526001602052604081206122189083613b5b565b9392505050565b61222761358a565b60005b818110156114175761226483838381811061224757612247614b57565b905060200201602081019061225c9190614583565b600790613af7565b5061226e81614b83565b905061222a565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6122a661358a565b6122bc6301e13380670de0b6b3a7640000614bb2565b8111156122dc57604051632a9ffab760e21b815260040160405180910390fd5b6122e4611c34565b50601281905560405181815233907f6943a055fb52d86ee20201343e49489cdfa589e06b204529c75cf0439150150a90602001611475565b61232461358a565b6001600160a01b03821661234b57604051639fabe1c160e01b815260040160405180910390fd5b633b9aca0061235d60208301836146c7565b63ffffffff16111561238257604051632a9ffab760e21b815260040160405180910390fd5b633b9aca0061239760408301602084016146c7565b63ffffffff1611156123bc57604051632a9ffab760e21b815260040160405180910390fd5b6123c960208201826146c7565b63ffffffff166123df60408301602084016146c7565b63ffffffff16111561240457604051632a9ffab760e21b815260040160405180910390fd5b6001600160a01b0382166000908152600b6020526040902081906124288282614bfe565b50506001600160a01b038216337f63d8aeda4f35263b07f39fbde68841c60484ed087a0ce8fd03fa58f3a119678961246360208501856146c7565b60405163ffffffff909116815260200160405180910390a36001600160a01b038216337f44203aa3b83162c84e9809ba3a44b98238fc5d45ba82a23ec0e51c496c6008096124b760408501602086016146c7565b60405163ffffffff909116815260200160405180910390a36001600160a01b038216337f2714bab35acd7c92e76384ee3da8594f758f9df3337332802b65b14dc571209361250b6060850160408601614c8d565b60405162ffffff909116815260200160405180910390a35050565b61252e6130d8565b61253661324f565b61253f8261312f565b6000612549611c34565b9050600061256083670de0b6b3a764000084613b67565b905080600d6000868152602001908152602001600020600082825461258591906149fd565b90915550506000848152600e6020526040812080548592906125a89084906149fd565b9250508190555080601360008282546125c191906149fd565b90915550600090506125d38584613662565b905060006125e486600060026137a8565b509150508181101561260957604051631d9d79c160e01b815260040160405180910390fd5b60045482111561262c576040516330c84bd760e21b815260040160405180910390fd5b6040516340c10f1960e01b8152336004820152602481018690527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906340c10f1990604401600060405180830381600087803b15801561269457600080fd5b505af11580156126a8573d6000803e3d6000fd5b50506040518781528892503391507f14937bfa593938d0972448553713724cf8834e7e5000ec55929e04f6f015b52e9060200160405180910390a3505050506114ff6001600255565b6126f961324f565b6127016130d8565b61270a8261312f565b6000828152600d602052604090205415612737576040516304aec73b60e01b815260040160405180910390fd5b6127418282613996565b604051829033907f7429155d3efb190893af355db048556e16b4076ce9a162c4276ffbab8b332ef090600090a36114ff6001600255565b606061193b6007613a95565b600061278e6130d8565b6127978461312f565b6000848152600f60205260409020548083116127b357826127b5565b805b60405163a9059cbb60e01b81526001600160a01b038681166004830152602482018390529193507f00000000000000000000000000000000000000000000000000000000000000009091169063a9059cbb906044016020604051808303816000875af1158015612829573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061284d9190614ade565b506000858152600f60205260408120805484929061286c9084906149c7565b90915550506001600255509392505050565b600080600061289084600060016137a8565b5090935091506128a2846000806137a8565b5093959294505050565b6128b46130d8565b60006128be611c34565b905060006128cc8483613662565b90508281106128db57826128dd565b805b6040516323b872dd60e01b81529093506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906323b872dd9061293090339030908890600401614aa5565b6020604051808303816000875af115801561294f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129739190614ade565b506000848152600e60205260408120549061298f8286856135b0565b905060006129a686670de0b6b3a764000087613b67565b905080600d600089815260200190815260200160002060008282546129cb91906149c7565b9250508190555080601360008282546129e491906149c7565b909155506129f4905082846149c7565b6000888152600e60205260409020556001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016634000aea07f0000000000000000000000000000000000000000000000000000000000000000612a5d858a6149c7565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526060604482015260006064820152608401600060405180830381600087803b158015612ab157600080fd5b505af1158015612ac5573d6000803e3d6000fd5b505060405163079cc67960e41b8152306004820152602481018590527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031692506379cc67909150604401600060405180830381600087803b158015612b3157600080fd5b505af1158015612b45573d6000803e3d6000fd5b50506040518881528992503391507f1039e927a4722f9e4a6efb289f1cfb0808a9ebce5102556eb560d05c827280c69060200160405180910390a350505050506114ff6001600255565b60608167ffffffffffffffff811115612baa57612baa614caa565b604051908082528060200260200182016040528015612bdd57816020015b6060815260200190600190039081612bc85790505b50905060005b82811015612c7d57612c4d30858584818110612c0157612c01614b57565b9050602002810190612c139190614cc0565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613ba792505050565b828281518110612c5f57612c5f614b57565b60200260200101819052508080612c7590614b83565b915050612be3565b5092915050565b612c8c61358a565b600481905560405181815233907fd6c80c8187c610628275eae7acd960b1d89c8b68cf546187c4db023a9d538a6a90602001611475565b612ccb61324f565b612cd36130d8565b612cdc8161312f565b6000818152600f6020526040902054151580612d0557506000818152600c602052604090205415155b15612d23576040516303eb22b560e11b815260040160405180910390fd5b604051630852cd8d60e31b8152600481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906342966c6890602401600060405180830381600087803b158015612d8557600080fd5b505af1158015612d99573d6000803e3d6000fd5b5050505061192c6001600255565b612daf61358a565b600581905560405181815233907f08deb31f2d1a36f08ced004659e7a7ee9284ad5b523d4ea01ae1b332a1bdcc3190602001611475565b6000818152600160205260408120610c9590613bcc565b612e0561358a565b6003805463ff0000001916905560405133907ff6d694957fc6ba48da5c87ad0a0dcb70e7b2ada0c55226c44082bb37a51798f390600090a2565b600082815260208190526040902060010154612e5a81613738565b6114178383613764565b612e6c61358a565b60005b8181101561141757612ea9838383818110612e8c57612e8c614b57565b9050602002016020810190612ea19190614583565b600790613b46565b50612eb381614b83565b9050612e6f565b612ec261358a565b633b9aca008163ffffffff161115612eed57604051632a9ffab760e21b815260040160405180910390fd5b6006805467ffffffff00000000191664010000000063ffffffff84169081029190911790915560405190815233907f7b022c806d425b80b10c2ea7aa181b64bf8f7ce77dc4d1c31c56851b764e69f190602001611475565b612f4d6130d8565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b88d4fde33308486604051602001612f9291815260200190565b6040516020818303038152906040526040518563ffffffff1660e01b8152600401612fc09493929190614d07565b600060405180830381600087803b158015612fda57600080fd5b505af1158015612fee573d6000803e3d6000fd5b505050506114ff6001600255565b61300461358a565b6003805462ff000019166201000017905560405133907f3066f4025a8f2e26b77ff543f0191277ece751b4c4eb7afc447293062e64082a90600090a2565b60008061304d6130d8565b82356000818152601060205260409020546130678161312f565b60405163fc6f786560e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063fc6f786590610d0c908890600401614a15565b60006001600160e01b03198216635a05180f60e01b1480610c955750610c9582613bd6565b60028054036131295760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016114ec565b60028055565b60405163609c6d7f60e01b8152600481018290523360248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063609c6d7f90604401602060405180830381865afa15801561319a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131be9190614ade565b61192c57604051631dd2188d60e31b815260040160405180910390fd5b60006131e5611c34565b90506000806131f6858560026137a8565b92509250506132058584613662565b82101561322557604051631d9d79c160e01b815260040160405180910390fd5b60055481101561324857604051635a0e910960e11b815260040160405180910390fd5b5050505050565b600354610100900460ff1615613278576040516313d0ff5960e31b815260040160405180910390fd5b565b60035462010000900460ff1615801561329b5750613299600784613786565b155b156132b9576040516351caf8cd60e01b815260040160405180910390fd5b6000828152600c602052604090208054600654600160401b900460ff16116132f457604051636187c51360e11b815260040160405180910390fd5b80541580156133955750604051634f4a156760e11b81526004810184905230906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690639e942ace90602401602060405180830381865afa158015613365573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133899190614d3a565b6001600160a01b031614155b156133b357604051630681d31960e51b815260040160405180910390fd5b60008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166326a49e37866040518263ffffffff1660e01b815260040161340691815260200190565b608060405180830381865afa158015613423573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134479190614d57565b6001600160a01b0381166000908152600b602090815260408083208151606081018352905463ffffffff8082168352640100000000820416938201849052600160401b900462ffffff169181019190915294985092965090945091925090036134c25760405162820f3560e61b815260040160405180910390fd5b806040015162ffffff168362ffffff1610156134f1576040516330c63b5960e21b815260040160405180910390fd5b60055484101561351457604051635a0e910960e11b815260040160405180910390fd5b60008681526010602090815260408083208a9055875460018101895588845291909220018790555187906001600160a01b038a16907ff4d587c98d234ca4d147061e6b5167e7f41ee17f11562a9f0b49570abece859e90613578908a815260200190565b60405180910390a35050505050505050565b61359333610e37565b61327857604051631dd2188d60e31b815260040160405180910390fd5b60008080600019858709858702925082811083820303915050806000036135e957600084116135de57600080fd5b508290049050612218565b8084116135f557600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000828152600d60205260408120546122189083670de0b6b3a76400006135b0565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526136d58482613c0b565b611fb157604080516001600160a01b038516602482015260006044808301919091528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b17905261372e908590613cb2565b611fb18482613cb2565b61192c8133613d87565b61374c8282613de0565b60008281526001602052604090206114179082613af7565b61376e8282613e64565b60008281526001602052604090206114179082613b46565b6001600160a01b03811660009081526001830160205260408120541515612218565b6000838152600c60205260408120805482918291825b8181101561398a5760008382815481106137da576137da614b57565b9060005260206000200154905060008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166326a49e37856040518263ffffffff1660e01b815260040161383a91815260200190565b608060405180830381865afa158015613857573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061387b9190614d57565b6001600160a01b0381166000908152600b60209081526040918290208251606081018452905463ffffffff808216835264010000000082041692820192909252600160401b90910462ffffff16918101919091529396509194509092506138e49050838c6149fd565b9a5060018c036139185761390783826000015163ffffffff16633b9aca006135b0565b613911908b6149fd565b9950613974565b61393183826020015163ffffffff16633b9aca006135b0565b61393b908b6149fd565b995060028c14801561394b575083155b15613969576040516313cbf65960e01b815260040160405180910390fd5b8c8503613974578298505b50505050508061398390614b83565b90506137be565b50505093509350939050565b6000828152600c60205260408120805490915b81811015613a7d5760008382815481106139c5576139c5614b57565b9060005260206000200154905060106000828152602001908152602001600020600090557f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166323b872dd3087846040518463ffffffff1660e01b8152600401613a3993929190614aa5565b600060405180830381600087803b158015613a5357600080fd5b505af1158015613a67573d6000803e3d6000fd5b505050505080613a7690614b83565b90506139a9565b506000848152600c60205260408120611fb191614442565b6060600061221883613ec9565b6114ff8282613742565b600082815260208190526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6000612218836001600160a01b038416613f23565b613b1533610e37565b158015613b285750613b2633611d8b565b155b1561327857604051631dd2188d60e31b815260040160405180910390fd5b6000612218836001600160a01b038416613f72565b60006122188383614065565b6000613b748484846135b0565b905060008280613b8657613b86614b9c565b8486091115612218576000198110613b9d57600080fd5b6001019392505050565b60606122188383604051806060016040528060278152602001614ec56027913961408f565b6000610c95825490565b60006001600160e01b03198216637965db0b60e01b1480610c9557506301ffc9a760e01b6001600160e01b0319831614610c95565b6000806000846001600160a01b031684604051613c289190614da9565b6000604051808303816000865af19150503d8060008114613c65576040519150601f19603f3d011682016040523d82523d6000602084013e613c6a565b606091505b5091509150818015613c94575080511580613c94575080806020019051810190613c949190614ade565b8015613ca957506001600160a01b0385163b15155b95945050505050565b6000613d07826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166141079092919063ffffffff16565b9050805160001480613d28575080806020019051810190613d289190614ade565b6114175760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016114ec565b613d918282612275565b6114ff57613d9e81614116565b613da9836020614128565b604051602001613dba929190614dc5565b60408051601f198184030181529082905262461bcd60e51b82526114ec91600401614e3a565b613dea8282612275565b6114ff576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055613e203390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b613e6e8282612275565b156114ff576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b606081600001805480602002602001604051908101604052809291908181526020018280548015611a1357602002820191906000526020600020908154815260200190600101908083116119ff5750505050509050919050565b6000818152600183016020526040812054613f6a57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610c95565b506000610c95565b6000818152600183016020526040812054801561405b576000613f966001836149c7565b8554909150600090613faa906001906149c7565b905081811461400f576000866000018281548110613fca57613fca614b57565b9060005260206000200154905080876000018481548110613fed57613fed614b57565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061402057614020614b6d565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610c95565b6000915050610c95565b600082600001828154811061407c5761407c614b57565b9060005260206000200154905092915050565b6060600080856001600160a01b0316856040516140ac9190614da9565b600060405180830381855af49150503d80600081146140e7576040519150601f19603f3d011682016040523d82523d6000602084013e6140ec565b606091505b50915091506140fd868383876142c4565b9695505050505050565b6060610ef5848460008561433d565b6060610c956001600160a01b03831660145b606060006141378360026149de565b6141429060026149fd565b67ffffffffffffffff81111561415a5761415a614caa565b6040519080825280601f01601f191660200182016040528015614184576020820181803683370190505b509050600360fc1b8160008151811061419f5761419f614b57565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106141ce576141ce614b57565b60200101906001600160f81b031916908160001a90535060006141f28460026149de565b6141fd9060016149fd565b90505b6001811115614275576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061423157614231614b57565b1a60f81b82828151811061424757614247614b57565b60200101906001600160f81b031916908160001a90535060049490941c9361426e81614e4d565b9050614200565b5083156122185760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016114ec565b6060831561433357825160000361432c576001600160a01b0385163b61432c5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016114ec565b5081610ef5565b610ef58383614418565b60608247101561439e5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016114ec565b600080866001600160a01b031685876040516143ba9190614da9565b60006040518083038185875af1925050503d80600081146143f7576040519150601f19603f3d011682016040523d82523d6000602084013e6143fc565b606091505b509150915061440d878383876142c4565b979650505050505050565b8151156144285781518083602001fd5b8060405162461bcd60e51b81526004016114ec9190614e3a565b508054600082559060005260206000209081019061192c91905b80821115614470576000815560010161445c565b5090565b60006020828403121561448657600080fd5b81356001600160e01b03198116811461221857600080fd5b600060a082840312156144b057600080fd5b50919050565b6001600160a01b038116811461192c57600080fd5b6000806000806000608086880312156144e357600080fd5b85356144ee816144b6565b945060208601356144fe816144b6565b935060408601359250606086013567ffffffffffffffff8082111561452257600080fd5b818801915088601f83011261453657600080fd5b81358181111561454557600080fd5b89602082850101111561455757600080fd5b9699959850939650602001949392505050565b60006020828403121561457c57600080fd5b5035919050565b60006020828403121561459557600080fd5b8135612218816144b6565b600080604083850312156145b357600080fd5b50508035926020909101359150565b6000608082840312156144b057600080fd5b6000808284036101408112156145e957600080fd5b6145f385856145c2565b925060c0607f198201121561460757600080fd5b506080830190509250929050565b6000806040838503121561462857600080fd5b82359150602083013561463a816144b6565b809150509250929050565b60006020828403121561465757600080fd5b813560ff8116811461221857600080fd5b6020808252825182820181905260009190848201906040850190845b818110156146a95783516001600160a01b031683529284019291840191600101614684565b50909695505050505050565b63ffffffff8116811461192c57600080fd5b6000602082840312156146d957600080fd5b8135612218816146b5565b6020808252825182820181905260009190848201906040850190845b818110156146a957835183529284019291840191600101614700565b60008060006060848603121561473157600080fd5b833561473c816144b6565b95602085013595506040909401359392505050565b60008083601f84011261476357600080fd5b50813567ffffffffffffffff81111561477b57600080fd5b6020830191508360208260051b850101111561479657600080fd5b9250929050565b600080602083850312156147b057600080fd5b823567ffffffffffffffff8111156147c757600080fd5b6147d385828601614751565b90969095509350505050565b60008082840360808112156147f357600080fd5b83356147fe816144b6565b92506060601f198201121561481257600080fd5b506020830190509250929050565b60008060006060848603121561483557600080fd5b833592506020840135614847816144b6565b929592945050506040919091013590565b60005b8381101561487357818101518382015260200161485b565b83811115611fb15750506000910152565b6000815180845261489c816020860160208601614858565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561490557603f198886030184526148f3858351614884565b945092850192908501906001016148d7565b5092979650505050505050565b60006080828403121561492457600080fd5b61221883836145c2565b6001600160801b038116811461192c57600080fd5b8135815260a0810160208301356149598161492e565b6001600160801b03811660208401525060408301356040830152606083013560608301526080830135608083015292915050565b600080604083850312156149a057600080fd5b505080516020909101519092909150565b634e487b7160e01b600052601160045260246000fd5b6000828210156149d9576149d96149b1565b500390565b60008160001904831182151516156149f8576149f86149b1565b500290565b60008219821115614a1057614a106149b1565b500190565b81358152608081016020830135614a2b816144b6565b6001600160a01b031660208301526040830135614a478161492e565b6001600160801b039081166040840152606084013590614a668261492e565b8082166060850152505092915050565b60008060408385031215614a8957600080fd5b8251614a94816144b6565b602084015190925061463a816144b6565b6001600160a01b039384168152919092166020820152604081019190915260600190565b80518015158114614ad957600080fd5b919050565b600060208284031215614af057600080fd5b61221882614ac9565b600080600060608486031215614b0e57600080fd5b8351614b198161492e565b602085015160409095015190969495509392505050565b60018060a01b0384168152826020820152606060408201526000613ca96060830184614884565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b600060018201614b9557614b956149b1565b5060010190565b634e487b7160e01b600052601260045260246000fd5b600082614bcf57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215614be657600080fd5b5051919050565b62ffffff8116811461192c57600080fd5b8135614c09816146b5565b63ffffffff8116905081548163ffffffff1982161783556020840135614c2e816146b5565b67ffffffff000000008160201b169050808367ffffffffffffffff198416171784556040850135614c5e81614bed565b6affffff00000000000000008160401b16846affffffffffffffffffffff198516178317178555505050505050565b600060208284031215614c9f57600080fd5b813561221881614bed565b634e487b7160e01b600052604160045260246000fd5b6000808335601e19843603018112614cd757600080fd5b83018035915067ffffffffffffffff821115614cf257600080fd5b60200191503681900382131561479657600080fd5b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906140fd90830184614884565b600060208284031215614d4c57600080fd5b8151612218816144b6565b60008060008060808587031215614d6d57600080fd5b614d7685614ac9565b9350602085015192506040850151614d8d81614bed565b6060860151909250614d9e816144b6565b939692955090935050565b60008251614dbb818460208701614858565b9190910192915050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614dfd816017850160208801614858565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351614e2e816028840160208801614858565b01602801949350505050565b6020815260006122186020830184614884565b600081614e5c57614e5c6149b1565b50600019019056fec171260023d22a25a00a2789664c9334017843b831138c8ef03cc8897e5873d7f23ec0bb4210edd5cba85afd05127efcd2fc6a781bfed49188da1081670b22d846a52cf33029de9f84853745a87af28464c80bf0346df1b32e205fc73319f622416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220a251be3f9204c3433762905d58db3d60a91488b21846712dff9beaaeeac6063364736f6c634300080f0033000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8800000000000000000000000031320bb77b26f0ce0e3febf089a5570b590add88000000000000000000000000904b6ebd837d9ee6330cf357f902172e9dfedfd5000000000000000000000000b0b195aefa3650a6908f15cdac7d92f8a5791b0b0000000000000000000000009032e988f5d46e0a21629e9effbb000cfbc28e2d0000000000000000000000008ae129b5b0beec40dc6c114b34a28b1efde49ee6

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106104545760003560e01c80638f1006e811610241578063b187bd261161013b578063d547741f116100c3578063ece1373211610087578063ece1373214610c0b578063fbe8287314610c1e578063fc018c0514610c2d578063fc0c546a14610c35578063fc6f786514610c5c57600080fd5b8063d547741f14610b94578063da65693614610ba7578063dc9a153514610bd2578063e273d23e14610be5578063e9f43bfe14610bf857600080fd5b8063bf0e05bd1161010a578063bf0e05bd14610b2c578063bf183d5414610b3f578063ca15c87314610b52578063cc3d812d14610b65578063cdd7b38a14610b6d57600080fd5b8063b187bd2614610a54578063ba66c0c314610a66578063ba98daa114610b0f578063baa6d73b14610b2357600080fd5b80639b52d8c8116101c9578063a39e4f6d1161018d578063a39e4f6d146109c0578063a5db40d3146109ee578063a8406ea314610a0e578063ac9650d814610a21578063ad88de4514610a4157600080fd5b80639b52d8c8146109775780639cd161981461098a578063a09eb0e71461099d578063a0fff598146109a5578063a217fddf146109b857600080fd5b806391d148541161021057806391d148541461085d57806393aab9d51461087057806394bf512d1461093c578063983d27371461094f57806398e35b721461096457600080fd5b80638f1006e8146108195780639010d07c1461082c578063918f86741461083f57806391b7ab471461084a57600080fd5b80634f7fe8181161035257806378a2d732116102da5780637dc63bd91161029e5780637dc63bd9146107cb57806383914540146107de5780638456cb59146107e957806386f54712146107f157806389ea841a146107f957600080fd5b806378a2d73214610742578063791b98bc146107625780637a1ac61e146107895780637c84b40c1461079c5780637dc0d1d0146107a457600080fd5b806361d027b31161032157806361d027b3146106cb57806368b35b1a146106f25780636cf80f07146106fa5780636d70f7ae1461071a57806375b238fc1461072d57600080fd5b80634f7fe818146106705780635412abbc146106855780635d2bb997146106985780636112fe2e146106b857600080fd5b80632c357f7f116103e057806336568abe116103a457806336568abe1461062c578063392e53cd1461063f5780633f4ba83a1461064c578063415f1240146106545780634643db3d1461066757600080fd5b80632c357f7f146105a55780632d922369146105b85780632e8dc029146105cb5780632f2ff15d1461060657806334ccc93b1461061957600080fd5b8063150b7a0211610427578063150b7a021461050b57806317733aa414610537578063243d9ee814610541578063248a9ca31461056f57806324d7806c1461059257600080fd5b806301ffc9a71461045957806307546172146104815780630952ff54146104c05780630c49ccbe146104e3575b600080fd5b61046c610467366004614474565b610c6f565b60405190151581526020015b60405180910390f35b6104a87f0000000000000000000000009032e988f5d46e0a21629e9effbb000cfbc28e2d81565b6040516001600160a01b039091168152602001610478565b6104d5600080516020614e6583398151915281565b604051908152602001610478565b6104f66104f136600461449e565b610c9b565b60408051928352602083019190915201610478565b61051e6105193660046144cb565b610d6e565b6040516001600160e01b03199091168152602001610478565b61053f610def565b005b60115461055990600160d81b900464ffffffffff1681565b60405164ffffffffff9091168152602001610478565b6104d561057d36600461456a565b60009081526020819052604090206001015490565b61046c6105a0366004614583565b610e37565b6104d56105b33660046145a0565b610e6f565b6104d56105c636600461456a565b610e8f565b6105de6105d93660046145d4565b610efd565b604080519586526020860194909452928401919091526060830152608082015260a001610478565b61053f610614366004614615565b6113f2565b61053f610627366004614645565b61141c565b61053f61063a366004614615565b611480565b60035461046c9060ff1681565b61053f611503565b61053f61066236600461456a565b611543565b6104d560135481565b61067861192f565b6040516104789190614668565b61053f6106933660046146c7565b611940565b6106ab6106a636600461456a565b6119bd565b60405161047891906146e4565b61053f6106c636600461456a565b611a1f565b6104a87f000000000000000000000000904b6ebd837d9ee6330cf357f902172e9dfedfd581565b6104d5611c34565b6104d561070836600461456a565b600d6020526000908152604090205481565b61046c610728366004614583565b611d8b565b6104d5600080516020614e8583398151915281565b6104d561075036600461456a565b600f6020526000908152604090205481565b6104a87f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8881565b61053f61079736600461471c565b611da5565b61053f611fb7565b6104a87f00000000000000000000000031320bb77b26f0ce0e3febf089a5570b590add8881565b61053f6107d936600461479d565b611ff8565b6104d56301e1338081565b61053f61204e565b6104d5612092565b6104d561080736600461456a565b60106020526000908152604090205481565b61053f61082736600461479d565b6121aa565b6104a861083a3660046145a0565b612200565b6104d5633b9aca0081565b61053f61085836600461479d565b61221f565b61046c61086b366004614615565b612275565b6108eb6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152506040805160a0810182526004548152600554602082015260065463ffffffff8082169383019390935264010000000081049092166060820152600160401b90910460ff16608082015290565b6040516104789190600060a0820190508251825260208301516020830152604083015163ffffffff8082166040850152806060860151166060850152505060ff608084015116608083015292915050565b61053f61094a36600461456a565b61229e565b6104d5600080516020614ea583398151915281565b61053f6109723660046147df565b61231c565b61053f6109853660046145a0565b612526565b61053f610998366004614615565b6126f1565b610678612778565b6104d56109b3366004614820565b612784565b6104d5600081565b6109d36109ce36600461456a565b61287e565b60408051938452602084019290925290820152606001610478565b6104d56109fc36600461456a565b600e6020526000908152604090205481565b61053f610a1c3660046145a0565b6128ac565b610a34610a2f36600461479d565b612b8f565b60405161047891906148b0565b61053f610a4f36600461456a565b612c84565b60035461046c90610100900460ff1681565b610add610a74366004614583565b6040805160608082018352600080835260208084018290529284018190526001600160a01b03949094168452600b825292829020825193840183525463ffffffff808216855264010000000082041691840191909152600160401b900462ffffff169082015290565b60408051825163ffffffff9081168252602080850151909116908201529181015162ffffff1690820152606001610478565b60035461046c906301000000900460ff1681565b6104d560125481565b61053f610b3a36600461456a565b612cc3565b61053f610b4d36600461456a565b612da7565b6104d5610b6036600461456a565b612de6565b61053f612dfd565b6104a87f0000000000000000000000008ae129b5b0beec40dc6c114b34a28b1efde49ee681565b61053f610ba2366004614615565b612e3f565b601154610bba906001600160d81b031681565b6040516001600160d81b039091168152602001610478565b60035461046c9062010000900460ff1681565b61053f610bf336600461479d565b612e64565b61053f610c063660046146c7565b612eba565b61053f610c193660046145a0565b612f45565b6104d5670de0b6b3a764000081565b61053f612ffc565b6104a87f000000000000000000000000b0b195aefa3650a6908f15cdac7d92f8a5791b0b81565b6104f6610c6a366004614912565b613042565b6000610c7a826130b3565b80610c955750630a85bd0160e11b6001600160e01b03198316145b92915050565b600080610ca66130d8565b8235600081815260106020526040902054610cc08161312f565b604051630624e65f60e11b81526001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe881690630c49ccbe90610d0c908890600401614943565b60408051808303816000875af1158015610d2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4e919061498d565b9094509250610d5d81836131db565b5050610d696001600255565b915091565b6000610d7861324f565b336001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe881614610dc157604051631dd2188d60e31b815260040160405180910390fd5b6000610dcf8385018561456a565b9050610ddc86828761327a565b50630a85bd0160e11b9695505050505050565b610df761358a565b6003805463ff0000001916630100000017905560405133907fef5e493c2e7348f4fd959bcf6e71d301b624326b6250845cbe59c8d0fcebe82a90600090a2565b6000610e51600080516020614e8583398151915283612275565b80610c955750610c95600080516020614e6583398151915283612275565b6000610e79612092565b9050610e858184612f45565b610c958183612526565b60115460009064ffffffffff600160d81b820416906001600160d81b031642821015610eeb57610ede610ec283426149c7565b601254610ecf91906149de565b82670de0b6b3a76400006135b0565b610ee890826149fd565b90505b610ef58482613662565b949350505050565b6000806000806000610f0d6130d8565b8635600081815260106020526040902054610f278161312f565b87358214610f4857604051632a9ffab760e21b815260040160405180910390fd5b60405163fc6f786560e01b81526001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88169063fc6f786590610f94908c90600401614a15565b60408051808303816000875af1158015610fb2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fd6919061498d565b604051630a8d58d560e11b81528a356004820152919550935060009081907f00000000000000000000000031320bb77b26f0ce0e3febf089a5570b590add886001600160a01b03169063151ab1aa906024016040805180830381865afa158015611044573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110689190614a76565b91509150816001600160a01b03166323b872dd33308d602001356040518463ffffffff1660e01b81526004016110a093929190614aa5565b6020604051808303816000875af11580156110bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e39190614ade565b50806001600160a01b03166323b872dd33308d604001356040518463ffffffff1660e01b815260040161111893929190614aa5565b6020604051808303816000875af1158015611137573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061115b9190614ade565b506111946001600160a01b0383167f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8860208d0135613684565b6111cc6001600160a01b0382167f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8860408d0135613684565b6040805163219f5d1760e01b81528b35600482015260208c01356024820152908b0135604482015260608b0135606482015260808b0135608482015260a08b013560a48201527f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03169063219f5d179060c4016060604051808303816000875af1158015611265573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112899190614af9565b6001600160801b039092169a509850965060208a0135881015611335576001600160a01b03821663a9059cbb336112c48b60208f01356149c7565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af115801561130f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113339190614ade565b505b89604001358710156113d0576001600160a01b03811663a9059cbb3361135f8a60408f01356149c7565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af11580156113aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113ce9190614ade565b505b6113da83856131db565b505050506113e86001600255565b9295509295909350565b60008281526020819052604090206001015461140d81613738565b6114178383613742565b505050565b61142461358a565b6006805468ff00000000000000001916600160401b60ff84169081029190911790915560405190815233907f93ebd95cae780a1d30f508000644b08880ede14a9f7c0a15d0cc3688c8bb9e32906020015b60405180910390a250565b6001600160a01b03811633146114f55760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b6114ff8282613764565b5050565b61150b61358a565b6003805461ff001916905560405133907f92414512bd79c80103975d8bef2f4e78aa5930c2869b4bd6139d98836ba8d91890600090a2565b61154b6130d8565b6003546301000000900460ff1615801561156d575061156b600933613786565b155b1561158b57604051633e53754760e01b815260040160405180910390fd5b6000611595611c34565b6000838152600d60205260408120546013805493945090928392906115bb9084906149c7565b90915550600090506115d68284670de0b6b3a76400006135b0565b90506000806115e886600060016137a8565b509150915082811061160d57604051630879983f60e21b815260040160405180910390fd5b60065460009061163e9061163390640100000000900463ffffffff16633b9aca006149c7565b84633b9aca006135b0565b90508381101561164b5750825b6040516323b872dd60e01b81526001600160a01b037f000000000000000000000000b0b195aefa3650a6908f15cdac7d92f8a5791b0b16906323b872dd9061169b90339030908690600401614aa5565b6020604051808303816000875af11580156116ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116de9190614ade565b506000878152600e60205260409081902054905163079cc67960e41b8152306004820152602481018290527f0000000000000000000000009032e988f5d46e0a21629e9effbb000cfbc28e2d6001600160a01b0316906379cc679090604401600060405180830381600087803b15801561175757600080fd5b505af115801561176b573d6000803e3d6000fd5b50506006546000925061178b9150869063ffffffff16633b9aca006135b0565b905061179786846149c7565b81106117ae576117a786846149c7565b90506117e7565b806117b987856149c7565b6117c391906149c7565b60008a8152600f6020526040812080549091906117e19084906149fd565b90915550505b6001600160a01b037f000000000000000000000000b0b195aefa3650a6908f15cdac7d92f8a5791b0b16634000aea07f000000000000000000000000904b6ebd837d9ee6330cf357f902172e9dfedfd583611842868b6149c7565b61184c91906149fd565b611856868b6149c7565b60405160200161186891815260200190565b6040516020818303038152906040526040518463ffffffff1660e01b815260040161189593929190614b30565b600060405180830381600087803b1580156118af57600080fd5b505af11580156118c3573d6000803e3d6000fd5b50505060008a8152600d60209081526040808320839055600e909152812055506118ed8933613996565b604051899033907f54047e1fbd97c7c3a1208df001f1b5c6c3e64e726907d2f8342f6b3946f4b83f90600090a3505050505050505061192c6001600255565b50565b606061193b6009613a95565b905090565b61194861358a565b633b9aca008163ffffffff16111561197357604051632a9ffab760e21b815260040160405180910390fd5b6006805463ffffffff191663ffffffff831690811790915560405190815233907fdab104cd183eaceea39a326133021af670c87a36ddd5f18a314a2f4ab2797a3290602001611475565b6000818152600c6020908152604091829020805483518184028101840190945280845260609392830182828015611a1357602002820191906000526020600020905b8154815260200190600101908083116119ff575b50505050509050919050565b611a276130d8565b6000611a31611c34565b600083815260106020526040902054909150611a4c8161312f565b6000818152600c60205260408120805490915b81811015611b1d5785838281548110611a7a57611a7a614b57565b906000526020600020015403611b0d57611a956001836149c7565b811015611ae25782611aa86001846149c7565b81548110611ab857611ab8614b57565b9060005260206000200154838281548110611ad557611ad5614b57565b6000918252602090912001555b82805480611af257611af2614b6d565b60019003818190600052602060002001600090559055611b1d565b611b1681614b83565b9050611a5f565b5060008581526010602052604080822091909155516323b872dd60e01b81526001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8816906323b872dd90611b7f90309033908a90600401614aa5565b600060405180830381600087803b158015611b9957600080fd5b505af1158015611bad573d6000803e3d6000fd5b505050506000611bc084600060026137a8565b50915050611bce8486613662565b811015611bee57604051631d9d79c160e01b815260040160405180910390fd5b604051868152849033907f7203614e0f504976b0818798e50fe583523edfc0a9ee31bfa30fcf095d8e2d2c9060200160405180910390a3505050505061192c6001600255565b6011546000906001600160d81b03811690600160d81b900464ffffffffff1642819003611c615750919050565b6000611c8c611c7083426149c7565b601254611c7d91906149de565b84670de0b6b3a76400006135b0565b90506000611ca560135483670de0b6b3a76400006135b0565b90508015611d2857604051630801f16960e11b8152600481018290527f000000000000000000000000904b6ebd837d9ee6330cf357f902172e9dfedfd56001600160a01b031690631003e2d290602401600060405180830381600087803b158015611d0f57600080fd5b505af1158015611d23573d6000803e3d6000fd5b505050505b611d3282856149fd565b6001600160d81b038116600160d81b4264ffffffffff1602176011556040518181529095507f8dada0f2db7e541d4a72a5ea7e60c61ba7e29c06f89144d9493fba9f59ea48d19060200160405180910390a15050505090565b6000610c95600080516020614ea583398151915283612275565b60035460ff1615611dc9576040516302ed543d60e51b815260040160405180910390fd5b6001600160a01b038316611df057604051639fabe1c160e01b815260040160405180910390fd5b611e066301e13380670de0b6b3a7640000614bb2565b821115611e2657604051632a9ffab760e21b815260040160405180910390fd5b611e3e600080516020614ea583398151915284613aa2565b611e56600080516020614e8583398151915284613aa2565b611e6e600080516020614e8583398151915280613aac565b611e94600080516020614e65833981519152600080516020614e85833981519152613aac565b611eba600080516020614ea5833981519152600080516020614e65833981519152613aac565b601282905564ffffffffff4216600160d81b02670de0b6b3a76400001760115560048181556003805460ff1916600117905560405163095ea7b360e01b81526001600160a01b037f000000000000000000000000b0b195aefa3650a6908f15cdac7d92f8a5791b0b169163095ea7b391611f6e917f0000000000000000000000009032e988f5d46e0a21629e9effbb000cfbc28e2d9160001991016001600160a01b03929092168252602082015260400190565b6020604051808303816000875af1158015611f8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fb19190614ade565b50505050565b611fbf61358a565b6003805462ff00001916905560405133907fccc348a419242e49e3259210e9a529e07bdb57cd751a519adcff1819f28fa52390600090a2565b61200061358a565b60005b818110156114175761203d83838381811061202057612020614b57565b90506020020160208101906120359190614583565b600990613af7565b5061204781614b83565b9050612003565b612056613b0c565b6003805461ff00191661010017905560405133907f0e453e53649b13b8c30ef82dd7bce6c745cfcc7a1dc95170b4750764194f19b290600090a2565b600061209c61324f565b6120a46130d8565b60035462010000900460ff161580156120c557506120c3600733613786565b155b156120e3576040516351caf8cd60e01b815260040160405180910390fd5b6040516335313c2160e11b81523360048201527f0000000000000000000000008ae129b5b0beec40dc6c114b34a28b1efde49ee66001600160a01b031690636a627842906024016020604051808303816000875af1158015612149573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061216d9190614bd4565b604051909150819033907f1774e23245eedaa4541d7c6aafe9840fbea9a6dc740c21dfbe2ecf3162789cb790600090a36121a76001600255565b90565b6121b261358a565b60005b81811015611417576121ef8383838181106121d2576121d2614b57565b90506020020160208101906121e79190614583565b600990613b46565b506121f981614b83565b90506121b5565b60008281526001602052604081206122189083613b5b565b9392505050565b61222761358a565b60005b818110156114175761226483838381811061224757612247614b57565b905060200201602081019061225c9190614583565b600790613af7565b5061226e81614b83565b905061222a565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6122a661358a565b6122bc6301e13380670de0b6b3a7640000614bb2565b8111156122dc57604051632a9ffab760e21b815260040160405180910390fd5b6122e4611c34565b50601281905560405181815233907f6943a055fb52d86ee20201343e49489cdfa589e06b204529c75cf0439150150a90602001611475565b61232461358a565b6001600160a01b03821661234b57604051639fabe1c160e01b815260040160405180910390fd5b633b9aca0061235d60208301836146c7565b63ffffffff16111561238257604051632a9ffab760e21b815260040160405180910390fd5b633b9aca0061239760408301602084016146c7565b63ffffffff1611156123bc57604051632a9ffab760e21b815260040160405180910390fd5b6123c960208201826146c7565b63ffffffff166123df60408301602084016146c7565b63ffffffff16111561240457604051632a9ffab760e21b815260040160405180910390fd5b6001600160a01b0382166000908152600b6020526040902081906124288282614bfe565b50506001600160a01b038216337f63d8aeda4f35263b07f39fbde68841c60484ed087a0ce8fd03fa58f3a119678961246360208501856146c7565b60405163ffffffff909116815260200160405180910390a36001600160a01b038216337f44203aa3b83162c84e9809ba3a44b98238fc5d45ba82a23ec0e51c496c6008096124b760408501602086016146c7565b60405163ffffffff909116815260200160405180910390a36001600160a01b038216337f2714bab35acd7c92e76384ee3da8594f758f9df3337332802b65b14dc571209361250b6060850160408601614c8d565b60405162ffffff909116815260200160405180910390a35050565b61252e6130d8565b61253661324f565b61253f8261312f565b6000612549611c34565b9050600061256083670de0b6b3a764000084613b67565b905080600d6000868152602001908152602001600020600082825461258591906149fd565b90915550506000848152600e6020526040812080548592906125a89084906149fd565b9250508190555080601360008282546125c191906149fd565b90915550600090506125d38584613662565b905060006125e486600060026137a8565b509150508181101561260957604051631d9d79c160e01b815260040160405180910390fd5b60045482111561262c576040516330c84bd760e21b815260040160405180910390fd5b6040516340c10f1960e01b8152336004820152602481018690527f0000000000000000000000009032e988f5d46e0a21629e9effbb000cfbc28e2d6001600160a01b0316906340c10f1990604401600060405180830381600087803b15801561269457600080fd5b505af11580156126a8573d6000803e3d6000fd5b50506040518781528892503391507f14937bfa593938d0972448553713724cf8834e7e5000ec55929e04f6f015b52e9060200160405180910390a3505050506114ff6001600255565b6126f961324f565b6127016130d8565b61270a8261312f565b6000828152600d602052604090205415612737576040516304aec73b60e01b815260040160405180910390fd5b6127418282613996565b604051829033907f7429155d3efb190893af355db048556e16b4076ce9a162c4276ffbab8b332ef090600090a36114ff6001600255565b606061193b6007613a95565b600061278e6130d8565b6127978461312f565b6000848152600f60205260409020548083116127b357826127b5565b805b60405163a9059cbb60e01b81526001600160a01b038681166004830152602482018390529193507f000000000000000000000000b0b195aefa3650a6908f15cdac7d92f8a5791b0b9091169063a9059cbb906044016020604051808303816000875af1158015612829573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061284d9190614ade565b506000858152600f60205260408120805484929061286c9084906149c7565b90915550506001600255509392505050565b600080600061289084600060016137a8565b5090935091506128a2846000806137a8565b5093959294505050565b6128b46130d8565b60006128be611c34565b905060006128cc8483613662565b90508281106128db57826128dd565b805b6040516323b872dd60e01b81529093506001600160a01b037f000000000000000000000000b0b195aefa3650a6908f15cdac7d92f8a5791b0b16906323b872dd9061293090339030908890600401614aa5565b6020604051808303816000875af115801561294f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129739190614ade565b506000848152600e60205260408120549061298f8286856135b0565b905060006129a686670de0b6b3a764000087613b67565b905080600d600089815260200190815260200160002060008282546129cb91906149c7565b9250508190555080601360008282546129e491906149c7565b909155506129f4905082846149c7565b6000888152600e60205260409020556001600160a01b037f000000000000000000000000b0b195aefa3650a6908f15cdac7d92f8a5791b0b16634000aea07f000000000000000000000000904b6ebd837d9ee6330cf357f902172e9dfedfd5612a5d858a6149c7565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526060604482015260006064820152608401600060405180830381600087803b158015612ab157600080fd5b505af1158015612ac5573d6000803e3d6000fd5b505060405163079cc67960e41b8152306004820152602481018590527f0000000000000000000000009032e988f5d46e0a21629e9effbb000cfbc28e2d6001600160a01b031692506379cc67909150604401600060405180830381600087803b158015612b3157600080fd5b505af1158015612b45573d6000803e3d6000fd5b50506040518881528992503391507f1039e927a4722f9e4a6efb289f1cfb0808a9ebce5102556eb560d05c827280c69060200160405180910390a350505050506114ff6001600255565b60608167ffffffffffffffff811115612baa57612baa614caa565b604051908082528060200260200182016040528015612bdd57816020015b6060815260200190600190039081612bc85790505b50905060005b82811015612c7d57612c4d30858584818110612c0157612c01614b57565b9050602002810190612c139190614cc0565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613ba792505050565b828281518110612c5f57612c5f614b57565b60200260200101819052508080612c7590614b83565b915050612be3565b5092915050565b612c8c61358a565b600481905560405181815233907fd6c80c8187c610628275eae7acd960b1d89c8b68cf546187c4db023a9d538a6a90602001611475565b612ccb61324f565b612cd36130d8565b612cdc8161312f565b6000818152600f6020526040902054151580612d0557506000818152600c602052604090205415155b15612d23576040516303eb22b560e11b815260040160405180910390fd5b604051630852cd8d60e31b8152600481018290527f0000000000000000000000008ae129b5b0beec40dc6c114b34a28b1efde49ee66001600160a01b0316906342966c6890602401600060405180830381600087803b158015612d8557600080fd5b505af1158015612d99573d6000803e3d6000fd5b5050505061192c6001600255565b612daf61358a565b600581905560405181815233907f08deb31f2d1a36f08ced004659e7a7ee9284ad5b523d4ea01ae1b332a1bdcc3190602001611475565b6000818152600160205260408120610c9590613bcc565b612e0561358a565b6003805463ff0000001916905560405133907ff6d694957fc6ba48da5c87ad0a0dcb70e7b2ada0c55226c44082bb37a51798f390600090a2565b600082815260208190526040902060010154612e5a81613738565b6114178383613764565b612e6c61358a565b60005b8181101561141757612ea9838383818110612e8c57612e8c614b57565b9050602002016020810190612ea19190614583565b600790613b46565b50612eb381614b83565b9050612e6f565b612ec261358a565b633b9aca008163ffffffff161115612eed57604051632a9ffab760e21b815260040160405180910390fd5b6006805467ffffffff00000000191664010000000063ffffffff84169081029190911790915560405190815233907f7b022c806d425b80b10c2ea7aa181b64bf8f7ce77dc4d1c31c56851b764e69f190602001611475565b612f4d6130d8565b7f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b031663b88d4fde33308486604051602001612f9291815260200190565b6040516020818303038152906040526040518563ffffffff1660e01b8152600401612fc09493929190614d07565b600060405180830381600087803b158015612fda57600080fd5b505af1158015612fee573d6000803e3d6000fd5b505050506114ff6001600255565b61300461358a565b6003805462ff000019166201000017905560405133907f3066f4025a8f2e26b77ff543f0191277ece751b4c4eb7afc447293062e64082a90600090a2565b60008061304d6130d8565b82356000818152601060205260409020546130678161312f565b60405163fc6f786560e01b81526001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88169063fc6f786590610d0c908890600401614a15565b60006001600160e01b03198216635a05180f60e01b1480610c955750610c9582613bd6565b60028054036131295760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016114ec565b60028055565b60405163609c6d7f60e01b8152600481018290523360248201527f0000000000000000000000008ae129b5b0beec40dc6c114b34a28b1efde49ee66001600160a01b03169063609c6d7f90604401602060405180830381865afa15801561319a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131be9190614ade565b61192c57604051631dd2188d60e31b815260040160405180910390fd5b60006131e5611c34565b90506000806131f6858560026137a8565b92509250506132058584613662565b82101561322557604051631d9d79c160e01b815260040160405180910390fd5b60055481101561324857604051635a0e910960e11b815260040160405180910390fd5b5050505050565b600354610100900460ff1615613278576040516313d0ff5960e31b815260040160405180910390fd5b565b60035462010000900460ff1615801561329b5750613299600784613786565b155b156132b9576040516351caf8cd60e01b815260040160405180910390fd5b6000828152600c602052604090208054600654600160401b900460ff16116132f457604051636187c51360e11b815260040160405180910390fd5b80541580156133955750604051634f4a156760e11b81526004810184905230906001600160a01b037f0000000000000000000000008ae129b5b0beec40dc6c114b34a28b1efde49ee61690639e942ace90602401602060405180830381865afa158015613365573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133899190614d3a565b6001600160a01b031614155b156133b357604051630681d31960e51b815260040160405180910390fd5b60008060007f00000000000000000000000031320bb77b26f0ce0e3febf089a5570b590add886001600160a01b03166326a49e37866040518263ffffffff1660e01b815260040161340691815260200190565b608060405180830381865afa158015613423573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134479190614d57565b6001600160a01b0381166000908152600b602090815260408083208151606081018352905463ffffffff8082168352640100000000820416938201849052600160401b900462ffffff169181019190915294985092965090945091925090036134c25760405162820f3560e61b815260040160405180910390fd5b806040015162ffffff168362ffffff1610156134f1576040516330c63b5960e21b815260040160405180910390fd5b60055484101561351457604051635a0e910960e11b815260040160405180910390fd5b60008681526010602090815260408083208a9055875460018101895588845291909220018790555187906001600160a01b038a16907ff4d587c98d234ca4d147061e6b5167e7f41ee17f11562a9f0b49570abece859e90613578908a815260200190565b60405180910390a35050505050505050565b61359333610e37565b61327857604051631dd2188d60e31b815260040160405180910390fd5b60008080600019858709858702925082811083820303915050806000036135e957600084116135de57600080fd5b508290049050612218565b8084116135f557600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000828152600d60205260408120546122189083670de0b6b3a76400006135b0565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526136d58482613c0b565b611fb157604080516001600160a01b038516602482015260006044808301919091528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b17905261372e908590613cb2565b611fb18482613cb2565b61192c8133613d87565b61374c8282613de0565b60008281526001602052604090206114179082613af7565b61376e8282613e64565b60008281526001602052604090206114179082613b46565b6001600160a01b03811660009081526001830160205260408120541515612218565b6000838152600c60205260408120805482918291825b8181101561398a5760008382815481106137da576137da614b57565b9060005260206000200154905060008060007f00000000000000000000000031320bb77b26f0ce0e3febf089a5570b590add886001600160a01b03166326a49e37856040518263ffffffff1660e01b815260040161383a91815260200190565b608060405180830381865afa158015613857573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061387b9190614d57565b6001600160a01b0381166000908152600b60209081526040918290208251606081018452905463ffffffff808216835264010000000082041692820192909252600160401b90910462ffffff16918101919091529396509194509092506138e49050838c6149fd565b9a5060018c036139185761390783826000015163ffffffff16633b9aca006135b0565b613911908b6149fd565b9950613974565b61393183826020015163ffffffff16633b9aca006135b0565b61393b908b6149fd565b995060028c14801561394b575083155b15613969576040516313cbf65960e01b815260040160405180910390fd5b8c8503613974578298505b50505050508061398390614b83565b90506137be565b50505093509350939050565b6000828152600c60205260408120805490915b81811015613a7d5760008382815481106139c5576139c5614b57565b9060005260206000200154905060106000828152602001908152602001600020600090557f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166323b872dd3087846040518463ffffffff1660e01b8152600401613a3993929190614aa5565b600060405180830381600087803b158015613a5357600080fd5b505af1158015613a67573d6000803e3d6000fd5b505050505080613a7690614b83565b90506139a9565b506000848152600c60205260408120611fb191614442565b6060600061221883613ec9565b6114ff8282613742565b600082815260208190526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6000612218836001600160a01b038416613f23565b613b1533610e37565b158015613b285750613b2633611d8b565b155b1561327857604051631dd2188d60e31b815260040160405180910390fd5b6000612218836001600160a01b038416613f72565b60006122188383614065565b6000613b748484846135b0565b905060008280613b8657613b86614b9c565b8486091115612218576000198110613b9d57600080fd5b6001019392505050565b60606122188383604051806060016040528060278152602001614ec56027913961408f565b6000610c95825490565b60006001600160e01b03198216637965db0b60e01b1480610c9557506301ffc9a760e01b6001600160e01b0319831614610c95565b6000806000846001600160a01b031684604051613c289190614da9565b6000604051808303816000865af19150503d8060008114613c65576040519150601f19603f3d011682016040523d82523d6000602084013e613c6a565b606091505b5091509150818015613c94575080511580613c94575080806020019051810190613c949190614ade565b8015613ca957506001600160a01b0385163b15155b95945050505050565b6000613d07826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166141079092919063ffffffff16565b9050805160001480613d28575080806020019051810190613d289190614ade565b6114175760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016114ec565b613d918282612275565b6114ff57613d9e81614116565b613da9836020614128565b604051602001613dba929190614dc5565b60408051601f198184030181529082905262461bcd60e51b82526114ec91600401614e3a565b613dea8282612275565b6114ff576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055613e203390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b613e6e8282612275565b156114ff576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b606081600001805480602002602001604051908101604052809291908181526020018280548015611a1357602002820191906000526020600020908154815260200190600101908083116119ff5750505050509050919050565b6000818152600183016020526040812054613f6a57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610c95565b506000610c95565b6000818152600183016020526040812054801561405b576000613f966001836149c7565b8554909150600090613faa906001906149c7565b905081811461400f576000866000018281548110613fca57613fca614b57565b9060005260206000200154905080876000018481548110613fed57613fed614b57565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061402057614020614b6d565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610c95565b6000915050610c95565b600082600001828154811061407c5761407c614b57565b9060005260206000200154905092915050565b6060600080856001600160a01b0316856040516140ac9190614da9565b600060405180830381855af49150503d80600081146140e7576040519150601f19603f3d011682016040523d82523d6000602084013e6140ec565b606091505b50915091506140fd868383876142c4565b9695505050505050565b6060610ef5848460008561433d565b6060610c956001600160a01b03831660145b606060006141378360026149de565b6141429060026149fd565b67ffffffffffffffff81111561415a5761415a614caa565b6040519080825280601f01601f191660200182016040528015614184576020820181803683370190505b509050600360fc1b8160008151811061419f5761419f614b57565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106141ce576141ce614b57565b60200101906001600160f81b031916908160001a90535060006141f28460026149de565b6141fd9060016149fd565b90505b6001811115614275576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061423157614231614b57565b1a60f81b82828151811061424757614247614b57565b60200101906001600160f81b031916908160001a90535060049490941c9361426e81614e4d565b9050614200565b5083156122185760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016114ec565b6060831561433357825160000361432c576001600160a01b0385163b61432c5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016114ec565b5081610ef5565b610ef58383614418565b60608247101561439e5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016114ec565b600080866001600160a01b031685876040516143ba9190614da9565b60006040518083038185875af1925050503d80600081146143f7576040519150601f19603f3d011682016040523d82523d6000602084013e6143fc565b606091505b509150915061440d878383876142c4565b979650505050505050565b8151156144285781518083602001fd5b8060405162461bcd60e51b81526004016114ec9190614e3a565b508054600082559060005260206000209081019061192c91905b80821115614470576000815560010161445c565b5090565b60006020828403121561448657600080fd5b81356001600160e01b03198116811461221857600080fd5b600060a082840312156144b057600080fd5b50919050565b6001600160a01b038116811461192c57600080fd5b6000806000806000608086880312156144e357600080fd5b85356144ee816144b6565b945060208601356144fe816144b6565b935060408601359250606086013567ffffffffffffffff8082111561452257600080fd5b818801915088601f83011261453657600080fd5b81358181111561454557600080fd5b89602082850101111561455757600080fd5b9699959850939650602001949392505050565b60006020828403121561457c57600080fd5b5035919050565b60006020828403121561459557600080fd5b8135612218816144b6565b600080604083850312156145b357600080fd5b50508035926020909101359150565b6000608082840312156144b057600080fd5b6000808284036101408112156145e957600080fd5b6145f385856145c2565b925060c0607f198201121561460757600080fd5b506080830190509250929050565b6000806040838503121561462857600080fd5b82359150602083013561463a816144b6565b809150509250929050565b60006020828403121561465757600080fd5b813560ff8116811461221857600080fd5b6020808252825182820181905260009190848201906040850190845b818110156146a95783516001600160a01b031683529284019291840191600101614684565b50909695505050505050565b63ffffffff8116811461192c57600080fd5b6000602082840312156146d957600080fd5b8135612218816146b5565b6020808252825182820181905260009190848201906040850190845b818110156146a957835183529284019291840191600101614700565b60008060006060848603121561473157600080fd5b833561473c816144b6565b95602085013595506040909401359392505050565b60008083601f84011261476357600080fd5b50813567ffffffffffffffff81111561477b57600080fd5b6020830191508360208260051b850101111561479657600080fd5b9250929050565b600080602083850312156147b057600080fd5b823567ffffffffffffffff8111156147c757600080fd5b6147d385828601614751565b90969095509350505050565b60008082840360808112156147f357600080fd5b83356147fe816144b6565b92506060601f198201121561481257600080fd5b506020830190509250929050565b60008060006060848603121561483557600080fd5b833592506020840135614847816144b6565b929592945050506040919091013590565b60005b8381101561487357818101518382015260200161485b565b83811115611fb15750506000910152565b6000815180845261489c816020860160208601614858565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561490557603f198886030184526148f3858351614884565b945092850192908501906001016148d7565b5092979650505050505050565b60006080828403121561492457600080fd5b61221883836145c2565b6001600160801b038116811461192c57600080fd5b8135815260a0810160208301356149598161492e565b6001600160801b03811660208401525060408301356040830152606083013560608301526080830135608083015292915050565b600080604083850312156149a057600080fd5b505080516020909101519092909150565b634e487b7160e01b600052601160045260246000fd5b6000828210156149d9576149d96149b1565b500390565b60008160001904831182151516156149f8576149f86149b1565b500290565b60008219821115614a1057614a106149b1565b500190565b81358152608081016020830135614a2b816144b6565b6001600160a01b031660208301526040830135614a478161492e565b6001600160801b039081166040840152606084013590614a668261492e565b8082166060850152505092915050565b60008060408385031215614a8957600080fd5b8251614a94816144b6565b602084015190925061463a816144b6565b6001600160a01b039384168152919092166020820152604081019190915260600190565b80518015158114614ad957600080fd5b919050565b600060208284031215614af057600080fd5b61221882614ac9565b600080600060608486031215614b0e57600080fd5b8351614b198161492e565b602085015160409095015190969495509392505050565b60018060a01b0384168152826020820152606060408201526000613ca96060830184614884565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b600060018201614b9557614b956149b1565b5060010190565b634e487b7160e01b600052601260045260246000fd5b600082614bcf57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215614be657600080fd5b5051919050565b62ffffff8116811461192c57600080fd5b8135614c09816146b5565b63ffffffff8116905081548163ffffffff1982161783556020840135614c2e816146b5565b67ffffffff000000008160201b169050808367ffffffffffffffff198416171784556040850135614c5e81614bed565b6affffff00000000000000008160401b16846affffffffffffffffffffff198516178317178555505050505050565b600060208284031215614c9f57600080fd5b813561221881614bed565b634e487b7160e01b600052604160045260246000fd5b6000808335601e19843603018112614cd757600080fd5b83018035915067ffffffffffffffff821115614cf257600080fd5b60200191503681900382131561479657600080fd5b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906140fd90830184614884565b600060208284031215614d4c57600080fd5b8151612218816144b6565b60008060008060808587031215614d6d57600080fd5b614d7685614ac9565b9350602085015192506040850151614d8d81614bed565b6060860151909250614d9e816144b6565b939692955090935050565b60008251614dbb818460208701614858565b9190910192915050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614dfd816017850160208801614858565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351614e2e816028840160208801614858565b01602801949350505050565b6020815260006122186020830184614884565b600081614e5c57614e5c6149b1565b50600019019056fec171260023d22a25a00a2789664c9334017843b831138c8ef03cc8897e5873d7f23ec0bb4210edd5cba85afd05127efcd2fc6a781bfed49188da1081670b22d846a52cf33029de9f84853745a87af28464c80bf0346df1b32e205fc73319f622416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220a251be3f9204c3433762905d58db3d60a91488b21846712dff9beaaeeac6063364736f6c634300080f0033

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

000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8800000000000000000000000031320bb77b26f0ce0e3febf089a5570b590add88000000000000000000000000904b6ebd837d9ee6330cf357f902172e9dfedfd5000000000000000000000000b0b195aefa3650a6908f15cdac7d92f8a5791b0b0000000000000000000000009032e988f5d46e0a21629e9effbb000cfbc28e2d0000000000000000000000008ae129b5b0beec40dc6c114b34a28b1efde49ee6

-----Decoded View---------------
Arg [0] : positionManager_ (address): 0xC36442b4a4522E871399CD717aBDD847Ab11FE88
Arg [1] : oracle_ (address): 0x31320bb77B26F0cE0E3febf089A5570B590add88
Arg [2] : treasury_ (address): 0x904B6EBd837d9ee6330CF357f902172e9DFEdFD5
Arg [3] : token_ (address): 0xB0B195aEFA3650A6908f15CdaC7D92F8a5791B0B
Arg [4] : minter_ (address): 0x9032e988F5d46e0a21629e9EFFbb000Cfbc28e2d
Arg [5] : vaultRegistry_ (address): 0x8aE129B5B0beEC40dc6c114B34A28B1EfdE49ee6

-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88
Arg [1] : 00000000000000000000000031320bb77b26f0ce0e3febf089a5570b590add88
Arg [2] : 000000000000000000000000904b6ebd837d9ee6330cf357f902172e9dfedfd5
Arg [3] : 000000000000000000000000b0b195aefa3650a6908f15cdac7d92f8a5791b0b
Arg [4] : 0000000000000000000000009032e988f5d46e0a21629e9effbb000cfbc28e2d
Arg [5] : 0000000000000000000000008ae129b5b0beec40dc6c114b34a28b1efde49ee6


Block Transaction Gas Used Reward
view all blocks produced

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

Validator Index Block Amount
View All Withdrawals

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

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