ETH Price: $3,896.06 (+0.31%)

Contract

0x6F2064837D82358AFF96E2dFe6AA8953123A0249
 

Overview

ETH Balance

0.293668491404599555 ETH

Eth Value

$1,144.15 (@ $3,896.06/ETH)

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Set Max Borrow P...213945562024-12-13 15:42:116 hrs ago1734104531IN
0x6F206483...3123A0249
0 ETH0.0010022121.60095836
Pay Back Loan213876172024-12-12 16:27:4729 hrs ago1734020867IN
0x6F206483...3123A0249
0.3 ETH0.0048976137.90755757
Set Max LTV Over...213801102024-12-11 15:18:232 days ago1733930303IN
0x6F206483...3123A0249
0 ETH0.0007856827.18821691
Toggle Whitelist...213801022024-12-11 15:16:472 days ago1733930207IN
0x6F206483...3123A0249
0 ETH0.0053348231.7307594
Toggle Whitelist...213800922024-12-11 15:14:472 days ago1733930087IN
0x6F206483...3123A0249
0 ETH0.0047459629.33536537
Toggle Whitelist...213800482024-12-11 15:05:472 days ago1733929547IN
0x6F206483...3123A0249
0 ETH0.0018890431.1271575
Withdraw213656112024-12-09 14:41:354 days ago1733755295IN
0x6F206483...3123A0249
0 ETH0.0143527738.16546541
Deposit And Borr...213404882024-12-06 2:31:237 days ago1733452283IN
0x6F206483...3123A0249
0 ETH0.0121623518.69069067
Pay Back Loan213095262024-12-01 18:43:1112 days ago1733078591IN
0x6F206483...3123A0249
1.2 ETH0.0028731219.64999986
Borrow212157672024-11-18 16:22:2325 days ago1731946943IN
0x6F206483...3123A0249
0 ETH0.0051355927.59813397
Borrow211917852024-11-15 8:04:5928 days ago1731657899IN
0x6F206483...3123A0249
0 ETH0.0037164515.92672863
Pay Back Loan211745342024-11-12 22:16:5930 days ago1731449819IN
0x6F206483...3123A0249
0.15 ETH0.0037869929.32362422
Withdraw211739642024-11-12 20:22:5931 days ago1731442979IN
0x6F206483...3123A0249
0 ETH0.0110077630.68048872
Pay Back Loan211739602024-11-12 20:22:1131 days ago1731442931IN
0x6F206483...3123A0249
1.6 ETH0.0040715931.52727636
Borrow211298502024-11-06 16:37:5937 days ago1730911079IN
0x6F206483...3123A0249
0 ETH0.0032986417.72539486
Deposit211298482024-11-06 16:37:3537 days ago1730911055IN
0x6F206483...3123A0249
0 ETH0.0044747517.45497127
Deposit211295262024-11-06 15:32:5937 days ago1730907179IN
0x6F206483...3123A0249
0 ETH0.0051244419.0094111
Borrow211145782024-11-04 13:27:2339 days ago1730726843IN
0x6F206483...3123A0249
0 ETH0.00116836.27158783
Pay Back Loan210903502024-11-01 4:17:1142 days ago1730434631IN
0x6F206483...3123A0249
0.15 ETH0.00077856.02629097
Pay Back Loan210902122024-11-01 3:49:3542 days ago1730432975IN
0x6F206483...3123A0249
0.1 ETH0.000955436.53131755
Borrow210727092024-10-29 17:12:5945 days ago1730221979IN
0x6F206483...3123A0249
0 ETH0.004562824.50105962
Deposit210727072024-10-29 17:12:3545 days ago1730221955IN
0x6F206483...3123A0249
0 ETH0.0079468925.41705222
Deposit And Borr...209280942024-10-09 12:40:4765 days ago1728477647IN
0x6F206483...3123A0249
0 ETH0.0169076820.29234275
Pay Back Loan An...208027392024-09-22 1:10:2382 days ago1726967423IN
0x6F206483...3123A0249
0.60022949 ETH0.001908747.33262904
Deposit206720352024-09-03 19:06:35101 days ago1725390395IN
0x6F206483...3123A0249
0 ETH0.000597171.84172188
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
213876172024-12-12 16:27:4729 hrs ago1734020867
0x6F206483...3123A0249
0.01169134 ETH
213404882024-12-06 2:31:237 days ago1733452283
0x6F206483...3123A0249
1.13912232 ETH
213404882024-12-06 2:31:237 days ago1733452283
0x6F206483...3123A0249
0.03523058 ETH
213095262024-12-01 18:43:1112 days ago1733078591
0x6F206483...3123A0249
0.02028725 ETH
212157672024-11-18 16:22:2325 days ago1731946943
0x6F206483...3123A0249
0.57970269 ETH
212157672024-11-18 16:22:2325 days ago1731946943
0x6F206483...3123A0249
0.0257827 ETH
211917852024-11-15 8:04:5928 days ago1731657899
0x6F206483...3123A0249
1.39458108 ETH
211917852024-11-15 8:04:5928 days ago1731657899
0x6F206483...3123A0249
0.10541891 ETH
211745342024-11-12 22:16:5930 days ago1731449819
0x6F206483...3123A0249
0.00192604 ETH
211739602024-11-12 20:22:1131 days ago1731442931
0x6F206483...3123A0249
0.01195699 ETH
211298502024-11-06 16:37:5937 days ago1730911079
0x6F206483...3123A0249
1.937598 ETH
211298502024-11-06 16:37:5937 days ago1730911079
0x6F206483...3123A0249
0.06240199 ETH
211145782024-11-04 13:27:2339 days ago1730726843
0x6F206483...3123A0249
1.02078674 ETH
211145782024-11-04 13:27:2339 days ago1730726843
0x6F206483...3123A0249
0.03576093 ETH
210903502024-11-01 4:17:1142 days ago1730434631
0x6F206483...3123A0249
0.00000429 ETH
210902122024-11-01 3:49:3542 days ago1730432975
0x6F206483...3123A0249
0.01511012 ETH
210727092024-10-29 17:12:5945 days ago1730221979
0x6F206483...3123A0249
1.06195987 ETH
210727092024-10-29 17:12:5945 days ago1730221979
0x6F206483...3123A0249
0.03804012 ETH
209280942024-10-09 12:40:4765 days ago1728477647
0x6F206483...3123A0249
0.59923737 ETH
209280942024-10-09 12:40:4765 days ago1728477647
0x6F206483...3123A0249
0.01853311 ETH
208027392024-09-22 1:10:2382 days ago1726967423
0x6F206483...3123A0249
0.00304235 ETH
208027392024-09-22 1:10:2382 days ago1726967423
0x6F206483...3123A0249
0.02759344 ETH
206720292024-09-03 19:05:23101 days ago1725390323
0x6F206483...3123A0249
0.00879554 ETH
206697812024-09-03 11:34:11101 days ago1725363251
0x6F206483...3123A0249
0.01623641 ETH
206071542024-08-25 17:40:35110 days ago1724607635
0x6F206483...3123A0249
0.00639729 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
LendingPool

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 42 : LendingPool.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
pragma abicoder v2;

import '@chainlink/contracts/src/v0.8/automation/interfaces/AutomationCompatibleInterface.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
import '@uniswap/v3-core/contracts/libraries/FixedPoint96.sol';
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import './LoanToken.sol';
import './LendingPoolTokenCustodian.sol';
import './LendingRewards.sol';
import './interfaces/IHyperbolicProtocol.sol';
import './interfaces/ITwapUtils.sol';
import './interfaces/IWETH.sol';

contract LendingPool is Ownable, AutomationCompatibleInterface {
  using SafeERC20 for ERC20;

  uint32 constant DENOMENATOR = 10000;
  uint256 Q96_2 = 2 ** (96 / 2);
  address immutable _WETH;

  bool public enabled;
  bool public liquidateDefaultCapital;
  uint32 public liquidateSlippage = (DENOMENATOR * 10) / 100; // 10%
  uint32 public maxLiquidationsPerUpkeep = 10;

  LendingPoolTokenCustodian public custodian;
  LoanToken public loanNFT;
  IHyperbolicProtocol _hype;
  LendingRewards _lendingRewards;
  ITwapUtils _twapUtils;
  ISwapRouter _swapRouter;

  mapping(address => bool) public whitelistPools;
  address[] _allWhitelistedPools;
  mapping(address => uint256) _allWhitelistPoolsInd;

  uint32 public borrowInitFee = (DENOMENATOR * 3) / 100; // 3%
  uint32 public borrowAPRMin = (DENOMENATOR * 2) / 100; // 2%
  uint32 public borrowAPRMax = (DENOMENATOR * 15) / 100; // 15%
  uint32 public liquidationLTV = (DENOMENATOR * 95) / 100; // 95%
  uint32 public maxLTVOverall = (DENOMENATOR * 50) / 100; // 50%
  // pool => LTV override
  mapping(address => uint32) public maxLTVOverride;
  // pool => current borrowed ETH
  mapping(address => uint256) public currentBorrowPerPool;
  // pool => borrow max
  mapping(address => uint256) public maxBorrowPerPool;

  struct Loan {
    uint256 created; // when the loan was first created
    address createdBy; // original wallet who created loan for lending rewards
    uint256 aprStart; // the starting timestamp we should evaluate APR fees from
    address collateralPool; // Uniswap V3 Pool of collateral token and ETH (WETH)
    uint256 amountDeposited; // amount of collateral token from collateralPool deposited
    uint256 amountETHBorrowed; // amount ETH borrowed, this and collateral deposited is used to determine LTV
  }
  // tokenId => Loan
  mapping(uint256 => Loan) public loans;

  event Deposit(
    address indexed wallet,
    uint256 indexed tokenId,
    uint256 amountCollateral
  );
  event Withdraw(
    address indexed wallet,
    uint256 indexed tokenId,
    uint256 amountCollateral
  );
  event Borrow(
    address indexed wallet,
    uint256 indexed tokenId,
    uint256 amountETH
  );
  event PayBackLoan(
    address indexed wallet,
    uint256 indexed tokenId,
    uint256 amountDesired,
    uint256 amountFees
  );
  event DeleteLoan(uint256 indexed tokenId);

  constructor(
    string memory _baseTokenURI,
    ISwapRouter __swapRouter,
    IHyperbolicProtocol __hype,
    ITwapUtils __twapUtils,
    LendingRewards __lendingRewards,
    address __WETH
  ) {
    _swapRouter = __swapRouter;
    _hype = __hype;
    _twapUtils = __twapUtils;
    _lendingRewards = __lendingRewards;
    _WETH = __WETH;

    custodian = new LendingPoolTokenCustodian(address(_hype));
    loanNFT = new LoanToken(_baseTokenURI);
    loanNFT.setRoyaltyAddress(msg.sender);
    loanNFT.transferOwnership(msg.sender);
  }

  function getLTVX96(
    uint256 _tokenId
  )
    public
    view
    returns (
      uint256 ltvX96,
      uint256 ltvWithFeesX96,
      uint256 amountETHDepositedX96,
      uint256 amountETHBorrowedX96
    )
  {
    require(loanNFT.doesTokenExist(_tokenId), 'GETLTV: loan must exist');
    Loan memory _loan = loans[_tokenId];
    uint256 _fees = calculateAPRFees(_loan.amountETHBorrowed, _loan.aprStart);
    if (_loan.amountDeposited == 0 && _loan.amountETHBorrowed == 0) {
      return (0, 0, 0, 0);
    }
    uint160 _sqrtPriceX96 = _twapUtils.getSqrtPriceX96FromPoolAndInterval(
      _loan.collateralPool
    );
    uint256 _priceX96 = _twapUtils.getPriceX96FromSqrtPriceX96(_sqrtPriceX96);
    address _token0 = IUniswapV3Pool(_loan.collateralPool).token0();
    uint256 _amountETHDepositedX96 = _token0 == _WETH
      ? _loan.amountDeposited * (FixedPoint96.Q96 ** 2 / _priceX96)
      : _priceX96 * _loan.amountDeposited;
    uint256 _amountETHBorrowedX96 = _loan.amountETHBorrowed * FixedPoint96.Q96;
    uint256 _amountETHBorrWithFeesX96 = (_loan.amountETHBorrowed + _fees) *
      FixedPoint96.Q96;
    return (
      ((_amountETHBorrowedX96 * Q96_2) / _amountETHDepositedX96) * Q96_2,
      ((_amountETHBorrWithFeesX96 * Q96_2) / _amountETHDepositedX96) * Q96_2,
      _amountETHDepositedX96,
      _amountETHBorrowedX96
    );
  }

  function getAllWhitelistedPools() external view returns (address[] memory) {
    return _allWhitelistedPools;
  }

  function getETHBalance(address _wallet) external view returns (uint256) {
    return address(_wallet).balance;
  }

  function depositAndBorrow(
    uint256 _tokenId,
    address _pool,
    uint256 _amountDepositing,
    uint256 _amountETHBorrowing
  ) external returns (uint256 tokenId) {
    _tokenId = _deposit(msg.sender, _tokenId, _pool, _amountDepositing);
    return _borrow(msg.sender, _tokenId, _amountETHBorrowing);
  }

  function deposit(uint256 _tokenId, address _pool, uint256 _amount) external {
    _deposit(msg.sender, _tokenId, _pool, _amount);
  }

  function borrow(
    uint256 _tokenId,
    uint256 _amountETHBorrowing
  ) external returns (uint256 tokenId) {
    return _borrow(msg.sender, _tokenId, _amountETHBorrowing);
  }

  function withdraw(uint256 _tokenId, uint256 _amount) external {
    _withdraw(msg.sender, _tokenId, _amount);
  }

  function payBackLoan(uint256 _tokenId) external payable {
    _payBackLoan(msg.sender, _tokenId, msg.value);
  }

  function payBackLoanAndClose(uint256 _tokenId) external payable {
    if (loans[_tokenId].amountETHBorrowed > 0) {
      _payBackLoan(msg.sender, _tokenId, msg.value);
    } else {
      require(msg.value == 0, 'PAYBACKLOSE: no ETH needed');
    }
    _withdraw(msg.sender, _tokenId, loans[_tokenId].amountDeposited);
  }

  function _deposit(
    address _wallet,
    uint256 _tokenId,
    address _pool,
    uint256 _amount
  ) internal returns (uint256) {
    require(enabled, 'DEPOSIT: not enabled');
    (uint256 __tokenId, ) = _getOrCreateLoan(_wallet, _tokenId);
    _tokenId = __tokenId;
    Loan storage _loan = loans[_tokenId];

    IUniswapV3Pool _uniPool;
    if (_loan.collateralPool == address(0)) {
      require(whitelistPools[_pool], 'DEPOSIT: bad pool0');
      _loan.created = block.timestamp;
      _loan.createdBy = _wallet;
      _loan.aprStart = block.timestamp;
      _loan.collateralPool = _pool;
      _uniPool = IUniswapV3Pool(_pool);
    } else {
      require(whitelistPools[_loan.collateralPool], 'DEPOSIT: bad pool1');
      _uniPool = IUniswapV3Pool(_loan.collateralPool);
    }
    _loan.amountDeposited += _amount;
    address _token0 = _uniPool.token0();
    if (_token0 == _WETH) {
      ERC20 _t1 = ERC20(_uniPool.token1());
      _t1.safeTransferFrom(_wallet, address(this), _amount);
      _t1.approve(address(custodian), _amount);
      custodian.process(_t1, _loan.createdBy, _amount, false);
    } else {
      ERC20 _t0 = ERC20(_token0);
      _t0.safeTransferFrom(_wallet, address(this), _amount);
      _t0.approve(address(custodian), _amount);
      custodian.process(_t0, _loan.createdBy, _amount, false);
    }
    emit Deposit(_wallet, _tokenId, _amount);
    return _tokenId;
  }

  function _withdraw(
    address _wallet,
    uint256 _tokenId,
    uint256 _amount
  ) internal {
    require(_amount > 0, 'WITHDRAW: must withdraw from loan');
    _validateLoanOwner(_wallet, _tokenId);

    Loan storage _loan = loans[_tokenId];
    require(_amount <= _loan.amountDeposited, 'WITHDRAW: too much');
    _loan.amountDeposited -= _amount;

    // get LTV info after we've removed _amount to withdraw from loan
    (, uint256 _ltvAndFeesX96, , ) = getLTVX96(_tokenId);
    if (maxLTVOverride[_loan.collateralPool] > 0) {
      require(
        _ltvAndFeesX96 <=
          (FixedPoint96.Q96 * maxLTVOverride[_loan.collateralPool]) /
            DENOMENATOR,
        'WITHDRAW: exceeds max LTV'
      );
    } else {
      require(
        _ltvAndFeesX96 <= (FixedPoint96.Q96 * maxLTVOverall) / DENOMENATOR,
        'WITHDRAW: exceeds max LTV'
      );
    }
    IUniswapV3Pool _uniPool = IUniswapV3Pool(_loan.collateralPool);
    address _token0 = _uniPool.token0();
    if (_token0 == _WETH) {
      ERC20 _t1 = ERC20(_uniPool.token1());
      custodian.process(_t1, _loan.createdBy, _amount, true);
      _t1.safeTransfer(_wallet, _amount);
    } else {
      ERC20 _t0 = ERC20(_token0);
      custodian.process(_t0, _loan.createdBy, _amount, true);
      _t0.safeTransfer(_wallet, _amount);
    }
    if (_loan.amountDeposited == 0) {
      _deleteLoan(_tokenId);
    }
    emit Withdraw(_wallet, _tokenId, _amount);
  }

  function _borrow(
    address _wallet,
    uint256 _tokenId,
    uint256 _amountETH
  ) internal returns (uint256) {
    require(enabled, 'BORROW: not enabled');
    _validateLoanOwner(_wallet, _tokenId);

    Loan storage _loan = loans[_tokenId];
    require(whitelistPools[_loan.collateralPool], 'BORROW: bad pool');

    // take out current APR fees from amount borrowing
    uint256 _amountAPRFees = calculateAPRFees(
      _loan.amountETHBorrowed,
      _loan.aprStart
    );
    _loan.aprStart = block.timestamp;
    (, , uint256 ethDepositedX96, uint256 ethBorrowedX96) = getLTVX96(_tokenId);
    uint256 ethDeposited = ethDepositedX96 / FixedPoint96.Q96;
    uint256 ethBorrowed = ethBorrowedX96 / FixedPoint96.Q96;

    uint256 _maxLoanETH = maxLTVOverride[_loan.collateralPool] > 0
      ? (ethDeposited * maxLTVOverride[_loan.collateralPool]) / DENOMENATOR
      : (ethDeposited * maxLTVOverall) / DENOMENATOR;
    require(ethBorrowed < _maxLoanETH, 'BORROW: cannot borrow');
    if (ethBorrowed + _amountETH > _maxLoanETH) {
      _amountETH = _maxLoanETH - ethBorrowed;
    }
    require(address(this).balance >= _amountETH, 'BORROW: not enough funds');

    if (maxBorrowPerPool[_loan.collateralPool] > 0) {
      require(
        currentBorrowPerPool[_loan.collateralPool] + _amountETH <=
          maxBorrowPerPool[_loan.collateralPool],
        'BORROW: exceeds pool max'
      );
    }
    currentBorrowPerPool[_loan.collateralPool] += _amountETH;
    _loan.amountETHBorrowed += _amountETH;
    uint256 _amountFees = _amountAPRFees +
      ((_amountETH * borrowInitFee) / DENOMENATOR);
    require(_amountETH > _amountFees, 'BORROW: fees more than borrow amount');

    uint256 _amountToBorrower = _amountETH - _amountFees;
    _depositRewards(_amountFees);
    (bool success, ) = payable(_wallet).call{ value: _amountToBorrower }('');
    require(success, 'BORROW: ETH not delivered');

    emit Borrow(_wallet, _tokenId, _amountETH);
    return _tokenId;
  }

  function _payBackLoan(
    address _wallet,
    uint256 _tokenId,
    uint256 _amount
  ) internal {
    require(_amount > 0, 'PAYBACK: no ETH to pay back');
    _validateLoanOwner(_wallet, _tokenId);

    Loan storage _loan = loans[_tokenId];
    // take out current APR fees from amount borrowing
    uint256 _amountAPRFees = calculateAPRFees(
      _loan.amountETHBorrowed,
      _loan.aprStart
    );
    _loan.aprStart = block.timestamp;
    require(_amount > _amountAPRFees, 'PAYBACK: must pay back above fees');
    uint256 _amountBorrowedPlusFees = _loan.amountETHBorrowed + _amountAPRFees;

    uint256 _refund;
    if (_amount > _amountBorrowedPlusFees) {
      _refund = _amount - _amountBorrowedPlusFees;
    }

    // remove amount minus fees from the amount borrowed
    currentBorrowPerPool[_loan.collateralPool] -= (_amount - _amountAPRFees) >
      currentBorrowPerPool[_loan.collateralPool]
      ? currentBorrowPerPool[_loan.collateralPool]
      : _amount - _amountAPRFees;
    _loan.amountETHBorrowed -= (_amount - _amountAPRFees) >
      _loan.amountETHBorrowed
      ? _loan.amountETHBorrowed
      : _amount - _amountAPRFees;

    if (_amountAPRFees > 0) {
      _depositRewards(_amountAPRFees);
    }
    if (_refund > 0) {
      (bool wasRefunded, ) = payable(_wallet).call{ value: _refund }('');
      require(wasRefunded, 'PAYBACK: refund unsuccessful');
    }
    emit PayBackLoan(_wallet, _tokenId, _amount, _amountAPRFees);
  }

  function _getOrCreateLoan(
    address _wallet,
    uint256 _tokenId
  ) internal returns (uint256 tokenId, bool isNewLoan) {
    if (_tokenId == 0) {
      tokenId = loanNFT.mint(_wallet);
      return (tokenId, true);
    }
    _validateLoanOwner(_wallet, _tokenId);
    tokenId = _tokenId;
    return (tokenId, false);
  }

  function _deleteLoan(uint256 _tokenId) internal {
    delete loans[_tokenId];
    loanNFT.burn(_tokenId);
    emit DeleteLoan(_tokenId);
  }

  function _depositRewards(uint256 _amount) internal virtual {
    _lendingRewards.depositRewards{ value: _amount }();
  }

  function calculateAPRFees(
    uint256 _amountETHBorrowed,
    uint256 _aprStart
  ) public view returns (uint256) {
    return
      ((block.timestamp - _aprStart) *
        calculateBorrowAPR() *
        _amountETHBorrowed) /
      DENOMENATOR /
      365 days;
  }

  function calculateBorrowAPR() public view returns (uint256) {
    (uint256 _poolBalETH, uint256 _mcETH) = _hype.poolBalToMarketCapRatio();
    uint256 _targetPoolBal = (_mcETH * _hype.poolToMarketCapTarget()) /
      DENOMENATOR;
    if (_poolBalETH < _targetPoolBal) {
      uint256 _aprLessMax = ((borrowAPRMax - borrowAPRMin) * _poolBalETH) /
        _targetPoolBal;
      return borrowAPRMax - _aprLessMax;
    }
    return borrowAPRMin;
  }

  function shouldLiquidateLoan(uint256 _tokenId) external view returns (bool) {
    return _shouldLiquidateLoan(_tokenId);
  }

  function _shouldLiquidateLoan(uint256 _tokenId) internal view returns (bool) {
    if (!loanNFT.doesTokenExist(_tokenId)) {
      return false;
    }
    (, uint256 _ltvWithFeesX96, , ) = getLTVX96(_tokenId);
    return _ltvWithFeesX96 >= (FixedPoint96.Q96 * liquidationLTV) / DENOMENATOR;
  }

  function _toggleWhitelistCollateralPool(address _pool) internal {
    if (whitelistPools[_pool]) {
      uint256 _ind = _allWhitelistPoolsInd[_pool];
      address _poolMoving = _allWhitelistedPools[
        _allWhitelistedPools.length - 1
      ];
      _allWhitelistedPools[_ind] = _poolMoving;
      _allWhitelistPoolsInd[_poolMoving] = _ind;
      delete whitelistPools[_pool];
      _allWhitelistedPools.pop();
    } else {
      // add
      whitelistPools[_pool] = true;
      _allWhitelistPoolsInd[_pool] = _allWhitelistedPools.length;
      _allWhitelistedPools.push(_pool);
    }
  }

  function checkUpkeep(
    bytes calldata
  )
    external
    view
    override
    returns (bool upkeepNeeded, bytes memory performData)
  {
    uint256[] memory _openedLoans = loanNFT.getAllOpenedLoans();
    uint256[] memory _upkeepLoans = new uint256[](maxLiquidationsPerUpkeep);
    uint32 _numUpkeeps = 0;
    for (uint256 _i = 0; _i < _openedLoans.length; _i++) {
      if (_numUpkeeps >= maxLiquidationsPerUpkeep) {
        break;
      }
      uint256 _tokenId = _openedLoans[_i];
      if (_shouldLiquidateLoan(_tokenId)) {
        upkeepNeeded = true;
        _upkeepLoans[_numUpkeeps] = _tokenId;
        _numUpkeeps++;
      }
    }

    if (upkeepNeeded) {
      performData = abi.encode(_upkeepLoans);
    }
  }

  function performUpkeep(bytes calldata performData) external override {
    uint256[] memory _upkeepLoans = abi.decode(performData, (uint256[]));
    for (uint256 _i = 0; _i < _upkeepLoans.length; _i++) {
      uint256 _tokenId = _upkeepLoans[_i];
      if (_tokenId == 0) {
        break;
      }
      if (_shouldLiquidateLoan(_tokenId)) {
        Loan memory _loan = loans[_tokenId];
        uint256 _amountDeposited = _loan.amountDeposited;
        IUniswapV3Pool _pool = IUniswapV3Pool(_loan.collateralPool);
        address _token0 = _pool.token0();
        if (_token0 == _WETH) {
          ERC20 _t1 = ERC20(_pool.token1());
          custodian.process(_t1, _loan.createdBy, _amountDeposited, true);
          _processLiquidatedTokens(_pool, _t1, _loan);
        } else {
          ERC20 _t0 = ERC20(_token0);
          custodian.process(_t0, _loan.createdBy, _amountDeposited, true);
          _processLiquidatedTokens(_pool, _t0, _loan);
        }
        _deleteLoan(_tokenId);
      }
    }
  }

  function _processLiquidatedTokens(
    IUniswapV3Pool _pool,
    ERC20 _token,
    Loan memory _loan
  ) internal {
    if (liquidateDefaultCapital && address(_token) != address(_hype)) {
      uint160 _sqrtPriceX96 = _twapUtils.getSqrtPriceX96FromPoolAndInterval(
        address(_pool)
      );
      uint256 _priceX96 = _twapUtils.getPriceX96FromSqrtPriceX96(_sqrtPriceX96);
      uint256 _priceWETHNumX96 = _pool.token1() == _WETH
        ? _priceX96
        : FixedPoint96.Q96 ** 2 / _priceX96;
      uint256 _minETHBaseFromPrice = (_priceWETHNumX96 *
        _loan.amountDeposited) / FixedPoint96.Q96;
      uint256 _minETHBase = _minETHBaseFromPrice > _loan.amountETHBorrowed
        ? _minETHBaseFromPrice
        : _loan.amountETHBorrowed;

      TransferHelper.safeApprove(
        address(_token),
        address(_swapRouter),
        _loan.amountDeposited
      );
      _swapRouter.exactInputSingle(
        ISwapRouter.ExactInputSingleParams({
          tokenIn: address(_token),
          tokenOut: _WETH,
          fee: _pool.fee(),
          recipient: address(this),
          deadline: block.timestamp,
          amountIn: _loan.amountDeposited,
          amountOutMinimum: (_minETHBase * (DENOMENATOR - liquidateSlippage)) /
            DENOMENATOR,
          sqrtPriceLimitX96: 0
        })
      );
      uint256 _balWETH = IERC20(_WETH).balanceOf(address(this));
      if (_balWETH > 0) {
        IWETH(_WETH).withdraw(_balWETH);
      }
    } else {
      _token.safeTransfer(owner(), _loan.amountDeposited);
    }
  }

  function _validateLoanOwner(address _wallet, uint256 _tokenId) internal view {
    require(_wallet == loanNFT.ownerOf(_tokenId), 'VALIDATEOWNER');
  }

  function setLiquidateDefaultCapital(bool _shouldLiq) external onlyOwner {
    require(liquidateDefaultCapital != _shouldLiq, 'SETLIQDEF');
    liquidateDefaultCapital = _shouldLiq;
  }

  function setLiquidateSlippage(uint32 _slippage) external onlyOwner {
    require(_slippage <= DENOMENATOR, 'lte 100%');
    liquidateSlippage = _slippage;
  }

  function setBorrowInitFee(uint32 _fee) external onlyOwner {
    require(_fee <= (DENOMENATOR * 30) / 100, 'SETBFEE: lte 30%');
    borrowInitFee = _fee;
  }

  function setBorrowAPRMin(uint32 _apr) external onlyOwner {
    require(_apr <= (DENOMENATOR * 10) / 100, 'SETBAPRMIN: lte 10%');
    borrowAPRMin = _apr;
  }

  function setBorrowAPRMax(uint32 _apr) external onlyOwner {
    require(_apr <= DENOMENATOR, 'SETBAPRMAX: lte 100%');
    borrowAPRMax = _apr;
  }

  function setMaxLTVOverall(uint32 _ltv) external onlyOwner {
    require(_ltv <= DENOMENATOR, 'SETLTVMAX: lte 100%');
    maxLTVOverall = _ltv;
  }

  function setMaxLTVOverride(address _pool, uint32 _ltv) external onlyOwner {
    require(_ltv <= DENOMENATOR, 'SETLTVMAX: lte 100%');
    maxLTVOverride[_pool] = _ltv;
  }

  function setMaxBorrowPerPool(
    address _pool,
    uint256 _amountETH
  ) external onlyOwner {
    maxBorrowPerPool[_pool] = _amountETH;
  }

  function setLiquidationLTV(uint32 _ltv) external onlyOwner {
    require(_ltv <= DENOMENATOR, 'SETLPLTV: lte 100%');
    liquidationLTV = _ltv;
  }

  function setMaxLiquidationsPerUpkeep(uint32 _max) external onlyOwner {
    maxLiquidationsPerUpkeep = _max;
  }

  function setEnabled(bool _enabled) external onlyOwner {
    require(enabled != _enabled, 'SETENABLED: must toggle');
    enabled = _enabled;
  }

  function toggleWhitelistCollateralPool(address _pool) external onlyOwner {
    IUniswapV3Pool _uniPool = IUniswapV3Pool(_pool);
    address _token0 = _uniPool.token0();
    address _token1 = _uniPool.token1();
    require(_token0 == _WETH || _token1 == _WETH, 'TOGGLECOLL: no ETH');

    uint32[] memory secondsAgo = new uint32[](2);
    secondsAgo[0] = 5 minutes;
    secondsAgo[1] = 0;
    _uniPool.observe(secondsAgo);

    _toggleWhitelistCollateralPool(_pool);
  }

  receive() external payable {}
}

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

interface AutomationCompatibleInterface {
  /**
   * @notice method that is simulated by the keepers to see if any work actually
   * needs to be performed. This method does does not actually need to be
   * executable, and since it is only ever simulated it can consume lots of gas.
   * @dev To ensure that it is never called, you may want to add the
   * cannotExecute modifier from KeeperBase to your implementation of this
   * method.
   * @param checkData specified in the upkeep registration so it is always the
   * same for a registered upkeep. This can easily be broken down into specific
   * arguments using `abi.decode`, so multiple upkeeps can be registered on the
   * same contract and easily differentiated by the contract.
   * @return upkeepNeeded boolean to indicate whether the keeper should call
   * performUpkeep or not.
   * @return performData bytes that the keeper should call performUpkeep with, if
   * upkeep is needed. If you would like to encode data to decode later, try
   * `abi.encode`.
   */
  function checkUpkeep(bytes calldata checkData) external returns (bool upkeepNeeded, bytes memory performData);

  /**
   * @notice method that is actually executed by the keepers, via the registry.
   * The data returned by the checkUpkeep simulation will be passed into
   * this method to actually be executed.
   * @dev The input to this method should not be trusted, and the caller of the
   * method should not even be restricted to any single registry. Anyone should
   * be able call it, and the input should be validated, there is no guarantee
   * that the data passed in is the performData returned from checkUpkeep. This
   * could happen due to malicious keepers, racing keepers, or simply a state
   * change while the performUpkeep transaction is waiting for confirmation.
   * Always validate the data passed in.
   * @param performData is the data which was passed back from the checkData
   * simulation. If it is encoded, it can easily be decoded into other types by
   * calling `abi.decode`. This data should not be trusted, and should be
   * validated against the contract's current state.
   */
  function performUpkeep(bytes calldata performData) external;
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

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

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

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

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

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

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

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

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

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(address from, address to, uint256 amount) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}

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

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        _approve(to, tokenId);
    }

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

        return _tokenApprovals[tokenId];
    }

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

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

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

        _transfer(from, to, tokenId);
    }

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

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

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * `data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
    }

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

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

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

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

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

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

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

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

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

        _owners[tokenId] = to;

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

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

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

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

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

        // Clear approvals
        delete _tokenApprovals[tokenId];

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

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

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

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

        _beforeTokenTransfer(from, to, tokenId, 1);

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

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

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

        emit Transfer(from, to, tokenId);

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

        uint256 tokenId = firstTokenId;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "../IERC721.sol";

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

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

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

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

pragma solidity ^0.8.0;

import "../IERC721.sol";

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}

File 18 of 42 : 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 19 of 42 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

import './pool/IUniswapV3PoolImmutables.sol';
import './pool/IUniswapV3PoolState.sol';
import './pool/IUniswapV3PoolDerivedState.sol';
import './pool/IUniswapV3PoolActions.sol';
import './pool/IUniswapV3PoolOwnerActions.sol';
import './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,
    IUniswapV3PoolEvents
{

}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
    /// when accessed externally.
    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
    /// 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.
    /// observationIndex The index of the last oracle observation that was written,
    /// observationCardinality The current maximum number of observations stored in the pool,
    /// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
    /// 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
    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,
    /// liquidityNet how much liquidity changes when the pool price crosses the tick,
    /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
    /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
    /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
    /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
    /// secondsOutside the seconds spent on the other side of the tick from the current tick,
    /// 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,
    /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
    /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
    /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
    /// Returns 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,
    /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
    /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
    /// Returns 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 31 of 42 : FixedPoint96.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;

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

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

import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}

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

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

library TransferHelper {
    /// @notice Transfers tokens from the targeted address to the given destination
    /// @notice Errors with 'STF' if transfer fails
    /// @param token The contract address of the token to be transferred
    /// @param from The originating address from which the tokens will be transferred
    /// @param to The destination address of the transfer
    /// @param value The amount to be transferred
    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) =
            token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
    }

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

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

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

File 34 of 42 : IHyperbolicProtocol.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface IHyperbolicProtocol {
  function poolBalToMarketCapRatio()
    external
    view
    returns (uint256 lendPoolETHBal, uint256 marketCapETH);

  function poolToMarketCapTarget() external view returns (uint32);
}

File 35 of 42 : IRewardsTracker.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface IRewardsTracker {
  function claimReward() external;

  function depositRewards() external payable;

  function getShares(address wallet) external view returns (uint256);

  function setShare(
    address shareholder,
    uint256 balanceUpdate,
    bool isRemoving
  ) external;
}

File 36 of 42 : ITwapUtils.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface ITwapUtils {
  function twapInterval() external view returns (uint32);

  function getPoolPriceUSDX96(
    address priceToken,
    address pricePool,
    address nativeStablePool,
    address WETH9,
    bool isPoolPairedWETH9
  ) external view returns (uint256);

  function getSqrtPriceX96FromPoolAndInterval(
    address uniswapV3Pool
  ) external view returns (uint160 sqrtPriceX96);

  function getSqrtPriceX96FromPriceX96(
    uint256 priceX96
  ) external pure returns (uint160 sqrtPriceX96);

  function getPriceX96FromSqrtPriceX96(
    uint160 sqrtPriceX96
  ) external pure returns (uint256 priceX96);
}

File 37 of 42 : IWETH.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface IWETH {
  function balanceOf(address wallet) external view returns (uint256);

  function decimals() external view returns (uint8);

  function deposit() external payable;

  function withdraw(uint256 _amount) external;
}

File 38 of 42 : LendingPoolTokenCustodian.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import './RewardsTracker.sol';

contract LendingPoolTokenCustodian is Ownable, RewardsTracker {
  using SafeERC20 for IERC20;

  address public hype;

  constructor(address _hype) RewardsTracker(_hype) {
    hype = _hype;
  }

  function process(
    IERC20 _token,
    address _user,
    uint256 _balanceUpdate,
    bool _isWithdrawing
  ) external onlyOwner {
    if (_isWithdrawing) {
      _token.safeTransfer(msg.sender, _balanceUpdate);
    } else {
      _token.safeTransferFrom(msg.sender, address(this), _balanceUpdate);
    }
    if (address(_token) == hype) {
      _setShare(_user, _balanceUpdate, _isWithdrawing);
    }
  }

  receive() external payable {
    uint256 _hypeTokens = IERC20(hype).balanceOf(address(this));
    if (_hypeTokens > 0) {
      _depositRewards(msg.value);
    } else {
      (bool _success, ) = payable(owner()).call{ value: msg.value }('');
      require(_success, 'RECEIVE: did not send to owner');
    }
  }
}

File 39 of 42 : LendingRewards.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import './RewardsTracker.sol';

contract LendingRewards is RewardsTracker {
  constructor(address _token) RewardsTracker(_token) {}
}

File 40 of 42 : BokkyPooBahsDateTimeLibrary.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

// ----------------------------------------------------------------------------
// BokkyPooBah's DateTime Library v1.00
//
// A gas-efficient Solidity date and time library
//
// https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary
//
// Tested date range 1970/01/01 to 2345/12/31
//
// Conventions:
// Unit      | Range         | Notes
// :-------- |:-------------:|:-----
// timestamp | >= 0          | Unix timestamp, number of seconds since 1970/01/01 00:00:00 UTC
// year      | 1970 ... 2345 |
// month     | 1 ... 12      |
// day       | 1 ... 31      |
// hour      | 0 ... 23      |
// minute    | 0 ... 59      |
// second    | 0 ... 59      |
// dayOfWeek | 1 ... 7       | 1 = Monday, ..., 7 = Sunday
//
//
// Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2018.
//
// GNU Lesser General Public License 3.0
// https://www.gnu.org/licenses/lgpl-3.0.en.html
// ----------------------------------------------------------------------------

library BokkyPooBahsDateTimeLibrary {
  uint constant SECONDS_PER_DAY = 24 * 60 * 60;
  uint constant SECONDS_PER_HOUR = 60 * 60;
  uint constant SECONDS_PER_MINUTE = 60;
  int constant OFFSET19700101 = 2440588;

  uint constant DOW_MON = 1;
  uint constant DOW_TUE = 2;
  uint constant DOW_WED = 3;
  uint constant DOW_THU = 4;
  uint constant DOW_FRI = 5;
  uint constant DOW_SAT = 6;
  uint constant DOW_SUN = 7;

  // ------------------------------------------------------------------------
  // Calculate the number of days from 1970/01/01 to year/month/day using
  // the date conversion algorithm from
  //   http://aa.usno.navy.mil/faq/docs/JD_Formula.php
  // and subtracting the offset 2440588 so that 1970/01/01 is day 0
  //
  // days = day
  //      - 32075
  //      + 1461 * (year + 4800 + (month - 14) / 12) / 4
  //      + 367 * (month - 2 - (month - 14) / 12 * 12) / 12
  //      - 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4
  //      - offset
  // ------------------------------------------------------------------------
  function _daysFromDate(
    uint year,
    uint month,
    uint day
  ) internal pure returns (uint _days) {
    require(year >= 1970);
    int _year = int(year);
    int _month = int(month);
    int _day = int(day);

    int __days = _day -
      32075 +
      (1461 * (_year + 4800 + (_month - 14) / 12)) /
      4 +
      (367 * (_month - 2 - ((_month - 14) / 12) * 12)) /
      12 -
      (3 * ((_year + 4900 + (_month - 14) / 12) / 100)) /
      4 -
      OFFSET19700101;

    _days = uint(__days);
  }

  // ------------------------------------------------------------------------
  // Calculate year/month/day from the number of days since 1970/01/01 using
  // the date conversion algorithm from
  //   http://aa.usno.navy.mil/faq/docs/JD_Formula.php
  // and adding the offset 2440588 so that 1970/01/01 is day 0
  //
  // int L = days + 68569 + offset
  // int N = 4 * L / 146097
  // L = L - (146097 * N + 3) / 4
  // year = 4000 * (L + 1) / 1461001
  // L = L - 1461 * year / 4 + 31
  // month = 80 * L / 2447
  // dd = L - 2447 * month / 80
  // L = month / 11
  // month = month + 2 - 12 * L
  // year = 100 * (N - 49) + year + L
  // ------------------------------------------------------------------------
  function _daysToDate(
    uint _days
  ) internal pure returns (uint year, uint month, uint day) {
    int __days = int(_days);

    int L = __days + 68569 + OFFSET19700101;
    int N = (4 * L) / 146097;
    L = L - (146097 * N + 3) / 4;
    int _year = (4000 * (L + 1)) / 1461001;
    L = L - (1461 * _year) / 4 + 31;
    int _month = (80 * L) / 2447;
    int _day = L - (2447 * _month) / 80;
    L = _month / 11;
    _month = _month + 2 - 12 * L;
    _year = 100 * (N - 49) + _year + L;

    year = uint(_year);
    month = uint(_month);
    day = uint(_day);
  }

  function timestampFromDate(
    uint year,
    uint month,
    uint day
  ) internal pure returns (uint timestamp) {
    timestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY;
  }

  function timestampFromDateTime(
    uint year,
    uint month,
    uint day,
    uint hour,
    uint minute,
    uint second
  ) internal pure returns (uint timestamp) {
    timestamp =
      _daysFromDate(year, month, day) *
      SECONDS_PER_DAY +
      hour *
      SECONDS_PER_HOUR +
      minute *
      SECONDS_PER_MINUTE +
      second;
  }

  function timestampToDate(
    uint timestamp
  ) internal pure returns (uint year, uint month, uint day) {
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
  }

  function timestampToDateTime(
    uint timestamp
  )
    internal
    pure
    returns (
      uint year,
      uint month,
      uint day,
      uint hour,
      uint minute,
      uint second
    )
  {
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
    uint secs = timestamp % SECONDS_PER_DAY;
    hour = secs / SECONDS_PER_HOUR;
    secs = secs % SECONDS_PER_HOUR;
    minute = secs / SECONDS_PER_MINUTE;
    second = secs % SECONDS_PER_MINUTE;
  }

  function isValidDate(
    uint year,
    uint month,
    uint day
  ) internal pure returns (bool valid) {
    if (year >= 1970 && month > 0 && month <= 12) {
      uint daysInMonth = _getDaysInMonth(year, month);
      if (day > 0 && day <= daysInMonth) {
        valid = true;
      }
    }
  }

  function isValidDateTime(
    uint year,
    uint month,
    uint day,
    uint hour,
    uint minute,
    uint second
  ) internal pure returns (bool valid) {
    if (isValidDate(year, month, day)) {
      if (hour < 24 && minute < 60 && second < 60) {
        valid = true;
      }
    }
  }

  function isLeapYear(uint timestamp) internal pure returns (bool leapYear) {
    uint year;
    uint month;
    uint day;
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
    leapYear = _isLeapYear(year);
  }

  function _isLeapYear(uint year) internal pure returns (bool leapYear) {
    leapYear = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
  }

  function isWeekDay(uint timestamp) internal pure returns (bool weekDay) {
    weekDay = getDayOfWeek(timestamp) <= DOW_FRI;
  }

  function isWeekEnd(uint timestamp) internal pure returns (bool weekEnd) {
    weekEnd = getDayOfWeek(timestamp) >= DOW_SAT;
  }

  function getDaysInMonth(
    uint timestamp
  ) internal pure returns (uint daysInMonth) {
    uint year;
    uint month;
    uint day;
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
    daysInMonth = _getDaysInMonth(year, month);
  }

  function _getDaysInMonth(
    uint year,
    uint month
  ) internal pure returns (uint daysInMonth) {
    if (
      month == 1 ||
      month == 3 ||
      month == 5 ||
      month == 7 ||
      month == 8 ||
      month == 10 ||
      month == 12
    ) {
      daysInMonth = 31;
    } else if (month != 2) {
      daysInMonth = 30;
    } else {
      daysInMonth = _isLeapYear(year) ? 29 : 28;
    }
  }

  // 1 = Monday, 7 = Sunday
  function getDayOfWeek(uint timestamp) internal pure returns (uint dayOfWeek) {
    uint _days = timestamp / SECONDS_PER_DAY;
    dayOfWeek = ((_days + 3) % 7) + 1;
  }

  function getYear(uint timestamp) internal pure returns (uint year) {
    uint month;
    uint day;
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
  }

  function getMonth(uint timestamp) internal pure returns (uint month) {
    uint year;
    uint day;
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
  }

  function getDay(uint timestamp) internal pure returns (uint day) {
    uint year;
    uint month;
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
  }

  function getHour(uint timestamp) internal pure returns (uint hour) {
    uint secs = timestamp % SECONDS_PER_DAY;
    hour = secs / SECONDS_PER_HOUR;
  }

  function getMinute(uint timestamp) internal pure returns (uint minute) {
    uint secs = timestamp % SECONDS_PER_HOUR;
    minute = secs / SECONDS_PER_MINUTE;
  }

  function getSecond(uint timestamp) internal pure returns (uint second) {
    second = timestamp % SECONDS_PER_MINUTE;
  }

  function addYears(
    uint timestamp,
    uint _years
  ) internal pure returns (uint newTimestamp) {
    uint year;
    uint month;
    uint day;
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
    year += _years;
    uint daysInMonth = _getDaysInMonth(year, month);
    if (day > daysInMonth) {
      day = daysInMonth;
    }
    newTimestamp =
      _daysFromDate(year, month, day) *
      SECONDS_PER_DAY +
      (timestamp % SECONDS_PER_DAY);
    require(newTimestamp >= timestamp);
  }

  function addMonths(
    uint timestamp,
    uint _months
  ) internal pure returns (uint newTimestamp) {
    uint year;
    uint month;
    uint day;
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
    month += _months;
    year += (month - 1) / 12;
    month = ((month - 1) % 12) + 1;
    uint daysInMonth = _getDaysInMonth(year, month);
    if (day > daysInMonth) {
      day = daysInMonth;
    }
    newTimestamp =
      _daysFromDate(year, month, day) *
      SECONDS_PER_DAY +
      (timestamp % SECONDS_PER_DAY);
    require(newTimestamp >= timestamp);
  }

  function addDays(
    uint timestamp,
    uint _days
  ) internal pure returns (uint newTimestamp) {
    newTimestamp = timestamp + _days * SECONDS_PER_DAY;
    require(newTimestamp >= timestamp);
  }

  function addHours(
    uint timestamp,
    uint _hours
  ) internal pure returns (uint newTimestamp) {
    newTimestamp = timestamp + _hours * SECONDS_PER_HOUR;
    require(newTimestamp >= timestamp);
  }

  function addMinutes(
    uint timestamp,
    uint _minutes
  ) internal pure returns (uint newTimestamp) {
    newTimestamp = timestamp + _minutes * SECONDS_PER_MINUTE;
    require(newTimestamp >= timestamp);
  }

  function addSeconds(
    uint timestamp,
    uint _seconds
  ) internal pure returns (uint newTimestamp) {
    newTimestamp = timestamp + _seconds;
    require(newTimestamp >= timestamp);
  }

  function subYears(
    uint timestamp,
    uint _years
  ) internal pure returns (uint newTimestamp) {
    uint year;
    uint month;
    uint day;
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
    year -= _years;
    uint daysInMonth = _getDaysInMonth(year, month);
    if (day > daysInMonth) {
      day = daysInMonth;
    }
    newTimestamp =
      _daysFromDate(year, month, day) *
      SECONDS_PER_DAY +
      (timestamp % SECONDS_PER_DAY);
    require(newTimestamp <= timestamp);
  }

  function subMonths(
    uint timestamp,
    uint _months
  ) internal pure returns (uint newTimestamp) {
    uint year;
    uint month;
    uint day;
    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
    uint yearMonth = year * 12 + (month - 1) - _months;
    year = yearMonth / 12;
    month = (yearMonth % 12) + 1;
    uint daysInMonth = _getDaysInMonth(year, month);
    if (day > daysInMonth) {
      day = daysInMonth;
    }
    newTimestamp =
      _daysFromDate(year, month, day) *
      SECONDS_PER_DAY +
      (timestamp % SECONDS_PER_DAY);
    require(newTimestamp <= timestamp);
  }

  function subDays(
    uint timestamp,
    uint _days
  ) internal pure returns (uint newTimestamp) {
    newTimestamp = timestamp - _days * SECONDS_PER_DAY;
    require(newTimestamp <= timestamp);
  }

  function subHours(
    uint timestamp,
    uint _hours
  ) internal pure returns (uint newTimestamp) {
    newTimestamp = timestamp - _hours * SECONDS_PER_HOUR;
    require(newTimestamp <= timestamp);
  }

  function subMinutes(
    uint timestamp,
    uint _minutes
  ) internal pure returns (uint newTimestamp) {
    newTimestamp = timestamp - _minutes * SECONDS_PER_MINUTE;
    require(newTimestamp <= timestamp);
  }

  function subSeconds(
    uint timestamp,
    uint _seconds
  ) internal pure returns (uint newTimestamp) {
    newTimestamp = timestamp - _seconds;
    require(newTimestamp <= timestamp);
  }

  function diffYears(
    uint fromTimestamp,
    uint toTimestamp
  ) internal pure returns (uint _years) {
    require(fromTimestamp <= toTimestamp);
    uint fromYear;
    uint fromMonth;
    uint fromDay;
    uint toYear;
    uint toMonth;
    uint toDay;
    (fromYear, fromMonth, fromDay) = _daysToDate(
      fromTimestamp / SECONDS_PER_DAY
    );
    (toYear, toMonth, toDay) = _daysToDate(toTimestamp / SECONDS_PER_DAY);
    _years = toYear - fromYear;
  }

  function diffMonths(
    uint fromTimestamp,
    uint toTimestamp
  ) internal pure returns (uint _months) {
    require(fromTimestamp <= toTimestamp);
    uint fromYear;
    uint fromMonth;
    uint fromDay;
    uint toYear;
    uint toMonth;
    uint toDay;
    (fromYear, fromMonth, fromDay) = _daysToDate(
      fromTimestamp / SECONDS_PER_DAY
    );
    (toYear, toMonth, toDay) = _daysToDate(toTimestamp / SECONDS_PER_DAY);
    _months = toYear * 12 + toMonth - fromYear * 12 - fromMonth;
  }

  function diffDays(
    uint fromTimestamp,
    uint toTimestamp
  ) internal pure returns (uint _days) {
    require(fromTimestamp <= toTimestamp);
    _days = (toTimestamp - fromTimestamp) / SECONDS_PER_DAY;
  }

  function diffHours(
    uint fromTimestamp,
    uint toTimestamp
  ) internal pure returns (uint _hours) {
    require(fromTimestamp <= toTimestamp);
    _hours = (toTimestamp - fromTimestamp) / SECONDS_PER_HOUR;
  }

  function diffMinutes(
    uint fromTimestamp,
    uint toTimestamp
  ) internal pure returns (uint _minutes) {
    require(fromTimestamp <= toTimestamp);
    _minutes = (toTimestamp - fromTimestamp) / SECONDS_PER_MINUTE;
  }

  function diffSeconds(
    uint fromTimestamp,
    uint toTimestamp
  ) internal pure returns (uint _seconds) {
    require(fromTimestamp <= toTimestamp);
    _seconds = toTimestamp - fromTimestamp;
  }
}

File 41 of 42 : LoanToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol';
import '@openzeppelin/contracts/utils/Counters.sol';

contract LoanToken is ERC721Enumerable, Ownable {
  using Strings for uint256;
  using Counters for Counters.Counter;

  address public lendingPool;

  Counters.Counter internal _ids;
  string private baseTokenURI; // baseTokenURI can point to IPFS folder like https://ipfs.io/ipfs/{cid}/ while
  address public royaltyAddress;

  // Royalties basis points (percentage using 2 decimals - 1000 = 100, 500 = 50, 0 = 0)
  uint256 private royaltyBasisPoints = 50; // 5%

  uint256[] _openedLoans;
  // tokenId => _openedLoans idx
  mapping(uint256 => uint256) _openedIndex;
  // token IDs owned by user
  mapping(address => uint256[]) public allUserOwned;
  // tokenId => allUserOwned idx
  mapping(uint256 => uint256) public ownedIndex;

  event Burn(uint256 indexed tokenId, address indexed owner);
  event Mint(uint256 indexed tokenId, address indexed owner);
  event SetPaymentAddress(address indexed user);
  event SetRoyaltyAddress(address indexed user);
  event SetRoyaltyBasisPoints(uint256 indexed _royaltyBasisPoints);
  event SetBaseTokenURI(string indexed newUri);

  modifier onlyLendingPool() {
    require(msg.sender == lendingPool, 'ONLYLENDINGPOOL');
    _;
  }

  constructor(
    string memory _baseTokenURI
  ) ERC721('Hyperbolic Protocol Loan', 'lHYPE') {
    baseTokenURI = _baseTokenURI;
    lendingPool = msg.sender;
  }

  function getAllOpenedLoans() external view returns (uint256[] memory) {
    return _openedLoans;
  }

  function mint(address owner) external onlyLendingPool returns (uint256) {
    _ids.increment();
    _safeMint(owner, _ids.current());
    emit Mint(_ids.current(), owner);
    return _ids.current();
  }

  function burn(uint256 _tokenId) external onlyLendingPool {
    address _user = ownerOf(_tokenId);
    require(_exists(_tokenId));
    _burn(_tokenId);
    emit Burn(_tokenId, _user);
  }

  // Support royalty info - See {EIP-2981}: https://eips.ethereum.org/EIPS/eip-2981
  function royaltyInfo(
    uint256,
    uint256 _salePrice
  ) external view returns (address receiver, uint256 royaltyAmount) {
    return (royaltyAddress, (_salePrice * royaltyBasisPoints) / 1000);
  }

  function tokenURI(
    uint256 _tokenId
  ) public view virtual override returns (string memory) {
    require(_exists(_tokenId));
    return string(abi.encodePacked(_baseURI(), _tokenId.toString(), '.json'));
  }

  // Contract metadata URI - Support for OpenSea: https://docs.opensea.io/docs/contract-level-metadata
  function contractURI() public view returns (string memory) {
    return string(abi.encodePacked(_baseURI(), 'contract.json'));
  }

  // Override supportsInterface - See {IERC165-supportsInterface}
  function supportsInterface(
    bytes4 _interfaceId
  ) public view virtual override(ERC721Enumerable) returns (bool) {
    return super.supportsInterface(_interfaceId);
  }

  function getLastMintedTokenId() external view returns (uint256) {
    return _ids.current();
  }

  function doesTokenExist(uint256 _tokenId) external view returns (bool) {
    return _exists(_tokenId);
  }

  function setRoyaltyAddress(address _address) external onlyOwner {
    royaltyAddress = _address;
    emit SetRoyaltyAddress(_address);
  }

  function setRoyaltyBasisPoints(uint256 _points) external onlyOwner {
    royaltyBasisPoints = _points;
    emit SetRoyaltyBasisPoints(_points);
  }

  function setBaseURI(string memory _uri) external onlyOwner {
    baseTokenURI = _uri;
    emit SetBaseTokenURI(_uri);
  }

  function setLendingPool(address _addy) external onlyOwner {
    lendingPool = _addy;
  }

  function getAllUserOwned(
    address _user
  ) external view returns (uint256[] memory) {
    return allUserOwned[_user];
  }

  function _baseURI() internal view override returns (string memory) {
    return baseTokenURI;
  }

  function _mint(address to, uint256 tokenId) internal virtual override {
    super._mint(to, tokenId);
    _afterTokenTransfer(address(0), to, tokenId);
  }

  function _burn(uint256 tokenId) internal virtual override {
    address _owner = ERC721.ownerOf(tokenId);
    super._burn(tokenId);
    _afterTokenTransfer(_owner, address(0), tokenId);
  }

  function _transfer(
    address from,
    address to,
    uint256 tokenId
  ) internal virtual override {
    super._transfer(from, to, tokenId);
    _afterTokenTransfer(from, to, tokenId);
  }

  function _afterTokenTransfer(
    address _from,
    address _to,
    uint256 _tokenId
  ) internal virtual {
    // ensure token not being minted
    if (_from != address(0)) {
      // update user owned
      uint256 _currIndex = ownedIndex[_tokenId];
      uint256 _tokenIdMovingIndices = allUserOwned[_from][
        allUserOwned[_from].length - 1
      ];
      allUserOwned[_from][_currIndex] = _tokenIdMovingIndices;
      allUserOwned[_from].pop();
      ownedIndex[_tokenIdMovingIndices] = _currIndex;

      // update all opened
      uint256 _curOpenedIdx = _openedIndex[_tokenId];
      uint256 _tokenIdMoveOpened = _openedLoans[_openedLoans.length - 1];
      _openedLoans[_curOpenedIdx] = _tokenIdMoveOpened;
      _openedLoans.pop();
      _openedIndex[_tokenIdMoveOpened] = _curOpenedIdx;
    }

    // ensure token not being burned
    if (_to != address(0)) {
      // update user owned
      ownedIndex[_tokenId] = allUserOwned[_to].length;
      allUserOwned[_to].push(_tokenId);

      // update all opened
      _openedIndex[_tokenId] = _openedLoans.length;
      _openedLoans.push(_tokenId);
    }
  }
}

File 42 of 42 : RewardsTracker.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import './interfaces/IRewardsTracker.sol';
import './libraries/BokkyPooBahsDateTimeLibrary.sol';

contract RewardsTracker is IRewardsTracker {
  uint256 constant MULTIPLIER = 10 ** 36;
  address public token;
  uint256 public totalStakedUsers;
  uint256 public totalSharesDeposited;

  struct Share {
    uint256 amount;
    uint256 stakedTime;
  }
  struct Reward {
    uint256 totalExcluded;
    uint256 totalRealized;
  }
  mapping(address => Share) private shares;
  mapping(address => Reward) public rewards;

  uint256 public rewardsPerShare;
  uint256 public totalDistributed;
  uint256 public totalRewards;
  mapping(uint256 => uint256) public monthlyRewards;

  event AddShares(address indexed user, uint256 amount);
  event RemoveShares(address indexed user, uint256 amount);
  event ClaimReward(address user);
  event DistributeReward(address indexed user, uint256 amount);
  event DepositRewards(address indexed user, uint256 amountTokens);

  modifier onlyToken() {
    require(msg.sender == token, 'ONLYTOKEN');
    _;
  }

  constructor(address _token) {
    token = _token;
  }

  function setShare(
    address shareholder,
    uint256 balanceUpdate,
    bool isRemoving
  ) public override onlyToken {
    _setShare(shareholder, balanceUpdate, isRemoving);
  }

  function _setShare(
    address shareholder,
    uint256 balanceUpdate,
    bool isRemoving
  ) internal {
    if (isRemoving) {
      _removeShares(shareholder, balanceUpdate);
      emit RemoveShares(shareholder, balanceUpdate);
    } else {
      _addShares(shareholder, balanceUpdate);
      emit AddShares(shareholder, balanceUpdate);
    }
  }

  function _addShares(address shareholder, uint256 amount) private {
    if (shares[shareholder].amount > 0) {
      _distributeReward(shareholder);
    }

    uint256 sharesBefore = shares[shareholder].amount;

    totalSharesDeposited += amount;
    shares[shareholder].amount += amount;
    shares[shareholder].stakedTime = block.timestamp;
    if (sharesBefore == 0 && shares[shareholder].amount > 0) {
      totalStakedUsers++;
    }
    rewards[shareholder].totalExcluded = _cumulativeRewards(
      shares[shareholder].amount
    );
  }

  function _removeShares(address shareholder, uint256 amount) private {
    require(
      shares[shareholder].amount > 0 && amount <= shares[shareholder].amount,
      'REMOVE: no shares'
    );
    _distributeReward(shareholder);

    totalSharesDeposited -= amount;
    shares[shareholder].amount -= amount;
    if (shares[shareholder].amount == 0) {
      totalStakedUsers--;
    }
    rewards[shareholder].totalExcluded = _cumulativeRewards(
      shares[shareholder].amount
    );
  }

  function depositRewards() external payable override {
    _depositRewards(msg.value);
  }

  function _depositRewards(uint256 _amount) internal {
    require(_amount > 0, 'DEPOSIT: no ETH');
    require(totalSharesDeposited > 0, 'DEPOSIT: no shares');

    totalRewards += _amount;
    uint256 _month = beginningOfMonth(block.timestamp);
    monthlyRewards[_month] += _amount;
    rewardsPerShare += (MULTIPLIER * _amount) / totalSharesDeposited;
    emit DepositRewards(msg.sender, _amount);
  }

  function _distributeReward(address shareholder) internal {
    if (shares[shareholder].amount == 0) {
      return;
    }

    uint256 amount = getUnpaid(shareholder);
    rewards[shareholder].totalRealized += amount;
    rewards[shareholder].totalExcluded = _cumulativeRewards(
      shares[shareholder].amount
    );

    if (amount > 0) {
      totalDistributed += amount;
      uint256 _balBefore = address(this).balance;
      (bool success, ) = payable(shareholder).call{ value: amount }('');
      require(success, 'DIST: could not distribute');
      require(address(this).balance >= _balBefore - amount, 'DIST: too much');
      emit DistributeReward(shareholder, amount);
    }
  }

  function claimReward() external override {
    _distributeReward(msg.sender);
    emit ClaimReward(msg.sender);
  }

  function getUnpaid(address shareholder) public view returns (uint256) {
    if (shares[shareholder].amount == 0) {
      return 0;
    }
    uint256 earnedRewards = _cumulativeRewards(shares[shareholder].amount);
    uint256 rewardsExcluded = rewards[shareholder].totalExcluded;
    if (earnedRewards <= rewardsExcluded) {
      return 0;
    }
    return earnedRewards - rewardsExcluded;
  }

  function beginningOfMonth(uint256 _timestamp) public pure returns (uint256) {
    (, , uint256 _dayOfMonth) = BokkyPooBahsDateTimeLibrary.timestampToDate(
      _timestamp
    );
    return
      _timestamp - ((_dayOfMonth - 1) * 24 * 60 * 60) - (_timestamp % 1 days);
  }

  function _cumulativeRewards(uint256 share) internal view returns (uint256) {
    return (share * rewardsPerShare) / MULTIPLIER;
  }

  function getShares(address user) external view override returns (uint256) {
    return shares[user].amount;
  }
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"string","name":"_baseTokenURI","type":"string"},{"internalType":"contract ISwapRouter","name":"__swapRouter","type":"address"},{"internalType":"contract IHyperbolicProtocol","name":"__hype","type":"address"},{"internalType":"contract ITwapUtils","name":"__twapUtils","type":"address"},{"internalType":"contract LendingRewards","name":"__lendingRewards","type":"address"},{"internalType":"address","name":"__WETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"wallet","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountETH","type":"uint256"}],"name":"Borrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"DeleteLoan","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"wallet","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountCollateral","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"wallet","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountDesired","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountFees","type":"uint256"}],"name":"PayBackLoan","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"wallet","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountCollateral","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_amountETHBorrowing","type":"uint256"}],"name":"borrow","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"borrowAPRMax","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowAPRMin","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowInitFee","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amountETHBorrowed","type":"uint256"},{"internalType":"uint256","name":"_aprStart","type":"uint256"}],"name":"calculateAPRFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"calculateBorrowAPR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"checkUpkeep","outputs":[{"internalType":"bool","name":"upkeepNeeded","type":"bool"},{"internalType":"bytes","name":"performData","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"currentBorrowPerPool","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"custodian","outputs":[{"internalType":"contract LendingPoolTokenCustodian","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"address","name":"_pool","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"address","name":"_pool","type":"address"},{"internalType":"uint256","name":"_amountDepositing","type":"uint256"},{"internalType":"uint256","name":"_amountETHBorrowing","type":"uint256"}],"name":"depositAndBorrow","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"enabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllWhitelistedPools","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_wallet","type":"address"}],"name":"getETHBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getLTVX96","outputs":[{"internalType":"uint256","name":"ltvX96","type":"uint256"},{"internalType":"uint256","name":"ltvWithFeesX96","type":"uint256"},{"internalType":"uint256","name":"amountETHDepositedX96","type":"uint256"},{"internalType":"uint256","name":"amountETHBorrowedX96","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidateDefaultCapital","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidateSlippage","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidationLTV","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"loanNFT","outputs":[{"internalType":"contract LoanToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"loans","outputs":[{"internalType":"uint256","name":"created","type":"uint256"},{"internalType":"address","name":"createdBy","type":"address"},{"internalType":"uint256","name":"aprStart","type":"uint256"},{"internalType":"address","name":"collateralPool","type":"address"},{"internalType":"uint256","name":"amountDeposited","type":"uint256"},{"internalType":"uint256","name":"amountETHBorrowed","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxBorrowPerPool","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxLTVOverall","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxLTVOverride","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxLiquidationsPerUpkeep","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"payBackLoan","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"payBackLoanAndClose","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"performData","type":"bytes"}],"name":"performUpkeep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_apr","type":"uint32"}],"name":"setBorrowAPRMax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_apr","type":"uint32"}],"name":"setBorrowAPRMin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_fee","type":"uint32"}],"name":"setBorrowInitFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_enabled","type":"bool"}],"name":"setEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_shouldLiq","type":"bool"}],"name":"setLiquidateDefaultCapital","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_slippage","type":"uint32"}],"name":"setLiquidateSlippage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_ltv","type":"uint32"}],"name":"setLiquidationLTV","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"uint256","name":"_amountETH","type":"uint256"}],"name":"setMaxBorrowPerPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_ltv","type":"uint32"}],"name":"setMaxLTVOverall","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"uint32","name":"_ltv","type":"uint32"}],"name":"setMaxLTVOverride","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_max","type":"uint32"}],"name":"setMaxLiquidationsPerUpkeep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"shouldLiquidateLoan","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"}],"name":"toggleWhitelistCollateralPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelistPools","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60a06040526601000000000000600155606462000020612710600a6200041c565b6200002c919062000453565b6002805462010000600160501b0319166201000063ffffffff939093169290920263ffffffff60301b191691909117660a00000000000017905560646200007761271060036200041c565b62000083919062000453565b600b805463ffffffff191663ffffffff929092169190911790556064620000ae61271060026200041c565b620000ba919062000453565b600b805463ffffffff929092166401000000000263ffffffff60201b199092169190911790556064620000f1612710600f6200041c565b620000fd919062000453565b600b805463ffffffff92909216680100000000000000000263ffffffff60401b19909216919091179055606462000138612710605f6200041c565b62000144919062000453565b600b805463ffffffff929092166c010000000000000000000000000263ffffffff60601b1990921691909117905560646200018361271060326200041c565b6200018f919062000453565b600b60106101000a81548163ffffffff021916908363ffffffff160217905550348015620001bc57600080fd5b5060405162008b6938038062008b69833981016040819052620001df91620004de565b620001ea33620003b0565b600780546001600160a01b038088166001600160a01b0319928316179092556004805487841690831681179091556006805487851690841617905560058054868516931692909217909155908216608052604051620002499062000400565b6001600160a01b039091168152602001604051809103906000f08015801562000276573d6000803e3d6000fd5b506002600a6101000a8154816001600160a01b0302191690836001600160a01b0316021790555085604051620002ac906200040e565b620002b89190620005f4565b604051809103906000f080158015620002d5573d6000803e3d6000fd5b50600380546001600160a01b0319166001600160a01b039290921691821790556040516303692a6d60e11b81523360048201526306d254da90602401600060405180830381600087803b1580156200032c57600080fd5b505af115801562000341573d6000803e3d6000fd5b505060035460405163f2fde38b60e01b81523360048201526001600160a01b03909116925063f2fde38b9150602401600060405180830381600087803b1580156200038b57600080fd5b505af1158015620003a0573d6000803e3d6000fd5b5050505050505050505062000629565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6116928062004cb983390190565b61281e806200634b83390190565b63ffffffff8181168382160280821691908281146200044b57634e487b7160e01b600052601160045260246000fd5b505092915050565b600063ffffffff808416806200047957634e487b7160e01b600052601260045260246000fd5b92169190910492915050565b634e487b7160e01b600052604160045260246000fd5b60005b83811015620004b85781810151838201526020016200049e565b50506000910152565b80516001600160a01b0381168114620004d957600080fd5b919050565b60008060008060008060c08789031215620004f857600080fd5b86516001600160401b03808211156200051057600080fd5b818901915089601f8301126200052557600080fd5b8151818111156200053a576200053a62000485565b604051601f8201601f19908116603f0116810190838211818310171562000565576200056562000485565b816040528281528c60208487010111156200057f57600080fd5b620005928360208301602088016200049b565b809a505050505050620005a860208801620004c1565b9450620005b860408801620004c1565b9350620005c860608801620004c1565b9250620005d860808801620004c1565b9150620005e860a08801620004c1565b90509295509295509295565b6020815260008251806020840152620006158160408501602087016200049b565b601f01601f19169190910160400192915050565b6080516146356200068460003960008181610ca701528181610f7c01528181610fb701528181611b0c015281816124a501528181612894015281816129ec01528181612bb001528181612c41015261347101526146356000f3fe6080604052600436106102765760003560e01c8063838122cf1161014f578063b2b8ec41116100c1578063d539c6d41161007a578063d539c6d4146107ed578063dfad779214610820578063e1ec3c681461083f578063f2c342c3146108d4578063f2fde38b14610901578063f77118341461092157600080fd5b8063b2b8ec4114610702578063b5df93f014610726578063bc157ac114610756578063c8092cf714610776578063cd08f9711461078b578063d45b6213146107ad57600080fd5b8063921b2fb711610113578063921b2fb714610646578063930cf9731461066a57806396e41e9e1461068a5780639d32a680146106aa5780639e4d5ddf146106ca578063a4b3eb0b146106ef57600080fd5b8063838122cf146105a85780638470fc55146105c85780638a05d5f9146105e85780638da5cb5b146106085780638e6cce351461062657600080fd5b8063441a3e70116101e85780636bc394d3116101ac5780636bc394d3146104ed5780636bfeba53146105115780636e04ff0d146105355780636faa8b3f146105635780636fea611114610576578063715018a61461059357600080fd5b8063441a3e70146104405780634585e33b146104605780634e9865c7146104805780635bc7b7f3146104a057806367d4a3d3146104c057600080fd5b806323169a7b1161023a57806323169a7b1461034f578063238dafe01461036f578063328d8f721461039957806334a41177146103b9578063375b74c3146103f15780633bb66a7b1461041857600080fd5b8063051b4d0714610282578063075ee2c8146102a457806309fff963146102c45780630ecbcdab146102e45780631c57d3d31461031757600080fd5b3661027d57005b600080fd5b34801561028e57600080fd5b506102a261029d366004613ce3565b610941565b005b3480156102b057600080fd5b506102a26102bf366004613ce3565b6109e0565b3480156102d057600080fd5b506102a26102df366004613d1c565b610a62565b3480156102f057600080fd5b506103046102ff366004613d48565b610a86565b6040519081526020015b60405180910390f35b34801561032357600080fd5b5060025461033a9062010000900463ffffffff1681565b60405163ffffffff909116815260200161030e565b34801561035b57600080fd5b506102a261036a366004613ce3565b610a9c565b34801561037b57600080fd5b506002546103899060ff1681565b604051901515815260200161030e565b3480156103a557600080fd5b506102a26103b4366004613d78565b610b0b565b3480156103c557600080fd5b506003546103d9906001600160a01b031681565b6040516001600160a01b03909116815260200161030e565b3480156103fd57600080fd5b506002546103d990600160501b90046001600160a01b031681565b34801561042457600080fd5b50610304610433366004613d95565b6001600160a01b03163190565b34801561044c57600080fd5b506102a261045b366004613d48565b610b80565b34801561046c57600080fd5b506102a261047b366004613db2565b610b8f565b34801561048c57600080fd5b506102a261049b366004613ce3565b610e70565b3480156104ac57600080fd5b506102a26104bb366004613d95565b610ea1565b3480156104cc57600080fd5b506103046104db366004613d95565b600e6020526000908152604090205481565b3480156104f957600080fd5b50600b5461033a90600160801b900463ffffffff1681565b34801561051d57600080fd5b5060025461033a90600160301b900463ffffffff1681565b34801561054157600080fd5b50610555610550366004613db2565b61112a565b60405161030e929190613e74565b6102a2610571366004613e8f565b6112d6565b34801561058257600080fd5b50600b5461033a9063ffffffff1681565b34801561059f57600080fd5b506102a26112e4565b3480156105b457600080fd5b506103046105c3366004613ea8565b6112f8565b3480156105d457600080fd5b506102a26105e3366004613ee5565b61131e565b3480156105f457600080fd5b50610389610603366004613e8f565b6113a7565b34801561061457600080fd5b506000546001600160a01b03166103d9565b34801561063257600080fd5b506102a2610641366004613ce3565b6113b2565b34801561065257600080fd5b50600b5461033a90600160601b900463ffffffff1681565b34801561067657600080fd5b506102a2610685366004613ce3565b61142e565b34801561069657600080fd5b506102a26106a5366004613ce3565b6114b9565b3480156106b657600080fd5b506102a26106c5366004613d78565b611534565b3480156106d657600080fd5b50600b5461033a90640100000000900463ffffffff1681565b6102a26106fd366004613e8f565b6115a4565b34801561070e57600080fd5b50600b5461033a90600160401b900463ffffffff1681565b34801561073257600080fd5b50610389610741366004613d95565b60086020526000908152604090205460ff1681565b34801561076257600080fd5b506102a2610771366004613f1e565b611638565b34801561078257600080fd5b50610304611644565b34801561079757600080fd5b506107a06117ee565b60405161030e9190613f56565b3480156107b957600080fd5b506107cd6107c8366004613e8f565b611850565b60408051948552602085019390935291830152606082015260800161030e565b3480156107f957600080fd5b5061033a610808366004613d95565b600c6020526000908152604090205463ffffffff1681565b34801561082c57600080fd5b5060025461038990610100900460ff1681565b34801561084b57600080fd5b5061089b61085a366004613e8f565b600f6020526000908152604090208054600182015460028301546003840154600485015460059095015493946001600160a01b039384169492939091169186565b604080519687526001600160a01b03958616602088015286019390935292166060840152608083019190915260a082015260c00161030e565b3480156108e057600080fd5b506103046108ef366004613d95565b600d6020526000908152604090205481565b34801561090d57600080fd5b506102a261091c366004613d95565b611c1a565b34801561092d57600080fd5b5061030461093c366004613d48565b611c90565b610949611cd5565b6064610958612710600a613fb9565b6109629190613ff7565b63ffffffff168163ffffffff1611156109b85760405162461bcd60e51b8152602060048201526013602482015272534554424150524d494e3a206c74652031302560681b60448201526064015b60405180910390fd5b600b805463ffffffff9092166401000000000267ffffffff0000000019909216919091179055565b6109e8611cd5565b61271063ffffffff82161115610a375760405162461bcd60e51b8152602060048201526014602482015273534554424150524d41583a206c7465203130302560601b60448201526064016109af565b600b805463ffffffff909216600160401b026bffffffff000000000000000019909216919091179055565b610a6a611cd5565b6001600160a01b039091166000908152600e6020526040902055565b6000610a93338484611d2f565b90505b92915050565b610aa4611cd5565b61271063ffffffff82161115610ae75760405162461bcd60e51b81526020600482015260086024820152676c7465203130302560c01b60448201526064016109af565b6002805463ffffffff909216620100000265ffffffff000019909216919091179055565b610b13611cd5565b60025481151560ff909116151503610b6d5760405162461bcd60e51b815260206004820152601760248201527f534554454e41424c45443a206d75737420746f67676c6500000000000000000060448201526064016109af565b6002805460ff1916911515919091179055565b610b8b338383612217565b5050565b6000610b9d82840184614085565b905060005b8151811015610e6a576000828281518110610bbf57610bbf614110565b6020026020010151905080600003610bd75750610e6a565b610be0816126c4565b15610e57576000818152600f60209081526040808320815160c0810183528154815260018201546001600160a01b0390811682860152600283015482850152600383015416606082018190526004808401546080840181905260059094015460a08401528451630dfe168160e01b815294519296939591948593630dfe1681938284019390928290030181865afa158015610c7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca39190614126565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b031603610dc9576000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d429190614126565b6002546020870151604051633b6191dd60e01b8152929350600160501b9091046001600160a01b031691633b6191dd91610d86918591908990600190600401614143565b600060405180830381600087803b158015610da057600080fd5b505af1158015610db4573d6000803e3d6000fd5b50505050610dc3838287612781565b50610e49565b6002546020850151604051633b6191dd60e01b81528392600160501b90046001600160a01b031691633b6191dd91610e0a9185918990600190600401614143565b600060405180830381600087803b158015610e2457600080fd5b505af1158015610e38573d6000803e3d6000fd5b50505050610e47838287612781565b505b610e5285612ce1565b505050505b5080610e628161416c565b915050610ba2565b50505050565b610e78611cd5565b6002805463ffffffff909216600160301b0269ffffffff00000000000019909216919091179055565b610ea9611cd5565b60008190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610eee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f129190614126565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f54573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f789190614126565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161480610feb57507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b0316145b61102c5760405162461bcd60e51b81526020600482015260126024820152710a89e8e8e988a869e98987440dcde408aa8960731b60448201526064016109af565b60408051600280825260608201835260009260208301908036833701905050905061012c8160008151811061106357611063614110565b602002602001019063ffffffff16908163ffffffff168152505060008160018151811061109257611092614110565b63ffffffff9092166020928302919091019091015260405163883bdbfd60e01b81526001600160a01b0385169063883bdbfd906110d3908490600401614185565b600060405180830381865afa1580156110f0573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111189190810190614232565b505061112385612db4565b5050505050565b600060606000600360009054906101000a90046001600160a01b03166001600160a01b0316636800901a6040518163ffffffff1660e01b8152600401600060405180830381865afa158015611183573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111ab91908101906142fe565b600254909150600090600160301b900463ffffffff1667ffffffffffffffff8111156111d9576111d961401a565b604051908082528060200260200182016040528015611202578160200160208202803683370190505b5090506000805b83518110156112a25760025463ffffffff600160301b909104811690831610156112a257600084828151811061124157611241614110565b60200260200101519050611254816126c4565b1561128f576001965080848463ffffffff168151811061127657611276614110565b60209081029190910101528261128b81614384565b9350505b508061129a8161416c565b915050611209565b5084156112cc57816040516020016112ba91906143a7565b60405160208183030381529060405293505b5050509250929050565b6112e1338234612f39565b50565b6112ec611cd5565b6112f6600061320c565b565b60006113063386868661325c565b9450611313338684611d2f565b90505b949350505050565b611326611cd5565b61271063ffffffff821611156113745760405162461bcd60e51b81526020600482015260136024820152725345544c54564d41583a206c7465203130302560681b60448201526064016109af565b6001600160a01b03919091166000908152600c60205260409020805463ffffffff191663ffffffff909216919091179055565b6000610a96826126c4565b6113ba611cd5565b61271063ffffffff821611156114085760405162461bcd60e51b81526020600482015260136024820152725345544c54564d41583a206c7465203130302560681b60448201526064016109af565b600b805463ffffffff909216600160801b0263ffffffff60801b19909216919091179055565b611436611cd5565b6064611445612710601e613fb9565b61144f9190613ff7565b63ffffffff168163ffffffff16111561149d5760405162461bcd60e51b815260206004820152601060248201526f534554424645453a206c74652033302560801b60448201526064016109af565b600b805463ffffffff191663ffffffff92909216919091179055565b6114c1611cd5565b61271063ffffffff8216111561150e5760405162461bcd60e51b81526020600482015260126024820152715345544c504c54563a206c7465203130302560701b60448201526064016109af565b600b805463ffffffff909216600160601b0263ffffffff60601b19909216919091179055565b61153c611cd5565b801515600260019054906101000a900460ff1615150361158a5760405162461bcd60e51b815260206004820152600960248201526829a2aa2624a8a222a360b91b60448201526064016109af565b600280549115156101000261ff0019909216919091179055565b6000818152600f6020526040902060050154156115cb576115c6338234612f39565b611619565b34156116195760405162461bcd60e51b815260206004820152601a60248201527f5041594241434b4c4f53453a206e6f20455448206e656564656400000000000060448201526064016109af565b6000818152600f60205260409020600401546112e19033908390612217565b610e6a3384848461325c565b6000806000600460009054906101000a90046001600160a01b03166001600160a01b031663fb5ebf366040518163ffffffff1660e01b81526004016040805180830381865afa15801561169b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116bf91906143df565b91509150600061271063ffffffff16600460009054906101000a90046001600160a01b03166001600160a01b0316637e3596996040518163ffffffff1660e01b8152600401602060405180830381865afa158015611721573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117459190614403565b6117559063ffffffff1684614420565b61175f9190614437565b9050808310156117d557600b54600090829085906117949063ffffffff6401000000008204811691600160401b90041661444b565b63ffffffff166117a49190614420565b6117ae9190614437565b600b549091506117cc908290600160401b900463ffffffff1661446f565b94505050505090565b5050600b54640100000000900463ffffffff1692915050565b6060600980548060200260200160405190810160405280929190818152602001828054801561184657602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611828575b5050505050905090565b60035460405163c3738f3f60e01b8152600481018390526000918291829182916001600160a01b039091169063c3738f3f90602401602060405180830381865afa1580156118a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118c69190614482565b6119125760405162461bcd60e51b815260206004820152601760248201527f4745544c54563a206c6f616e206d75737420657869737400000000000000000060448201526064016109af565b6000858152600f60209081526040808320815160c0810183528154815260018201546001600160a01b0390811694820194909452600282015492810183905260038201549093166060840152600481015460808401526005015460a0830181905291929161197f91611c90565b905081608001516000148015611997575060a0820151155b156119b15760008060008095509550955095505050611c13565b6006546060830151604051631ece4f9760e21b81526001600160a01b0391821660048201526000929190911690637b393e5c90602401602060405180830381865afa158015611a04573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a289190614126565b6006546040516304e09a6160e41b81526001600160a01b03808416600483015292935060009290911690634e09a61090602401602060405180830381865afa158015611a78573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a9c919061449f565b9050600084606001516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b069190614126565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031614611b57576080860151611b529084614420565b611b80565b82611b676002600160601b61459c565b611b719190614437565b8660800151611b809190614420565b90506000600160601b8760a00151611b989190614420565b90506000600160601b878960a00151611bb191906145ab565b611bbb9190614420565b60015490915083611bcc8285614420565b611bd69190614437565b611be09190614420565b60015484611bee8285614420565b611bf89190614437565b611c029190614420565b909c509a5091985096505050505050505b9193509193565b611c22611cd5565b6001600160a01b038116611c875760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016109af565b6112e18161320c565b60006301e1338061271084611ca3611644565b611cad864261446f565b611cb79190614420565b611cc19190614420565b611ccb9190614437565b610a939190614437565b6000546001600160a01b031633146112f65760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016109af565b60025460009060ff16611d7a5760405162461bcd60e51b81526020600482015260136024820152721093d49493d5ce881b9bdd08195b98589b1959606a1b60448201526064016109af565b611d84848461377e565b6000838152600f6020908152604080832060038101546001600160a01b0316845260089092529091205460ff16611df05760405162461bcd60e51b815260206004820152601060248201526f1093d49493d5ce88189859081c1bdbdb60821b60448201526064016109af565b6000611e0482600501548360020154611c90565b4260028401559050600080611e1887611850565b9350935050506000600160601b83611e309190614437565b90506000611e42600160601b84614437565b60038701546001600160a01b03166000908152600c60205260408120549192509063ffffffff16611e9a57600b5461271090611e8b90600160801b900463ffffffff1685614420565b611e959190614437565b611ed5565b60038701546001600160a01b03166000908152600c602052604090205461271090611ecb9063ffffffff1685614420565b611ed59190614437565b9050808210611f1e5760405162461bcd60e51b8152602060048201526015602482015274424f52524f573a2063616e6e6f7420626f72726f7760581b60448201526064016109af565b80611f298a846145ab565b1115611f3c57611f39828261446f565b98505b88471015611f8c5760405162461bcd60e51b815260206004820152601860248201527f424f52524f573a206e6f7420656e6f7567682066756e6473000000000000000060448201526064016109af565b60038701546001600160a01b03166000908152600e6020526040902054156120305760038701546001600160a01b03166000908152600e6020908152604080832054600d90925290912054611fe2908b906145ab565b11156120305760405162461bcd60e51b815260206004820152601860248201527f424f52524f573a206578636565647320706f6f6c206d6178000000000000000060448201526064016109af565b60038701546001600160a01b03166000908152600d6020526040812080548b929061205c9084906145ab565b925050819055508887600501600082825461207791906145ab565b9091555050600b54600090612710906120969063ffffffff168c614420565b6120a09190614437565b6120aa90886145ab565b9050808a116121075760405162461bcd60e51b8152602060048201526024808201527f424f52524f573a2066656573206d6f7265207468616e20626f72726f7720616d6044820152631bdd5b9d60e21b60648201526084016109af565b6000612113828c61446f565b905061211e8261383b565b60008d6001600160a01b03168260405160006040518083038185875af1925050503d806000811461216b576040519150601f19603f3d011682016040523d82523d6000602084013e612170565b606091505b50509050806121c15760405162461bcd60e51b815260206004820152601960248201527f424f52524f573a20455448206e6f742064656c6976657265640000000000000060448201526064016109af565b8c8e6001600160a01b03167fe1979fe4c35e0cef342fef5668e2c8e7a7e9f5d5d1ca8fee0ac6c427fa4153af8e6040516121fd91815260200190565b60405180910390a3509a9c9b505050505050505050505050565b600081116122715760405162461bcd60e51b815260206004820152602160248201527f57495448445241573a206d7573742077697468647261772066726f6d206c6f616044820152603760f91b60648201526084016109af565b61227b838361377e565b6000828152600f6020526040902060048101548211156122d25760405162461bcd60e51b81526020600482015260126024820152710ae92a89088a482ae7440e8dede40daeac6d60731b60448201526064016109af565b818160040160008282546122e6919061446f565b90915550600090506122f784611850565b505060038401546001600160a01b03166000908152600c602052604090205490925063ffffffff161590506123b55760038201546001600160a01b03166000908152600c60205260409020546127109061235b9063ffffffff16600160601b614420565b6123659190614437565b8111156123b05760405162461bcd60e51b81526020600482015260196024820152782ba4aa24222920ab9d1032bc31b2b2b2399036b0bc10262a2b60391b60448201526064016109af565b61242c565b600b54612710906123d790600160801b900463ffffffff16600160601b614420565b6123e19190614437565b81111561242c5760405162461bcd60e51b81526020600482015260196024820152782ba4aa24222920ab9d1032bc31b2b2b2399036b0bc10262a2b60391b60448201526064016109af565b600382015460408051630dfe168160e01b815290516001600160a01b03909216916000918391630dfe1681916004808201926020929091908290030181865afa15801561247d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124a19190614126565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b0316036125d4576000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561251c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125409190614126565b600254600180880154604051633b6191dd60e01b81529394506001600160a01b03600160501b909304831693633b6191dd93612587938793909116918c9190600401614143565b600060405180830381600087803b1580156125a157600080fd5b505af11580156125b5573d6000803e3d6000fd5b506125ce925050506001600160a01b03821689886138a7565b50612662565b600254600185810154604051633b6191dd60e01b81528493600160501b90046001600160a01b0390811693633b6191dd93612619938793909116918c91600401614143565b600060405180830381600087803b15801561263357600080fd5b505af1158015612647573d6000803e3d6000fd5b50612660925050506001600160a01b03821689886138a7565b505b83600401546000036126775761267786612ce1565b85876001600160a01b03167ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b568876040516126b391815260200190565b60405180910390a350505050505050565b60035460405163c3738f3f60e01b8152600481018390526000916001600160a01b03169063c3738f3f90602401602060405180830381865afa15801561270e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127329190614482565b61273e57506000919050565b600061274983611850565b5050600b54909250612710915061276f90600160601b9081900463ffffffff1690614420565b6127799190614437565b111592915050565b600254610100900460ff1680156127a657506004546001600160a01b03838116911614155b15612cb157600654604051631ece4f9760e21b81526001600160a01b0385811660048301526000921690637b393e5c90602401602060405180830381865afa1580156127f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061281a9190614126565b6006546040516304e09a6160e41b81526001600160a01b03808416600483015292935060009290911690634e09a61090602401602060405180830381865afa15801561286a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061288e919061449f565b905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316866001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061291e9190614126565b6001600160a01b03161461294b578161293c6002600160601b61459c565b6129469190614437565b61294d565b815b90506000600160601b8560800151836129669190614420565b6129709190614437565b905060008560a001518211612989578560a0015161298b565b815b60075460808801519192506129ab9189916001600160a01b03169061390a565b600760009054906101000a90046001600160a01b03166001600160a01b031663414bf3896040518061010001604052808a6001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020018b6001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a7b91906145be565b62ffffff1681523060208201524260408201526080808b0151606083015260025491019061271090612ab99062010000900463ffffffff168261444b565b612ac99063ffffffff1687614420565b612ad39190614437565b815260006020918201526040805160e085811b6001600160e01b031916825284516001600160a01b03908116600484015293850151841660248301529184015162ffffff1660448201526060840151831660648201526080840151608482015260a084015160a482015260c084015160c48201529201511660e4820152610104016020604051808303816000875af1158015612b73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b97919061449f565b506040516370a0823160e01b81523060048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa158015612bff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c23919061449f565b90508015612ca657604051632e1a7d4d60e01b8152600481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015612c8d57600080fd5b505af1158015612ca1573d6000803e3d6000fd5b505050505b505050505050505050565b612cdc612cc66000546001600160a01b031690565b60808301516001600160a01b03851691906138a7565b505050565b6000818152600f60205260408082208281556001810180546001600160a01b03199081169091556002820184905560038083018054909216909155600480830185905560059092019390935591549051630852cd8d60e31b81529182018390526001600160a01b0316906342966c6890602401600060405180830381600087803b158015612d6e57600080fd5b505af1158015612d82573d6000803e3d6000fd5b50506040518392507f40e7dd78d661cb2192925e6eeecc3f99eb4f3e7457c18ea57ddd84cd051d01f39150600090a250565b6001600160a01b03811660009081526008602052604090205460ff1615612ec6576001600160a01b0381166000908152600a602052604081205460098054919291612e019060019061446f565b81548110612e1157612e11614110565b600091825260209091200154600980546001600160a01b039092169250829184908110612e4057612e40614110565b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790558383168252600a8152604080832086905592861682526008905220805460ff191690556009805480612e9c57612e9c6145e3565b600082815260209020810160001990810180546001600160a01b0319169055019055506112e19050565b6001600160a01b03166000818152600860209081526040808320805460ff1916600190811790915560098054600a909452918420839055820181559091527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0180546001600160a01b0319169091179055565b60008111612f895760405162461bcd60e51b815260206004820152601b60248201527f5041594241434b3a206e6f2045544820746f20706179206261636b000000000060448201526064016109af565b612f93838361377e565b6000828152600f6020526040812060058101546002820154919291612fb89190611c90565b42600284015590508083116130195760405162461bcd60e51b815260206004820152602160248201527f5041594241434b3a206d75737420706179206261636b2061626f7665206665656044820152607360f81b60648201526084016109af565b600081836005015461302b91906145ab565b905060008185111561304457613041828661446f565b90505b60038401546001600160a01b03166000908152600d602052604090205461306b848761446f565b1161307f5761307a838661446f565b61309d565b60038401546001600160a01b03166000908152600d60205260409020545b60038501546001600160a01b03166000908152600d6020526040812080549091906130c990849061446f565b909155505060058401546130dd848761446f565b116130f1576130ec838661446f565b6130f7565b83600501545b84600501600082825461310a919061446f565b9091555050821561311e5761311e8361383b565b80156131c9576000876001600160a01b03168260405160006040518083038185875af1925050503d8060008114613171576040519150601f19603f3d011682016040523d82523d6000602084013e613176565b606091505b50509050806131c75760405162461bcd60e51b815260206004820152601c60248201527f5041594241434b3a20726566756e6420756e7375636365737366756c0000000060448201526064016109af565b505b604080518681526020810185905287916001600160a01b038a16917fca92b037c5d17af773d2a576cd91e713e64b80af7c561456d811d12fc927960091016126b3565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60025460009060ff166132a85760405162461bcd60e51b815260206004820152601460248201527311115413d4d2550e881b9bdd08195b98589b195960621b60448201526064016109af565b60006132b48686613a03565b506000818152600f602052604081206003810154929750879350916001600160a01b031661337d576001600160a01b03861660009081526008602052604090205460ff166133395760405162461bcd60e51b815260206004820152601260248201527104445504f5349543a2062616420706f6f6c360741b60448201526064016109af565b50428082556001820180546001600160a01b03808b166001600160a01b031992831617909255600284019290925560038301805491881691909216179055846133ee565b60038201546001600160a01b031660009081526008602052604090205460ff166133de5760405162461bcd60e51b81526020600482015260126024820152714445504f5349543a2062616420706f6f6c3160701b60448201526064016109af565b5060038101546001600160a01b03165b8482600401600082825461340291906145ab565b925050819055506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015613449573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061346d9190614126565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b03160361361f576000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156134e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061350c9190614126565b90506135236001600160a01b0382168b308a613aa1565b60025460405163095ea7b360e01b8152600160501b9091046001600160a01b0390811660048301526024820189905282169063095ea7b3906044016020604051808303816000875af115801561357d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135a19190614482565b506002546001850154604051633b6191dd60e01b8152600160501b9092046001600160a01b0390811692633b6191dd926135e79286929116908c90600090600401614143565b600060405180830381600087803b15801561360157600080fd5b505af1158015613615573d6000803e3d6000fd5b505050505061372d565b806136356001600160a01b0382168b308a613aa1565b60025460405163095ea7b360e01b8152600160501b9091046001600160a01b0390811660048301526024820189905282169063095ea7b3906044016020604051808303816000875af115801561368f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136b39190614482565b506002546001850154604051633b6191dd60e01b8152600160501b9092046001600160a01b0390811692633b6191dd926136f99286929116908c90600090600401614143565b600060405180830381600087803b15801561371357600080fd5b505af1158015613727573d6000803e3d6000fd5b50505050505b87896001600160a01b03167f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a158860405161376991815260200190565b60405180910390a35095979650505050505050565b6003546040516331a9108f60e11b8152600481018390526001600160a01b0390911690636352211e90602401602060405180830381865afa1580156137c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137eb9190614126565b6001600160a01b0316826001600160a01b031614610b8b5760405162461bcd60e51b815260206004820152600d60248201526c2b20a624a220aa22a7aba722a960991b60448201526064016109af565b600560009054906101000a90046001600160a01b03166001600160a01b031663152111f7826040518263ffffffff1660e01b81526004016000604051808303818588803b15801561388b57600080fd5b505af115801561389f573d6000803e3d6000fd5b505050505050565b6040516001600160a01b038316602482015260448101829052612cdc90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613ad9565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b179052915160009283929087169161396691906145f9565b6000604051808303816000865af19150503d80600081146139a3576040519150601f19603f3d011682016040523d82523d6000602084013e6139a8565b606091505b50915091508180156139d25750805115806139d25750808060200190518101906139d29190614482565b6111235760405162461bcd60e51b8152602060048201526002602482015261534160f01b60448201526064016109af565b60008082600003613a89576003546040516335313c2160e11b81526001600160a01b03868116600483015290911690636a627842906024016020604051808303816000875af1158015613a5a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a7e919061449f565b915060019050613a9a565b613a93848461377e565b5081905060005b9250929050565b6040516001600160a01b0380851660248301528316604482015260648101829052610e6a9085906323b872dd60e01b906084016138d3565b6000613b2e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316613bae9092919063ffffffff16565b9050805160001480613b4f575080806020019051810190613b4f9190614482565b612cdc5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016109af565b6060611316848460008585600080866001600160a01b03168587604051613bd591906145f9565b60006040518083038185875af1925050503d8060008114613c12576040519150601f19603f3d011682016040523d82523d6000602084013e613c17565b606091505b5091509150613c2887838387613c33565b979650505050505050565b60608315613ca2578251600003613c9b576001600160a01b0385163b613c9b5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016109af565b5081611316565b6113168383815115613cb75781518083602001fd5b8060405162461bcd60e51b81526004016109af9190614615565b63ffffffff811681146112e157600080fd5b600060208284031215613cf557600080fd5b8135613d0081613cd1565b9392505050565b6001600160a01b03811681146112e157600080fd5b60008060408385031215613d2f57600080fd5b8235613d3a81613d07565b946020939093013593505050565b60008060408385031215613d5b57600080fd5b50508035926020909101359150565b80151581146112e157600080fd5b600060208284031215613d8a57600080fd5b8135613d0081613d6a565b600060208284031215613da757600080fd5b8135613d0081613d07565b60008060208385031215613dc557600080fd5b823567ffffffffffffffff80821115613ddd57600080fd5b818501915085601f830112613df157600080fd5b813581811115613e0057600080fd5b866020828501011115613e1257600080fd5b60209290920196919550909350505050565b60005b83811015613e3f578181015183820152602001613e27565b50506000910152565b60008151808452613e60816020860160208601613e24565b601f01601f19169290920160200192915050565b82151581526040602082015260006113166040830184613e48565b600060208284031215613ea157600080fd5b5035919050565b60008060008060808587031215613ebe57600080fd5b843593506020850135613ed081613d07565b93969395505050506040820135916060013590565b60008060408385031215613ef857600080fd5b8235613f0381613d07565b91506020830135613f1381613cd1565b809150509250929050565b600080600060608486031215613f3357600080fd5b833592506020840135613f4581613d07565b929592945050506040919091013590565b6020808252825182820181905260009190848201906040850190845b81811015613f975783516001600160a01b031683529284019291840191600101613f72565b50909695505050505050565b634e487b7160e01b600052601160045260246000fd5b63ffffffff818116838216028082169190828114613fd957613fd9613fa3565b505092915050565b634e487b7160e01b600052601260045260246000fd5b600063ffffffff8084168061400e5761400e613fe1565b92169190910492915050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156140595761405961401a565b604052919050565b600067ffffffffffffffff82111561407b5761407b61401a565b5060051b60200190565b6000602080838503121561409857600080fd5b823567ffffffffffffffff8111156140af57600080fd5b8301601f810185136140c057600080fd5b80356140d36140ce82614061565b614030565b81815260059190911b820183019083810190878311156140f257600080fd5b928401925b82841015613c28578335825292840192908401906140f7565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561413857600080fd5b8151613d0081613d07565b6001600160a01b0394851681529290931660208301526040820152901515606082015260800190565b60006001820161417e5761417e613fa3565b5060010190565b6020808252825182820181905260009190848201906040850190845b81811015613f9757835163ffffffff16835292840192918401916001016141a1565b600082601f8301126141d457600080fd5b815160206141e46140ce83614061565b82815260059290921b8401810191818101908684111561420357600080fd5b8286015b8481101561422757805161421a81613d07565b8352918301918301614207565b509695505050505050565b6000806040838503121561424557600080fd5b825167ffffffffffffffff8082111561425d57600080fd5b818501915085601f83011261427157600080fd5b815160206142816140ce83614061565b82815260059290921b840181019181810190898411156142a057600080fd5b948201945b838610156142ce5785518060060b81146142bf5760008081fd5b825294820194908201906142a5565b918801519196509093505050808211156142e757600080fd5b506142f4858286016141c3565b9150509250929050565b6000602080838503121561431157600080fd5b825167ffffffffffffffff81111561432857600080fd5b8301601f8101851361433957600080fd5b80516143476140ce82614061565b81815260059190911b8201830190838101908783111561436657600080fd5b928401925b82841015613c285783518252928401929084019061436b565b600063ffffffff80831681810361439d5761439d613fa3565b6001019392505050565b6020808252825182820181905260009190848201906040850190845b81811015613f97578351835292840192918401916001016143c3565b600080604083850312156143f257600080fd5b505080516020909101519092909150565b60006020828403121561441557600080fd5b8151613d0081613cd1565b8082028115828204841417610a9657610a96613fa3565b60008261444657614446613fe1565b500490565b63ffffffff82811682821603908082111561446857614468613fa3565b5092915050565b81810381811115610a9657610a96613fa3565b60006020828403121561449457600080fd5b8151613d0081613d6a565b6000602082840312156144b157600080fd5b5051919050565b600181815b808511156144f35781600019048211156144d9576144d9613fa3565b808516156144e657918102915b93841c93908002906144bd565b509250929050565b60008261450a57506001610a96565b8161451757506000610a96565b816001811461452d576002811461453757614553565b6001915050610a96565b60ff84111561454857614548613fa3565b50506001821b610a96565b5060208310610133831016604e8410600b8410161715614576575081810a610a96565b61458083836144b8565b806000190482111561459457614594613fa3565b029392505050565b6000610a9360ff8416836144fb565b80820180821115610a9657610a96613fa3565b6000602082840312156145d057600080fd5b815162ffffff81168114613d0057600080fd5b634e487b7160e01b600052603160045260246000fd5b6000825161460b818460208701613e24565b9190910192915050565b602081526000610a936020830184613e4856fea164736f6c6343000813000a608060405234801561001057600080fd5b5060405161169238038061169283398101604081905261002f916100bd565b806100393361006d565b600180546001600160a01b039283166001600160a01b031991821617909155600a80549390921692169190911790556100ed565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000602082840312156100cf57600080fd5b81516001600160a01b03811681146100e657600080fd5b9392505050565b611596806100fc6000396000f3fe6080604052600436106101185760003560e01c806380bb4055116100a0578063d076eabc11610064578063d076eabc14610413578063efca2eed14610433578063f04da65b14610449578063f2fde38b1461047f578063fc0c546a1461049f57600080fd5b806380bb40551461039457806389d96917146103aa5780638da5cb5b146103ca578063b88a802f146103e8578063c7e1d0b1146103fd57600080fd5b806329cc05cf116100e757806329cc05cf146102f15780633b6191dd146103115780633c6e6789146103315780636ecf9f7b14610347578063715018a61461037f57600080fd5b8063058df06d1461024a5780630700037d1461028a5780630e15561a146102d3578063152111f7146102e957600080fd5b3661024557600a546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015610166573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061018a9190611284565b9050801561019d5761019b346104bf565b005b600080546040516001600160a01b039091169034908381818185875af1925050503d80600081146101ea576040519150601f19603f3d011682016040523d82523d6000602084013e6101ef565b606091505b505090508061019b5760405162461bcd60e51b815260206004820152601e60248201527f524543454956453a20646964206e6f742073656e6420746f206f776e6572000060448201526064015b60405180910390fd5b600080fd5b34801561025657600080fd5b5061027761026536600461129d565b60096020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561029657600080fd5b506102be6102a53660046112cb565b6005602052600090815260409020805460019091015482565b60408051928352602083019190915201610281565b3480156102df57600080fd5b5061027760085481565b61019b61060a565b3480156102fd57600080fd5b5061019b61030c3660046112f6565b610615565b34801561031d57600080fd5b5061019b61032c366004611338565b61066b565b34801561033d57600080fd5b5061027760035481565b34801561035357600080fd5b50600a54610367906001600160a01b031681565b6040516001600160a01b039091168152602001610281565b34801561038b57600080fd5b5061019b6106ce565b3480156103a057600080fd5b5061027760025481565b3480156103b657600080fd5b506102776103c53660046112cb565b6106e0565b3480156103d657600080fd5b506000546001600160a01b0316610367565b3480156103f457600080fd5b5061019b610768565b34801561040957600080fd5b5061027760065481565b34801561041f57600080fd5b5061027761042e36600461129d565b6107a6565b34801561043f57600080fd5b5061027760075481565b34801561045557600080fd5b506102776104643660046112cb565b6001600160a01b031660009081526004602052604090205490565b34801561048b57600080fd5b5061019b61049a3660046112cb565b61080c565b3480156104ab57600080fd5b50600154610367906001600160a01b031681565b600081116105015760405162461bcd60e51b815260206004820152600f60248201526e0888aa09ea692a87440dcde408aa89608b1b604482015260640161023c565b6000600354116105485760405162461bcd60e51b81526020600482015260126024820152714445504f5349543a206e6f2073686172657360701b604482015260640161023c565b806008600082825461055a91906113a1565b909155506000905061056b426107a6565b90508160096000838152602001908152602001600020600082825461059091906113a1565b90915550506003546105b1836ec097ce7bc90715b34b9f10000000006113b4565b6105bb91906113e1565b600660008282546105cc91906113a1565b909155505060405182815233907fb9ad861b752f80117b35bea6dec99933d8a5ae360f2839ee8784b750d56134099060200160405180910390a25050565b610613346104bf565b565b6001546001600160a01b0316331461065b5760405162461bcd60e51b815260206004820152600960248201526827a7262caa27a5a2a760b91b604482015260640161023c565b610666838383610885565b505050565b610673610922565b80156106925761068d6001600160a01b038516338461097c565b6106a7565b6106a76001600160a01b0385163330856109df565b600a546001600160a01b03908116908516036106c8576106c8838383610885565b50505050565b6106d6610922565b6106136000610a17565b6001600160a01b038116600090815260046020526040812054810361070757506000919050565b6001600160a01b03821660009081526004602052604081205461072990610a67565b6001600160a01b038416600090815260056020526040902054909150808211610756575060009392505050565b61076081836113f5565b949350505050565b61077133610a97565b6040513381527f63e32091e4445d16e29c33a6b264577c2d86694021aa4e6f4dd590048f5792e89060200160405180910390a1565b6000806107b283610c88565b9250505062015180836107c59190611408565b6107d06001836113f5565b6107db9060186113b4565b6107e690603c6113b4565b6107f190603c6113b4565b6107fb90856113f5565b61080591906113f5565b9392505050565b610814610922565b6001600160a01b0381166108795760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161023c565b61088281610a17565b50565b80156108dd576108958383610cae565b826001600160a01b03167fae0577e1c96b26fbc0b9df702431f5470979d001d24f136eded791b8b6521d6f836040516108d091815260200190565b60405180910390a2505050565b6108e78383610df1565b826001600160a01b03167fba8f3777cf908803bf1f3dd58e7f4b7d3de4dbe3c234c4ccab0975d98f7cd388836040516108d091815260200190565b6000546001600160a01b031633146106135760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161023c565b6040516001600160a01b03831660248201526044810182905261066690849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152610f18565b6040516001600160a01b03808516602483015283166044820152606481018290526106c89085906323b872dd60e01b906084016109a8565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006ec097ce7bc90715b34b9f100000000060065483610a8791906113b4565b610a9191906113e1565b92915050565b6001600160a01b0381166000908152600460205260408120549003610ab95750565b6000610ac4826106e0565b6001600160a01b038316600090815260056020526040812060010180549293508392909190610af49084906113a1565b90915550506001600160a01b038216600090815260046020526040902054610b1b90610a67565b6001600160a01b0383166000908152600560205260409020558015610c84578060076000828254610b4c91906113a1565b909155505060405147906000906001600160a01b0385169084908381818185875af1925050503d8060008114610b9e576040519150601f19603f3d011682016040523d82523d6000602084013e610ba3565b606091505b5050905080610bf45760405162461bcd60e51b815260206004820152601a60248201527f444953543a20636f756c64206e6f742064697374726962757465000000000000604482015260640161023c565b610bfe83836113f5565b471015610c3e5760405162461bcd60e51b815260206004820152600e60248201526d08892a6a87440e8dede40daeac6d60931b604482015260640161023c565b836001600160a01b03167fe8b160e373db99a103e0a2abfa029b9c3fc8b328984a1ead8a65ae68ae646db784604051610c7991815260200190565b60405180910390a250505b5050565b60008080610ca1610c9c62015180866113e1565b610fed565b9196909550909350915050565b6001600160a01b03821660009081526004602052604090205415801590610ced57506001600160a01b0382166000908152600460205260409020548111155b610d2d5760405162461bcd60e51b815260206004820152601160248201527052454d4f56453a206e6f2073686172657360781b604482015260640161023c565b610d3682610a97565b8060036000828254610d4891906113f5565b90915550506001600160a01b03821660009081526004602052604081208054839290610d759084906113f5565b90915550506001600160a01b0382166000908152600460205260408120549003610daf5760028054906000610da98361141c565b91905055505b6001600160a01b038216600090815260046020526040902054610dd190610a67565b6001600160a01b0390921660009081526005602052604090209190915550565b6001600160a01b03821660009081526004602052604090205415610e1857610e1882610a97565b6001600160a01b0382166000908152600460205260408120546003805491928492610e449084906113a1565b90915550506001600160a01b03831660009081526004602052604081208054849290610e719084906113a1565b90915550506001600160a01b03831660009081526004602052604090204260019091015580158015610eba57506001600160a01b03831660009081526004602052604090205415155b15610ed55760028054906000610ecf83611433565b91905055505b6001600160a01b038316600090815260046020526040902054610ef790610a67565b6001600160a01b039093166000908152600560205260409020929092555050565b6000610f6d826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166111619092919063ffffffff16565b9050805160001480610f8e575080806020019051810190610f8e919061144c565b6106665760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161023c565b60008080838162253d8c6110048362010bd9611469565b61100e9190611469565b9050600062023ab1611021836004611491565b61102b91906114c1565b9050600461103c8262023ab1611491565b611047906003611469565b61105191906114c1565b61105b90836114ef565b9150600062164b0961106e846001611469565b61107a90610fa0611491565b61108491906114c1565b90506004611094826105b5611491565b61109e91906114c1565b6110a890846114ef565b6110b390601f611469565b9250600061098f6110c5856050611491565b6110cf91906114c1565b9050600060506110e18361098f611491565b6110eb91906114c1565b6110f590866114ef565b9050611102600b836114c1565b945061110f85600c611491565b61111a836002611469565b61112491906114ef565b915084836111336031876114ef565b61113e906064611491565b6111489190611469565b6111529190611469565b9a919950975095505050505050565b6060610760848460008585600080866001600160a01b03168587604051611188919061153a565b60006040518083038185875af1925050503d80600081146111c5576040519150601f19603f3d011682016040523d82523d6000602084013e6111ca565b606091505b50915091506111db878383876111e6565b979650505050505050565b6060831561125557825160000361124e576001600160a01b0385163b61124e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161023c565b5081610760565b610760838381511561126a5781518083602001fd5b8060405162461bcd60e51b815260040161023c9190611556565b60006020828403121561129657600080fd5b5051919050565b6000602082840312156112af57600080fd5b5035919050565b6001600160a01b038116811461088257600080fd5b6000602082840312156112dd57600080fd5b8135610805816112b6565b801515811461088257600080fd5b60008060006060848603121561130b57600080fd5b8335611316816112b6565b925060208401359150604084013561132d816112e8565b809150509250925092565b6000806000806080858703121561134e57600080fd5b8435611359816112b6565b93506020850135611369816112b6565b9250604085013591506060850135611380816112e8565b939692955090935050565b634e487b7160e01b600052601160045260246000fd5b80820180821115610a9157610a9161138b565b8082028115828204841417610a9157610a9161138b565b634e487b7160e01b600052601260045260246000fd5b6000826113f0576113f06113cb565b500490565b81810381811115610a9157610a9161138b565b600082611417576114176113cb565b500690565b60008161142b5761142b61138b565b506000190190565b6000600182016114455761144561138b565b5060010190565b60006020828403121561145e57600080fd5b8151610805816112e8565b80820182811260008312801582168215821617156114895761148961138b565b505092915050565b80820260008212600160ff1b841416156114ad576114ad61138b565b8181058314821517610a9157610a9161138b565b6000826114d0576114d06113cb565b600160ff1b8214600019841416156114ea576114ea61138b565b500590565b818103600083128015838313168383128216171561150f5761150f61138b565b5092915050565b60005b83811015611531578181015183820152602001611519565b50506000910152565b6000825161154c818460208701611516565b9190910192915050565b6020815260008251806020840152611575816040850160208701611516565b601f01601f1916919091016040019291505056fea164736f6c6343000813000a60806040526032600f553480156200001657600080fd5b506040516200281e3803806200281e83398101604081905262000039916200015e565b6040518060400160405280601881526020017f4879706572626f6c69632050726f746f636f6c204c6f616e0000000000000000815250604051806040016040528060058152602001646c4859504560d81b81525081600090816200009e9190620002c2565b506001620000ad8282620002c2565b505050620000ca620000c4620000f260201b60201c565b620000f6565b600d620000d88282620002c2565b5050600b80546001600160a01b031916331790556200038e565b3390565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b634e487b7160e01b600052604160045260246000fd5b600060208083850312156200017257600080fd5b82516001600160401b03808211156200018a57600080fd5b818501915085601f8301126200019f57600080fd5b815181811115620001b457620001b462000148565b604051601f8201601f19908116603f01168101908382118183101715620001df57620001df62000148565b816040528281528886848701011115620001f857600080fd5b600093505b828410156200021c5784840186015181850187015292850192620001fd565b600086848301015280965050505050505092915050565b600181811c908216806200024857607f821691505b6020821081036200026957634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620002bd57600081815260208120601f850160051c81016020861015620002985750805b601f850160051c820191505b81811015620002b957828155600101620002a4565b5050505b505050565b81516001600160401b03811115620002de57620002de62000148565b620002f681620002ef845462000233565b846200026f565b602080601f8311600181146200032e5760008415620003155750858301515b600019600386901b1c1916600185901b178555620002b9565b600085815260208120601f198616915b828110156200035f578886015182559484019460019091019084016200033e565b50858210156200037e5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b612480806200039e6000396000f3fe608060405234801561001057600080fd5b50600436106102115760003560e01c80636800901a11610125578063ad2f852a116100ad578063c87b56dd1161007c578063c87b56dd1461048b578063e8a3d4851461049e578063e985e9c5146104a6578063f2fde38b146104e2578063ffa80136146104f557600080fd5b8063ad2f852a1461043f578063b6b8194014610452578063b88d4fde14610465578063c3738f3f1461047857600080fd5b80637974e46a116100f45780637974e46a146103f85780638da5cb5b1461040057806395d89b4114610411578063a22cb46514610419578063a59a99731461042c57600080fd5b80636800901a146103b55780636a627842146103ca57806370a08231146103dd578063715018a6146103f057600080fd5b806323b872dd116101a857806342842e0e1161017757806342842e0e1461035657806342966c68146103695780634f6ccce71461037c57806355f804b31461038f5780636352211e146103a257600080fd5b806323b872dd146102de578063274de61e146102f15780632a55205a146103115780632f745c591461034357600080fd5b8063095ea7b3116101e4578063095ea7b314610293578063113aa8b1146102a657806318160ddd146102b957806320e3fa50146102cb57600080fd5b806301ffc9a71461021657806306d254da1461023e57806306fdde0314610253578063081812fc14610268575b600080fd5b610229610224366004611d75565b610508565b60405190151581526020015b60405180910390f35b61025161024c366004611db0565b610519565b005b61025b61056b565b6040516102359190611e1b565b61027b610276366004611e2e565b6105fd565b6040516001600160a01b039091168152602001610235565b6102516102a1366004611e47565b610624565b6102516102b4366004611db0565b61073e565b6008545b604051908152602001610235565b6102bd6102d9366004611e47565b610768565b6102516102ec366004611e71565b610799565b6102bd6102ff366004611e2e565b60136020526000908152604090205481565b61032461031f366004611ead565b6107ca565b604080516001600160a01b039093168352602083019190915201610235565b6102bd610351366004611e47565b610804565b610251610364366004611e71565b61089a565b610251610377366004611e2e565b6108b5565b6102bd61038a366004611e2e565b610963565b61025161039d366004611f5b565b6109f6565b61027b6103b0366004611e2e565b610a4c565b6103bd610aac565b6040516102359190611fa4565b6102bd6103d8366004611db0565b610b03565b6102bd6103eb366004611db0565b610bbb565b610251610c41565b6102bd610c55565b600a546001600160a01b031661027b565b61025b610c65565b610251610427366004611fe8565b610c74565b600b5461027b906001600160a01b031681565b600e5461027b906001600160a01b031681565b610251610460366004611e2e565b610c83565b610251610473366004612024565b610cbe565b610229610486366004611e2e565b610cf6565b61025b610499366004611e2e565b610d01565b61025b610d4d565b6102296104b43660046120a0565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6102516104f0366004611db0565b610d7b565b6103bd610503366004611db0565b610df4565b600061051382610e60565b92915050565b610521610e85565b600e80546001600160a01b0319166001600160a01b0383169081179091556040517f0f2a87e68f9d4311c1d18e960f7873198e70403a037237cdd2c583c69cdddf1f90600090a250565b60606000805461057a906120d3565b80601f01602080910402602001604051908101604052809291908181526020018280546105a6906120d3565b80156105f35780601f106105c8576101008083540402835291602001916105f3565b820191906000526020600020905b8154815290600101906020018083116105d657829003601f168201915b5050505050905090565b600061060882610edf565b506000908152600460205260409020546001600160a01b031690565b600061062f82610a4c565b9050806001600160a01b0316836001600160a01b0316036106a15760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084015b60405180910390fd5b336001600160a01b03821614806106bd57506106bd81336104b4565b61072f5760405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c0000006064820152608401610698565b6107398383610f2f565b505050565b610746610e85565b600b80546001600160a01b0319166001600160a01b0392909216919091179055565b6012602052816000526040600020818154811061078457600080fd5b90600052602060002001600091509150505481565b6107a33382610f9d565b6107bf5760405162461bcd60e51b81526004016106989061210d565b61073983838361101c565b600e54600f5460009182916001600160a01b03909116906103e8906107ef9086612170565b6107f99190612187565b915091509250929050565b600061080f83610bbb565b82106108715760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610698565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b61073983838360405180602001604052806000815250610cbe565b600b546001600160a01b031633146109015760405162461bcd60e51b815260206004820152600f60248201526e13d3931653115391125391d413d3d3608a1b6044820152606401610698565b600061090c82610a4c565b905061091782611032565b61092057600080fd5b6109298261104f565b6040516001600160a01b0382169083907ff6554c3a5d28e08c120b5a69c7edbaf52f935bd2596a60b8a18e282cd257cddb90600090a35050565b600061096e60085490565b82106109d15760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610698565b600882815481106109e4576109e46121a9565b90600052602060002001549050919050565b6109fe610e85565b600d610a0a828261220d565b5080604051610a1991906122cd565b604051908190038120907f199e933997358e1789d8b56ea8c551befeb05ce2fe3fe506199f1230f5a591b490600090a250565b6000818152600260205260408120546001600160a01b0316806105135760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606401610698565b606060108054806020026020016040519081016040528092919081815260200182805480156105f357602002820191906000526020600020905b815481526020019060010190808311610ae6575050505050905090565b600b546000906001600160a01b03163314610b525760405162461bcd60e51b815260206004820152600f60248201526e13d3931653115391125391d413d3d3608a1b6044820152606401610698565b610b60600c80546001019055565b610b7282610b6d600c5490565b611071565b816001600160a01b0316610b85600c5490565b6040517ff3cea5493d790af0133817606f7350a91d7f154ea52eaa79d179d4d231e5010290600090a3600c54610513565b919050565b60006001600160a01b038216610c255760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608401610698565b506001600160a01b031660009081526003602052604090205490565b610c49610e85565b610c53600061108b565b565b6000610c60600c5490565b905090565b60606001805461057a906120d3565b610c7f3383836110dd565b5050565b610c8b610e85565b600f81905560405181907f2ad2ae73af42f598ecb723109218def6abfe2e801eb5719ab4acbf9adc91c65d90600090a250565b610cc83383610f9d565b610ce45760405162461bcd60e51b81526004016106989061210d565b610cf0848484846111ab565b50505050565b600061051382611032565b6060610d0c82611032565b610d1557600080fd5b610d1d6111de565b610d26836111ed565b604051602001610d379291906122e9565b6040516020818303038152906040529050919050565b6060610d576111de565b604051602001610d679190612328565b604051602081830303815290604052905090565b610d83610e85565b6001600160a01b038116610de85760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610698565b610df18161108b565b50565b6001600160a01b038116600090815260126020908152604091829020805483518184028101840190945280845260609392830182828015610e5457602002820191906000526020600020905b815481526020019060010190808311610e40575b50505050509050919050565b60006001600160e01b0319821663780e9d6360e01b1480610513575061051382611280565b600a546001600160a01b03163314610c535760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610698565b610ee881611032565b610df15760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606401610698565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190610f6482610a4c565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600080610fa983610a4c565b9050806001600160a01b0316846001600160a01b03161480610ff057506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b806110145750836001600160a01b0316611009846105fd565b6001600160a01b0316145b949350505050565b6110278383836112d0565b610739838383611441565b6000908152600260205260409020546001600160a01b0316151590565b600061105a82610a4c565b90506110658261165b565b610c7f81600084611441565b610c7f8282604051806020016040528060008152506116fe565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b816001600160a01b0316836001600160a01b03160361113e5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610698565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6111b684848461101c565b6111c284848484611731565b610cf05760405162461bcd60e51b815260040161069890612359565b6060600d805461057a906120d3565b606060006111fa83611832565b600101905060008167ffffffffffffffff81111561121a5761121a611ecf565b6040519080825280601f01601f191660200182016040528015611244576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508461124e57509392505050565b60006001600160e01b031982166380ac58cd60e01b14806112b157506001600160e01b03198216635b5e139f60e01b145b8061051357506301ffc9a760e01b6001600160e01b0319831614610513565b826001600160a01b03166112e382610a4c565b6001600160a01b0316146113095760405162461bcd60e51b8152600401610698906123ab565b6001600160a01b03821661136b5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610698565b611378838383600161190a565b826001600160a01b031661138b82610a4c565b6001600160a01b0316146113b15760405162461bcd60e51b8152600401610698906123ab565b600081815260046020908152604080832080546001600160a01b03199081169091556001600160a01b0387811680865260038552838620805460001901905590871680865283862080546001019055868652600290945282852080549092168417909155905184937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6001600160a01b038316156115d0576000818152601360209081526040808320546001600160a01b0387168452601290925282208054919291611486906001906123f0565b81548110611496576114966121a9565b906000526020600020015490508060126000876001600160a01b03166001600160a01b0316815260200190815260200160002083815481106114da576114da6121a9565b60009182526020808320909101929092556001600160a01b038716815260129091526040902080548061150f5761150f612403565b600082815260208082208301600019908101839055909201909255828252601381526040808320859055858352601190915281205460108054919291611557906001906123f0565b81548110611567576115676121a9565b906000526020600020015490508060108381548110611588576115886121a9565b60009182526020909120015560108054806115a5576115a5612403565b6000828152602080822083016000199081018390559092019092559181526011909152604090205550505b6001600160a01b03821615610739576001600160a01b039190911660009081526012602090815260408083208054858552601384528285208190556001808201835591855283852001859055601080548686526011909452918420839055820181559091527f1b6847dc741a1b0cd08d278845f9d819d87b734759afb55fe2de5cb82a9ae672015550565b600061166682610a4c565b905061167681600084600161190a565b61167f82610a4c565b600083815260046020908152604080832080546001600160a01b03199081169091556001600160a01b0385168085526003845282852080546000190190558785526002909352818420805490911690555192935084927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6117088383611a3e565b6117156000848484611731565b6107395760405162461bcd60e51b815260040161069890612359565b60006001600160a01b0384163b1561182757604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611775903390899088908890600401612419565b6020604051808303816000875af19250505080156117b0575060408051601f3d908101601f191682019092526117ad91810190612456565b60015b61180d573d8080156117de576040519150601f19603f3d011682016040523d82523d6000602084013e6117e3565b606091505b5080516000036118055760405162461bcd60e51b815260040161069890612359565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611014565b506001949350505050565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106118715772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef8100000000831061189d576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106118bb57662386f26fc10000830492506010015b6305f5e10083106118d3576305f5e100830492506008015b61271083106118e757612710830492506004015b606483106118f9576064830492506002015b600a83106105135760010192915050565b60018111156119795760405162461bcd60e51b815260206004820152603560248201527f455243373231456e756d657261626c653a20636f6e7365637574697665207472604482015274185b9cd9995c9cc81b9bdd081cdd5c1c1bdc9d1959605a1b6064820152608401610698565b816001600160a01b0385166119d5576119d081600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b6119f8565b836001600160a01b0316856001600160a01b0316146119f8576119f88582611a54565b6001600160a01b038416611a1457611a0f81611af1565b611a37565b846001600160a01b0316846001600160a01b031614611a3757611a378482611ba0565b5050505050565b611a488282611be4565b610c7f60008383611441565b60006001611a6184610bbb565b611a6b91906123f0565b600083815260076020526040902054909150808214611abe576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b600854600090611b03906001906123f0565b60008381526009602052604081205460088054939450909284908110611b2b57611b2b6121a9565b906000526020600020015490508060088381548110611b4c57611b4c6121a9565b6000918252602080832090910192909255828152600990915260408082208490558582528120556008805480611b8457611b84612403565b6001900381819060005260206000200160009055905550505050565b6000611bab83610bbb565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6001600160a01b038216611c3a5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610698565b611c4381611032565b15611c905760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610698565b611c9e60008383600161190a565b611ca781611032565b15611cf45760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610698565b6001600160a01b038216600081815260036020908152604080832080546001019055848352600290915280822080546001600160a01b0319168417905551839291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6001600160e01b031981168114610df157600080fd5b600060208284031215611d8757600080fd5b8135611d9281611d5f565b9392505050565b80356001600160a01b0381168114610bb657600080fd5b600060208284031215611dc257600080fd5b611d9282611d99565b60005b83811015611de6578181015183820152602001611dce565b50506000910152565b60008151808452611e07816020860160208601611dcb565b601f01601f19169290920160200192915050565b602081526000611d926020830184611def565b600060208284031215611e4057600080fd5b5035919050565b60008060408385031215611e5a57600080fd5b611e6383611d99565b946020939093013593505050565b600080600060608486031215611e8657600080fd5b611e8f84611d99565b9250611e9d60208501611d99565b9150604084013590509250925092565b60008060408385031215611ec057600080fd5b50508035926020909101359150565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff80841115611f0057611f00611ecf565b604051601f8501601f19908116603f01168101908282118183101715611f2857611f28611ecf565b81604052809350858152868686011115611f4157600080fd5b858560208301376000602087830101525050509392505050565b600060208284031215611f6d57600080fd5b813567ffffffffffffffff811115611f8457600080fd5b8201601f81018413611f9557600080fd5b61101484823560208401611ee5565b6020808252825182820181905260009190848201906040850190845b81811015611fdc57835183529284019291840191600101611fc0565b50909695505050505050565b60008060408385031215611ffb57600080fd5b61200483611d99565b91506020830135801515811461201957600080fd5b809150509250929050565b6000806000806080858703121561203a57600080fd5b61204385611d99565b935061205160208601611d99565b925060408501359150606085013567ffffffffffffffff81111561207457600080fd5b8501601f8101871361208557600080fd5b61209487823560208401611ee5565b91505092959194509250565b600080604083850312156120b357600080fd5b6120bc83611d99565b91506120ca60208401611d99565b90509250929050565b600181811c908216806120e757607f821691505b60208210810361210757634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252602d908201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560408201526c1c881bdc88185c1c1c9bdd9959609a1b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176105135761051361215a565b6000826121a457634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b601f82111561073957600081815260208120601f850160051c810160208610156121e65750805b601f850160051c820191505b81811015612205578281556001016121f2565b505050505050565b815167ffffffffffffffff81111561222757612227611ecf565b61223b8161223584546120d3565b846121bf565b602080601f83116001811461227057600084156122585750858301515b600019600386901b1c1916600185901b178555612205565b600085815260208120601f198616915b8281101561229f57888601518255948401946001909101908401612280565b50858210156122bd5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600082516122df818460208701611dcb565b9190910192915050565b600083516122fb818460208801611dcb565b83519083019061230f818360208801611dcb565b64173539b7b760d91b9101908152600501949350505050565b6000825161233a818460208701611dcb565b6c31b7b73a3930b1ba173539b7b760991b920191825250600d01919050565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60208082526025908201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060408201526437bbb732b960d91b606082015260800190565b818103818111156105135761051361215a565b634e487b7160e01b600052603160045260246000fd5b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061244c90830184611def565b9695505050505050565b60006020828403121561246857600080fd5b8151611d9281611d5f56fea164736f6c6343000813000a00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000e592427a0aece92de3edee1f18e0157c0586156400000000000000000000000085225ed797fd4128ac45a992c46ea4681a7a15da000000000000000000000000bf1858b24243ecbcf7d940f458e36cb7401c2366000000000000000000000000300648a601c584e6379fa0d6a31cbbfcca6177e4000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000003668747470733a2f2f6170692e6879706572626f6c696370726f746f636f6c2e636f6d2f6c6f616e732f6574682f6d657461646174612f00000000000000000000

Deployed Bytecode

0x6080604052600436106102765760003560e01c8063838122cf1161014f578063b2b8ec41116100c1578063d539c6d41161007a578063d539c6d4146107ed578063dfad779214610820578063e1ec3c681461083f578063f2c342c3146108d4578063f2fde38b14610901578063f77118341461092157600080fd5b8063b2b8ec4114610702578063b5df93f014610726578063bc157ac114610756578063c8092cf714610776578063cd08f9711461078b578063d45b6213146107ad57600080fd5b8063921b2fb711610113578063921b2fb714610646578063930cf9731461066a57806396e41e9e1461068a5780639d32a680146106aa5780639e4d5ddf146106ca578063a4b3eb0b146106ef57600080fd5b8063838122cf146105a85780638470fc55146105c85780638a05d5f9146105e85780638da5cb5b146106085780638e6cce351461062657600080fd5b8063441a3e70116101e85780636bc394d3116101ac5780636bc394d3146104ed5780636bfeba53146105115780636e04ff0d146105355780636faa8b3f146105635780636fea611114610576578063715018a61461059357600080fd5b8063441a3e70146104405780634585e33b146104605780634e9865c7146104805780635bc7b7f3146104a057806367d4a3d3146104c057600080fd5b806323169a7b1161023a57806323169a7b1461034f578063238dafe01461036f578063328d8f721461039957806334a41177146103b9578063375b74c3146103f15780633bb66a7b1461041857600080fd5b8063051b4d0714610282578063075ee2c8146102a457806309fff963146102c45780630ecbcdab146102e45780631c57d3d31461031757600080fd5b3661027d57005b600080fd5b34801561028e57600080fd5b506102a261029d366004613ce3565b610941565b005b3480156102b057600080fd5b506102a26102bf366004613ce3565b6109e0565b3480156102d057600080fd5b506102a26102df366004613d1c565b610a62565b3480156102f057600080fd5b506103046102ff366004613d48565b610a86565b6040519081526020015b60405180910390f35b34801561032357600080fd5b5060025461033a9062010000900463ffffffff1681565b60405163ffffffff909116815260200161030e565b34801561035b57600080fd5b506102a261036a366004613ce3565b610a9c565b34801561037b57600080fd5b506002546103899060ff1681565b604051901515815260200161030e565b3480156103a557600080fd5b506102a26103b4366004613d78565b610b0b565b3480156103c557600080fd5b506003546103d9906001600160a01b031681565b6040516001600160a01b03909116815260200161030e565b3480156103fd57600080fd5b506002546103d990600160501b90046001600160a01b031681565b34801561042457600080fd5b50610304610433366004613d95565b6001600160a01b03163190565b34801561044c57600080fd5b506102a261045b366004613d48565b610b80565b34801561046c57600080fd5b506102a261047b366004613db2565b610b8f565b34801561048c57600080fd5b506102a261049b366004613ce3565b610e70565b3480156104ac57600080fd5b506102a26104bb366004613d95565b610ea1565b3480156104cc57600080fd5b506103046104db366004613d95565b600e6020526000908152604090205481565b3480156104f957600080fd5b50600b5461033a90600160801b900463ffffffff1681565b34801561051d57600080fd5b5060025461033a90600160301b900463ffffffff1681565b34801561054157600080fd5b50610555610550366004613db2565b61112a565b60405161030e929190613e74565b6102a2610571366004613e8f565b6112d6565b34801561058257600080fd5b50600b5461033a9063ffffffff1681565b34801561059f57600080fd5b506102a26112e4565b3480156105b457600080fd5b506103046105c3366004613ea8565b6112f8565b3480156105d457600080fd5b506102a26105e3366004613ee5565b61131e565b3480156105f457600080fd5b50610389610603366004613e8f565b6113a7565b34801561061457600080fd5b506000546001600160a01b03166103d9565b34801561063257600080fd5b506102a2610641366004613ce3565b6113b2565b34801561065257600080fd5b50600b5461033a90600160601b900463ffffffff1681565b34801561067657600080fd5b506102a2610685366004613ce3565b61142e565b34801561069657600080fd5b506102a26106a5366004613ce3565b6114b9565b3480156106b657600080fd5b506102a26106c5366004613d78565b611534565b3480156106d657600080fd5b50600b5461033a90640100000000900463ffffffff1681565b6102a26106fd366004613e8f565b6115a4565b34801561070e57600080fd5b50600b5461033a90600160401b900463ffffffff1681565b34801561073257600080fd5b50610389610741366004613d95565b60086020526000908152604090205460ff1681565b34801561076257600080fd5b506102a2610771366004613f1e565b611638565b34801561078257600080fd5b50610304611644565b34801561079757600080fd5b506107a06117ee565b60405161030e9190613f56565b3480156107b957600080fd5b506107cd6107c8366004613e8f565b611850565b60408051948552602085019390935291830152606082015260800161030e565b3480156107f957600080fd5b5061033a610808366004613d95565b600c6020526000908152604090205463ffffffff1681565b34801561082c57600080fd5b5060025461038990610100900460ff1681565b34801561084b57600080fd5b5061089b61085a366004613e8f565b600f6020526000908152604090208054600182015460028301546003840154600485015460059095015493946001600160a01b039384169492939091169186565b604080519687526001600160a01b03958616602088015286019390935292166060840152608083019190915260a082015260c00161030e565b3480156108e057600080fd5b506103046108ef366004613d95565b600d6020526000908152604090205481565b34801561090d57600080fd5b506102a261091c366004613d95565b611c1a565b34801561092d57600080fd5b5061030461093c366004613d48565b611c90565b610949611cd5565b6064610958612710600a613fb9565b6109629190613ff7565b63ffffffff168163ffffffff1611156109b85760405162461bcd60e51b8152602060048201526013602482015272534554424150524d494e3a206c74652031302560681b60448201526064015b60405180910390fd5b600b805463ffffffff9092166401000000000267ffffffff0000000019909216919091179055565b6109e8611cd5565b61271063ffffffff82161115610a375760405162461bcd60e51b8152602060048201526014602482015273534554424150524d41583a206c7465203130302560601b60448201526064016109af565b600b805463ffffffff909216600160401b026bffffffff000000000000000019909216919091179055565b610a6a611cd5565b6001600160a01b039091166000908152600e6020526040902055565b6000610a93338484611d2f565b90505b92915050565b610aa4611cd5565b61271063ffffffff82161115610ae75760405162461bcd60e51b81526020600482015260086024820152676c7465203130302560c01b60448201526064016109af565b6002805463ffffffff909216620100000265ffffffff000019909216919091179055565b610b13611cd5565b60025481151560ff909116151503610b6d5760405162461bcd60e51b815260206004820152601760248201527f534554454e41424c45443a206d75737420746f67676c6500000000000000000060448201526064016109af565b6002805460ff1916911515919091179055565b610b8b338383612217565b5050565b6000610b9d82840184614085565b905060005b8151811015610e6a576000828281518110610bbf57610bbf614110565b6020026020010151905080600003610bd75750610e6a565b610be0816126c4565b15610e57576000818152600f60209081526040808320815160c0810183528154815260018201546001600160a01b0390811682860152600283015482850152600383015416606082018190526004808401546080840181905260059094015460a08401528451630dfe168160e01b815294519296939591948593630dfe1681938284019390928290030181865afa158015610c7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca39190614126565b90507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316816001600160a01b031603610dc9576000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d429190614126565b6002546020870151604051633b6191dd60e01b8152929350600160501b9091046001600160a01b031691633b6191dd91610d86918591908990600190600401614143565b600060405180830381600087803b158015610da057600080fd5b505af1158015610db4573d6000803e3d6000fd5b50505050610dc3838287612781565b50610e49565b6002546020850151604051633b6191dd60e01b81528392600160501b90046001600160a01b031691633b6191dd91610e0a9185918990600190600401614143565b600060405180830381600087803b158015610e2457600080fd5b505af1158015610e38573d6000803e3d6000fd5b50505050610e47838287612781565b505b610e5285612ce1565b505050505b5080610e628161416c565b915050610ba2565b50505050565b610e78611cd5565b6002805463ffffffff909216600160301b0269ffffffff00000000000019909216919091179055565b610ea9611cd5565b60008190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610eee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f129190614126565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f54573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f789190614126565b90507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b03161480610feb57507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316816001600160a01b0316145b61102c5760405162461bcd60e51b81526020600482015260126024820152710a89e8e8e988a869e98987440dcde408aa8960731b60448201526064016109af565b60408051600280825260608201835260009260208301908036833701905050905061012c8160008151811061106357611063614110565b602002602001019063ffffffff16908163ffffffff168152505060008160018151811061109257611092614110565b63ffffffff9092166020928302919091019091015260405163883bdbfd60e01b81526001600160a01b0385169063883bdbfd906110d3908490600401614185565b600060405180830381865afa1580156110f0573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111189190810190614232565b505061112385612db4565b5050505050565b600060606000600360009054906101000a90046001600160a01b03166001600160a01b0316636800901a6040518163ffffffff1660e01b8152600401600060405180830381865afa158015611183573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111ab91908101906142fe565b600254909150600090600160301b900463ffffffff1667ffffffffffffffff8111156111d9576111d961401a565b604051908082528060200260200182016040528015611202578160200160208202803683370190505b5090506000805b83518110156112a25760025463ffffffff600160301b909104811690831610156112a257600084828151811061124157611241614110565b60200260200101519050611254816126c4565b1561128f576001965080848463ffffffff168151811061127657611276614110565b60209081029190910101528261128b81614384565b9350505b508061129a8161416c565b915050611209565b5084156112cc57816040516020016112ba91906143a7565b60405160208183030381529060405293505b5050509250929050565b6112e1338234612f39565b50565b6112ec611cd5565b6112f6600061320c565b565b60006113063386868661325c565b9450611313338684611d2f565b90505b949350505050565b611326611cd5565b61271063ffffffff821611156113745760405162461bcd60e51b81526020600482015260136024820152725345544c54564d41583a206c7465203130302560681b60448201526064016109af565b6001600160a01b03919091166000908152600c60205260409020805463ffffffff191663ffffffff909216919091179055565b6000610a96826126c4565b6113ba611cd5565b61271063ffffffff821611156114085760405162461bcd60e51b81526020600482015260136024820152725345544c54564d41583a206c7465203130302560681b60448201526064016109af565b600b805463ffffffff909216600160801b0263ffffffff60801b19909216919091179055565b611436611cd5565b6064611445612710601e613fb9565b61144f9190613ff7565b63ffffffff168163ffffffff16111561149d5760405162461bcd60e51b815260206004820152601060248201526f534554424645453a206c74652033302560801b60448201526064016109af565b600b805463ffffffff191663ffffffff92909216919091179055565b6114c1611cd5565b61271063ffffffff8216111561150e5760405162461bcd60e51b81526020600482015260126024820152715345544c504c54563a206c7465203130302560701b60448201526064016109af565b600b805463ffffffff909216600160601b0263ffffffff60601b19909216919091179055565b61153c611cd5565b801515600260019054906101000a900460ff1615150361158a5760405162461bcd60e51b815260206004820152600960248201526829a2aa2624a8a222a360b91b60448201526064016109af565b600280549115156101000261ff0019909216919091179055565b6000818152600f6020526040902060050154156115cb576115c6338234612f39565b611619565b34156116195760405162461bcd60e51b815260206004820152601a60248201527f5041594241434b4c4f53453a206e6f20455448206e656564656400000000000060448201526064016109af565b6000818152600f60205260409020600401546112e19033908390612217565b610e6a3384848461325c565b6000806000600460009054906101000a90046001600160a01b03166001600160a01b031663fb5ebf366040518163ffffffff1660e01b81526004016040805180830381865afa15801561169b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116bf91906143df565b91509150600061271063ffffffff16600460009054906101000a90046001600160a01b03166001600160a01b0316637e3596996040518163ffffffff1660e01b8152600401602060405180830381865afa158015611721573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117459190614403565b6117559063ffffffff1684614420565b61175f9190614437565b9050808310156117d557600b54600090829085906117949063ffffffff6401000000008204811691600160401b90041661444b565b63ffffffff166117a49190614420565b6117ae9190614437565b600b549091506117cc908290600160401b900463ffffffff1661446f565b94505050505090565b5050600b54640100000000900463ffffffff1692915050565b6060600980548060200260200160405190810160405280929190818152602001828054801561184657602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611828575b5050505050905090565b60035460405163c3738f3f60e01b8152600481018390526000918291829182916001600160a01b039091169063c3738f3f90602401602060405180830381865afa1580156118a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118c69190614482565b6119125760405162461bcd60e51b815260206004820152601760248201527f4745544c54563a206c6f616e206d75737420657869737400000000000000000060448201526064016109af565b6000858152600f60209081526040808320815160c0810183528154815260018201546001600160a01b0390811694820194909452600282015492810183905260038201549093166060840152600481015460808401526005015460a0830181905291929161197f91611c90565b905081608001516000148015611997575060a0820151155b156119b15760008060008095509550955095505050611c13565b6006546060830151604051631ece4f9760e21b81526001600160a01b0391821660048201526000929190911690637b393e5c90602401602060405180830381865afa158015611a04573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a289190614126565b6006546040516304e09a6160e41b81526001600160a01b03808416600483015292935060009290911690634e09a61090602401602060405180830381865afa158015611a78573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a9c919061449f565b9050600084606001516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b069190614126565b905060007f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b031614611b57576080860151611b529084614420565b611b80565b82611b676002600160601b61459c565b611b719190614437565b8660800151611b809190614420565b90506000600160601b8760a00151611b989190614420565b90506000600160601b878960a00151611bb191906145ab565b611bbb9190614420565b60015490915083611bcc8285614420565b611bd69190614437565b611be09190614420565b60015484611bee8285614420565b611bf89190614437565b611c029190614420565b909c509a5091985096505050505050505b9193509193565b611c22611cd5565b6001600160a01b038116611c875760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016109af565b6112e18161320c565b60006301e1338061271084611ca3611644565b611cad864261446f565b611cb79190614420565b611cc19190614420565b611ccb9190614437565b610a939190614437565b6000546001600160a01b031633146112f65760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016109af565b60025460009060ff16611d7a5760405162461bcd60e51b81526020600482015260136024820152721093d49493d5ce881b9bdd08195b98589b1959606a1b60448201526064016109af565b611d84848461377e565b6000838152600f6020908152604080832060038101546001600160a01b0316845260089092529091205460ff16611df05760405162461bcd60e51b815260206004820152601060248201526f1093d49493d5ce88189859081c1bdbdb60821b60448201526064016109af565b6000611e0482600501548360020154611c90565b4260028401559050600080611e1887611850565b9350935050506000600160601b83611e309190614437565b90506000611e42600160601b84614437565b60038701546001600160a01b03166000908152600c60205260408120549192509063ffffffff16611e9a57600b5461271090611e8b90600160801b900463ffffffff1685614420565b611e959190614437565b611ed5565b60038701546001600160a01b03166000908152600c602052604090205461271090611ecb9063ffffffff1685614420565b611ed59190614437565b9050808210611f1e5760405162461bcd60e51b8152602060048201526015602482015274424f52524f573a2063616e6e6f7420626f72726f7760581b60448201526064016109af565b80611f298a846145ab565b1115611f3c57611f39828261446f565b98505b88471015611f8c5760405162461bcd60e51b815260206004820152601860248201527f424f52524f573a206e6f7420656e6f7567682066756e6473000000000000000060448201526064016109af565b60038701546001600160a01b03166000908152600e6020526040902054156120305760038701546001600160a01b03166000908152600e6020908152604080832054600d90925290912054611fe2908b906145ab565b11156120305760405162461bcd60e51b815260206004820152601860248201527f424f52524f573a206578636565647320706f6f6c206d6178000000000000000060448201526064016109af565b60038701546001600160a01b03166000908152600d6020526040812080548b929061205c9084906145ab565b925050819055508887600501600082825461207791906145ab565b9091555050600b54600090612710906120969063ffffffff168c614420565b6120a09190614437565b6120aa90886145ab565b9050808a116121075760405162461bcd60e51b8152602060048201526024808201527f424f52524f573a2066656573206d6f7265207468616e20626f72726f7720616d6044820152631bdd5b9d60e21b60648201526084016109af565b6000612113828c61446f565b905061211e8261383b565b60008d6001600160a01b03168260405160006040518083038185875af1925050503d806000811461216b576040519150601f19603f3d011682016040523d82523d6000602084013e612170565b606091505b50509050806121c15760405162461bcd60e51b815260206004820152601960248201527f424f52524f573a20455448206e6f742064656c6976657265640000000000000060448201526064016109af565b8c8e6001600160a01b03167fe1979fe4c35e0cef342fef5668e2c8e7a7e9f5d5d1ca8fee0ac6c427fa4153af8e6040516121fd91815260200190565b60405180910390a3509a9c9b505050505050505050505050565b600081116122715760405162461bcd60e51b815260206004820152602160248201527f57495448445241573a206d7573742077697468647261772066726f6d206c6f616044820152603760f91b60648201526084016109af565b61227b838361377e565b6000828152600f6020526040902060048101548211156122d25760405162461bcd60e51b81526020600482015260126024820152710ae92a89088a482ae7440e8dede40daeac6d60731b60448201526064016109af565b818160040160008282546122e6919061446f565b90915550600090506122f784611850565b505060038401546001600160a01b03166000908152600c602052604090205490925063ffffffff161590506123b55760038201546001600160a01b03166000908152600c60205260409020546127109061235b9063ffffffff16600160601b614420565b6123659190614437565b8111156123b05760405162461bcd60e51b81526020600482015260196024820152782ba4aa24222920ab9d1032bc31b2b2b2399036b0bc10262a2b60391b60448201526064016109af565b61242c565b600b54612710906123d790600160801b900463ffffffff16600160601b614420565b6123e19190614437565b81111561242c5760405162461bcd60e51b81526020600482015260196024820152782ba4aa24222920ab9d1032bc31b2b2b2399036b0bc10262a2b60391b60448201526064016109af565b600382015460408051630dfe168160e01b815290516001600160a01b03909216916000918391630dfe1681916004808201926020929091908290030181865afa15801561247d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124a19190614126565b90507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316816001600160a01b0316036125d4576000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561251c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125409190614126565b600254600180880154604051633b6191dd60e01b81529394506001600160a01b03600160501b909304831693633b6191dd93612587938793909116918c9190600401614143565b600060405180830381600087803b1580156125a157600080fd5b505af11580156125b5573d6000803e3d6000fd5b506125ce925050506001600160a01b03821689886138a7565b50612662565b600254600185810154604051633b6191dd60e01b81528493600160501b90046001600160a01b0390811693633b6191dd93612619938793909116918c91600401614143565b600060405180830381600087803b15801561263357600080fd5b505af1158015612647573d6000803e3d6000fd5b50612660925050506001600160a01b03821689886138a7565b505b83600401546000036126775761267786612ce1565b85876001600160a01b03167ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b568876040516126b391815260200190565b60405180910390a350505050505050565b60035460405163c3738f3f60e01b8152600481018390526000916001600160a01b03169063c3738f3f90602401602060405180830381865afa15801561270e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127329190614482565b61273e57506000919050565b600061274983611850565b5050600b54909250612710915061276f90600160601b9081900463ffffffff1690614420565b6127799190614437565b111592915050565b600254610100900460ff1680156127a657506004546001600160a01b03838116911614155b15612cb157600654604051631ece4f9760e21b81526001600160a01b0385811660048301526000921690637b393e5c90602401602060405180830381865afa1580156127f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061281a9190614126565b6006546040516304e09a6160e41b81526001600160a01b03808416600483015292935060009290911690634e09a61090602401602060405180830381865afa15801561286a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061288e919061449f565b905060007f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316866001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061291e9190614126565b6001600160a01b03161461294b578161293c6002600160601b61459c565b6129469190614437565b61294d565b815b90506000600160601b8560800151836129669190614420565b6129709190614437565b905060008560a001518211612989578560a0015161298b565b815b60075460808801519192506129ab9189916001600160a01b03169061390a565b600760009054906101000a90046001600160a01b03166001600160a01b031663414bf3896040518061010001604052808a6001600160a01b031681526020017f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031681526020018b6001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a7b91906145be565b62ffffff1681523060208201524260408201526080808b0151606083015260025491019061271090612ab99062010000900463ffffffff168261444b565b612ac99063ffffffff1687614420565b612ad39190614437565b815260006020918201526040805160e085811b6001600160e01b031916825284516001600160a01b03908116600484015293850151841660248301529184015162ffffff1660448201526060840151831660648201526080840151608482015260a084015160a482015260c084015160c48201529201511660e4820152610104016020604051808303816000875af1158015612b73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b97919061449f565b506040516370a0823160e01b81523060048201526000907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316906370a0823190602401602060405180830381865afa158015612bff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c23919061449f565b90508015612ca657604051632e1a7d4d60e01b8152600481018290527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015612c8d57600080fd5b505af1158015612ca1573d6000803e3d6000fd5b505050505b505050505050505050565b612cdc612cc66000546001600160a01b031690565b60808301516001600160a01b03851691906138a7565b505050565b6000818152600f60205260408082208281556001810180546001600160a01b03199081169091556002820184905560038083018054909216909155600480830185905560059092019390935591549051630852cd8d60e31b81529182018390526001600160a01b0316906342966c6890602401600060405180830381600087803b158015612d6e57600080fd5b505af1158015612d82573d6000803e3d6000fd5b50506040518392507f40e7dd78d661cb2192925e6eeecc3f99eb4f3e7457c18ea57ddd84cd051d01f39150600090a250565b6001600160a01b03811660009081526008602052604090205460ff1615612ec6576001600160a01b0381166000908152600a602052604081205460098054919291612e019060019061446f565b81548110612e1157612e11614110565b600091825260209091200154600980546001600160a01b039092169250829184908110612e4057612e40614110565b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790558383168252600a8152604080832086905592861682526008905220805460ff191690556009805480612e9c57612e9c6145e3565b600082815260209020810160001990810180546001600160a01b0319169055019055506112e19050565b6001600160a01b03166000818152600860209081526040808320805460ff1916600190811790915560098054600a909452918420839055820181559091527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0180546001600160a01b0319169091179055565b60008111612f895760405162461bcd60e51b815260206004820152601b60248201527f5041594241434b3a206e6f2045544820746f20706179206261636b000000000060448201526064016109af565b612f93838361377e565b6000828152600f6020526040812060058101546002820154919291612fb89190611c90565b42600284015590508083116130195760405162461bcd60e51b815260206004820152602160248201527f5041594241434b3a206d75737420706179206261636b2061626f7665206665656044820152607360f81b60648201526084016109af565b600081836005015461302b91906145ab565b905060008185111561304457613041828661446f565b90505b60038401546001600160a01b03166000908152600d602052604090205461306b848761446f565b1161307f5761307a838661446f565b61309d565b60038401546001600160a01b03166000908152600d60205260409020545b60038501546001600160a01b03166000908152600d6020526040812080549091906130c990849061446f565b909155505060058401546130dd848761446f565b116130f1576130ec838661446f565b6130f7565b83600501545b84600501600082825461310a919061446f565b9091555050821561311e5761311e8361383b565b80156131c9576000876001600160a01b03168260405160006040518083038185875af1925050503d8060008114613171576040519150601f19603f3d011682016040523d82523d6000602084013e613176565b606091505b50509050806131c75760405162461bcd60e51b815260206004820152601c60248201527f5041594241434b3a20726566756e6420756e7375636365737366756c0000000060448201526064016109af565b505b604080518681526020810185905287916001600160a01b038a16917fca92b037c5d17af773d2a576cd91e713e64b80af7c561456d811d12fc927960091016126b3565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60025460009060ff166132a85760405162461bcd60e51b815260206004820152601460248201527311115413d4d2550e881b9bdd08195b98589b195960621b60448201526064016109af565b60006132b48686613a03565b506000818152600f602052604081206003810154929750879350916001600160a01b031661337d576001600160a01b03861660009081526008602052604090205460ff166133395760405162461bcd60e51b815260206004820152601260248201527104445504f5349543a2062616420706f6f6c360741b60448201526064016109af565b50428082556001820180546001600160a01b03808b166001600160a01b031992831617909255600284019290925560038301805491881691909216179055846133ee565b60038201546001600160a01b031660009081526008602052604090205460ff166133de5760405162461bcd60e51b81526020600482015260126024820152714445504f5349543a2062616420706f6f6c3160701b60448201526064016109af565b5060038101546001600160a01b03165b8482600401600082825461340291906145ab565b925050819055506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015613449573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061346d9190614126565b90507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316816001600160a01b03160361361f576000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156134e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061350c9190614126565b90506135236001600160a01b0382168b308a613aa1565b60025460405163095ea7b360e01b8152600160501b9091046001600160a01b0390811660048301526024820189905282169063095ea7b3906044016020604051808303816000875af115801561357d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135a19190614482565b506002546001850154604051633b6191dd60e01b8152600160501b9092046001600160a01b0390811692633b6191dd926135e79286929116908c90600090600401614143565b600060405180830381600087803b15801561360157600080fd5b505af1158015613615573d6000803e3d6000fd5b505050505061372d565b806136356001600160a01b0382168b308a613aa1565b60025460405163095ea7b360e01b8152600160501b9091046001600160a01b0390811660048301526024820189905282169063095ea7b3906044016020604051808303816000875af115801561368f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136b39190614482565b506002546001850154604051633b6191dd60e01b8152600160501b9092046001600160a01b0390811692633b6191dd926136f99286929116908c90600090600401614143565b600060405180830381600087803b15801561371357600080fd5b505af1158015613727573d6000803e3d6000fd5b50505050505b87896001600160a01b03167f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a158860405161376991815260200190565b60405180910390a35095979650505050505050565b6003546040516331a9108f60e11b8152600481018390526001600160a01b0390911690636352211e90602401602060405180830381865afa1580156137c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137eb9190614126565b6001600160a01b0316826001600160a01b031614610b8b5760405162461bcd60e51b815260206004820152600d60248201526c2b20a624a220aa22a7aba722a960991b60448201526064016109af565b600560009054906101000a90046001600160a01b03166001600160a01b031663152111f7826040518263ffffffff1660e01b81526004016000604051808303818588803b15801561388b57600080fd5b505af115801561389f573d6000803e3d6000fd5b505050505050565b6040516001600160a01b038316602482015260448101829052612cdc90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613ad9565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b179052915160009283929087169161396691906145f9565b6000604051808303816000865af19150503d80600081146139a3576040519150601f19603f3d011682016040523d82523d6000602084013e6139a8565b606091505b50915091508180156139d25750805115806139d25750808060200190518101906139d29190614482565b6111235760405162461bcd60e51b8152602060048201526002602482015261534160f01b60448201526064016109af565b60008082600003613a89576003546040516335313c2160e11b81526001600160a01b03868116600483015290911690636a627842906024016020604051808303816000875af1158015613a5a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a7e919061449f565b915060019050613a9a565b613a93848461377e565b5081905060005b9250929050565b6040516001600160a01b0380851660248301528316604482015260648101829052610e6a9085906323b872dd60e01b906084016138d3565b6000613b2e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316613bae9092919063ffffffff16565b9050805160001480613b4f575080806020019051810190613b4f9190614482565b612cdc5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016109af565b6060611316848460008585600080866001600160a01b03168587604051613bd591906145f9565b60006040518083038185875af1925050503d8060008114613c12576040519150601f19603f3d011682016040523d82523d6000602084013e613c17565b606091505b5091509150613c2887838387613c33565b979650505050505050565b60608315613ca2578251600003613c9b576001600160a01b0385163b613c9b5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016109af565b5081611316565b6113168383815115613cb75781518083602001fd5b8060405162461bcd60e51b81526004016109af9190614615565b63ffffffff811681146112e157600080fd5b600060208284031215613cf557600080fd5b8135613d0081613cd1565b9392505050565b6001600160a01b03811681146112e157600080fd5b60008060408385031215613d2f57600080fd5b8235613d3a81613d07565b946020939093013593505050565b60008060408385031215613d5b57600080fd5b50508035926020909101359150565b80151581146112e157600080fd5b600060208284031215613d8a57600080fd5b8135613d0081613d6a565b600060208284031215613da757600080fd5b8135613d0081613d07565b60008060208385031215613dc557600080fd5b823567ffffffffffffffff80821115613ddd57600080fd5b818501915085601f830112613df157600080fd5b813581811115613e0057600080fd5b866020828501011115613e1257600080fd5b60209290920196919550909350505050565b60005b83811015613e3f578181015183820152602001613e27565b50506000910152565b60008151808452613e60816020860160208601613e24565b601f01601f19169290920160200192915050565b82151581526040602082015260006113166040830184613e48565b600060208284031215613ea157600080fd5b5035919050565b60008060008060808587031215613ebe57600080fd5b843593506020850135613ed081613d07565b93969395505050506040820135916060013590565b60008060408385031215613ef857600080fd5b8235613f0381613d07565b91506020830135613f1381613cd1565b809150509250929050565b600080600060608486031215613f3357600080fd5b833592506020840135613f4581613d07565b929592945050506040919091013590565b6020808252825182820181905260009190848201906040850190845b81811015613f975783516001600160a01b031683529284019291840191600101613f72565b50909695505050505050565b634e487b7160e01b600052601160045260246000fd5b63ffffffff818116838216028082169190828114613fd957613fd9613fa3565b505092915050565b634e487b7160e01b600052601260045260246000fd5b600063ffffffff8084168061400e5761400e613fe1565b92169190910492915050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156140595761405961401a565b604052919050565b600067ffffffffffffffff82111561407b5761407b61401a565b5060051b60200190565b6000602080838503121561409857600080fd5b823567ffffffffffffffff8111156140af57600080fd5b8301601f810185136140c057600080fd5b80356140d36140ce82614061565b614030565b81815260059190911b820183019083810190878311156140f257600080fd5b928401925b82841015613c28578335825292840192908401906140f7565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561413857600080fd5b8151613d0081613d07565b6001600160a01b0394851681529290931660208301526040820152901515606082015260800190565b60006001820161417e5761417e613fa3565b5060010190565b6020808252825182820181905260009190848201906040850190845b81811015613f9757835163ffffffff16835292840192918401916001016141a1565b600082601f8301126141d457600080fd5b815160206141e46140ce83614061565b82815260059290921b8401810191818101908684111561420357600080fd5b8286015b8481101561422757805161421a81613d07565b8352918301918301614207565b509695505050505050565b6000806040838503121561424557600080fd5b825167ffffffffffffffff8082111561425d57600080fd5b818501915085601f83011261427157600080fd5b815160206142816140ce83614061565b82815260059290921b840181019181810190898411156142a057600080fd5b948201945b838610156142ce5785518060060b81146142bf5760008081fd5b825294820194908201906142a5565b918801519196509093505050808211156142e757600080fd5b506142f4858286016141c3565b9150509250929050565b6000602080838503121561431157600080fd5b825167ffffffffffffffff81111561432857600080fd5b8301601f8101851361433957600080fd5b80516143476140ce82614061565b81815260059190911b8201830190838101908783111561436657600080fd5b928401925b82841015613c285783518252928401929084019061436b565b600063ffffffff80831681810361439d5761439d613fa3565b6001019392505050565b6020808252825182820181905260009190848201906040850190845b81811015613f97578351835292840192918401916001016143c3565b600080604083850312156143f257600080fd5b505080516020909101519092909150565b60006020828403121561441557600080fd5b8151613d0081613cd1565b8082028115828204841417610a9657610a96613fa3565b60008261444657614446613fe1565b500490565b63ffffffff82811682821603908082111561446857614468613fa3565b5092915050565b81810381811115610a9657610a96613fa3565b60006020828403121561449457600080fd5b8151613d0081613d6a565b6000602082840312156144b157600080fd5b5051919050565b600181815b808511156144f35781600019048211156144d9576144d9613fa3565b808516156144e657918102915b93841c93908002906144bd565b509250929050565b60008261450a57506001610a96565b8161451757506000610a96565b816001811461452d576002811461453757614553565b6001915050610a96565b60ff84111561454857614548613fa3565b50506001821b610a96565b5060208310610133831016604e8410600b8410161715614576575081810a610a96565b61458083836144b8565b806000190482111561459457614594613fa3565b029392505050565b6000610a9360ff8416836144fb565b80820180821115610a9657610a96613fa3565b6000602082840312156145d057600080fd5b815162ffffff81168114613d0057600080fd5b634e487b7160e01b600052603160045260246000fd5b6000825161460b818460208701613e24565b9190910192915050565b602081526000610a936020830184613e4856fea164736f6c6343000813000a

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

00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000e592427a0aece92de3edee1f18e0157c0586156400000000000000000000000085225ed797fd4128ac45a992c46ea4681a7a15da000000000000000000000000bf1858b24243ecbcf7d940f458e36cb7401c2366000000000000000000000000300648a601c584e6379fa0d6a31cbbfcca6177e4000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000003668747470733a2f2f6170692e6879706572626f6c696370726f746f636f6c2e636f6d2f6c6f616e732f6574682f6d657461646174612f00000000000000000000

-----Decoded View---------------
Arg [0] : _baseTokenURI (string): https://api.hyperbolicprotocol.com/loans/eth/metadata/
Arg [1] : __swapRouter (address): 0xE592427A0AEce92De3Edee1F18E0157C05861564
Arg [2] : __hype (address): 0x85225Ed797fd4128Ac45A992C46eA4681a7A15dA
Arg [3] : __twapUtils (address): 0xBf1858b24243Ecbcf7d940f458e36CB7401c2366
Arg [4] : __lendingRewards (address): 0x300648a601c584E6379fa0D6a31CbBFCcA6177e4
Arg [5] : __WETH (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [1] : 000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564
Arg [2] : 00000000000000000000000085225ed797fd4128ac45a992c46ea4681a7a15da
Arg [3] : 000000000000000000000000bf1858b24243ecbcf7d940f458e36cb7401c2366
Arg [4] : 000000000000000000000000300648a601c584e6379fa0d6a31cbbfcca6177e4
Arg [5] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000036
Arg [7] : 68747470733a2f2f6170692e6879706572626f6c696370726f746f636f6c2e63
Arg [8] : 6f6d2f6c6f616e732f6574682f6d657461646174612f00000000000000000000


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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