ETH Price: $2,476.96 (-8.16%)

Contract

0x3837Ddc0b0Ee70aA9007dB6bED3f40b9cAEbd202
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
0x60806040167822132023-03-08 8:00:11538 days ago1678262411IN
 Create: WrapperGateway
0 ETH0.0758176820.14623327

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
WrapperGateway

Compiler Version
v0.8.4+commit.c7e474f2

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 23 : WrapperGateway.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {IERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {SafeERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import {ERC721HolderUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

import {Errors} from "../libraries/helpers/Errors.sol";
import {ILendPool} from "../interfaces/ILendPool.sol";
import {ILendPoolLoan} from "../interfaces/ILendPoolLoan.sol";
import {ILendPoolAddressesProvider} from "../interfaces/ILendPoolAddressesProvider.sol";
import {IWrapperGateway} from "../interfaces/IWrapperGateway.sol";
import {IERC721Wrapper} from "../interfaces/IERC721Wrapper.sol";
import {DataTypes} from "../libraries/types/DataTypes.sol";
import {IWETHGateway} from "../interfaces/IWETHGateway.sol";

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

contract WrapperGateway is
  IWrapperGateway,
  ReentrancyGuardUpgradeable,
  ERC721HolderUpgradeable,
  EmergencyTokenRecoveryUpgradeable
{
  using SafeERC20Upgradeable for IERC20Upgradeable;

  ILendPoolAddressesProvider public addressProvider;
  IWETHGateway public wethGateway;

  IERC721Upgradeable public underlyingToken;
  IERC721Wrapper public wrappedToken;

  mapping(address => bool) internal _callerWhitelists;

  function initialize(
    address addressProvider_,
    address wethGateway_,
    address underlyingToken_,
    address wrappedToken_
  ) public initializer {
    __ReentrancyGuard_init();
    __ERC721Holder_init();
    __EmergencyTokenRecovery_init();

    addressProvider = ILendPoolAddressesProvider(addressProvider_);
    wethGateway = IWETHGateway(wethGateway_);

    underlyingToken = IERC721Upgradeable(underlyingToken_);
    wrappedToken = IERC721Wrapper(wrappedToken_);

    underlyingToken.setApprovalForAll(address(wrappedToken), true);

    wrappedToken.setApprovalForAll(address(_getLendPool()), true);
    wrappedToken.setApprovalForAll(address(wethGateway), true);
  }

  function _getLendPool() internal view returns (ILendPool) {
    return ILendPool(addressProvider.getLendPool());
  }

  function _getLendPoolLoan() internal view returns (ILendPoolLoan) {
    return ILendPoolLoan(addressProvider.getLendPoolLoan());
  }

  function authorizeLendPoolERC20(address[] calldata tokens) external nonReentrant onlyOwner {
    for (uint256 i = 0; i < tokens.length; i++) {
      IERC20Upgradeable(tokens[i]).approve(address(_getLendPool()), type(uint256).max);
    }
  }

  function authorizeCallerWhitelist(address[] calldata callers, bool flag) external nonReentrant onlyOwner {
    for (uint256 i = 0; i < callers.length; i++) {
      _callerWhitelists[callers[i]] = flag;
    }
  }

  function isCallerInWhitelist(address caller) external view returns (bool) {
    return _callerWhitelists[caller];
  }

  function _checkValidCallerAndOnBehalfOf(address onBehalfOf) internal view {
    require(
      (onBehalfOf == _msgSender()) || (_callerWhitelists[_msgSender()] == true),
      Errors.CALLER_NOT_ONBEHALFOF_OR_IN_WHITELIST
    );
  }

  function _depositUnderlyingToken(uint256 nftTokenId) internal {
    ILendPoolLoan cachedPoolLoan = _getLendPoolLoan();

    uint256 loanId = cachedPoolLoan.getCollateralLoanId(address(wrappedToken), nftTokenId);
    if (loanId != 0) {
      return;
    }

    underlyingToken.safeTransferFrom(msg.sender, address(this), nftTokenId);

    wrappedToken.mint(nftTokenId);
  }

  function borrow(
    address reserveAsset,
    uint256 amount,
    uint256 nftTokenId,
    address onBehalfOf,
    uint16 referralCode
  ) external override nonReentrant {
    _checkValidCallerAndOnBehalfOf(onBehalfOf);

    ILendPool cachedPool = _getLendPool();

    _depositUnderlyingToken(nftTokenId);

    cachedPool.borrow(reserveAsset, amount, address(wrappedToken), nftTokenId, onBehalfOf, referralCode);

    IERC20Upgradeable(reserveAsset).transfer(onBehalfOf, amount);
  }

  function batchBorrow(
    address[] calldata reserveAssets,
    uint256[] calldata amounts,
    uint256[] calldata nftTokenIds,
    address onBehalfOf,
    uint16 referralCode
  ) external override nonReentrant {
    require(nftTokenIds.length == reserveAssets.length, "WrapperGateway: inconsistent reserveAssets length");
    require(nftTokenIds.length == amounts.length, "WrapperGateway: inconsistent amounts length");

    _checkValidCallerAndOnBehalfOf(onBehalfOf);

    ILendPool cachedPool = _getLendPool();

    for (uint256 i = 0; i < nftTokenIds.length; i++) {
      _depositUnderlyingToken(nftTokenIds[i]);

      cachedPool.borrow(reserveAssets[i], amounts[i], address(wrappedToken), nftTokenIds[i], onBehalfOf, referralCode);

      IERC20Upgradeable(reserveAssets[i]).transfer(onBehalfOf, amounts[i]);
    }
  }

  function _withdrawUnderlyingToken(uint256 nftTokenId, address onBehalfOf) internal {
    address owner = wrappedToken.ownerOf(nftTokenId);
    require(owner == _msgSender(), "WrapperGateway: caller is not owner");
    require(owner == onBehalfOf, "WrapperGateway: onBehalfOf is not owner");

    wrappedToken.safeTransferFrom(onBehalfOf, address(this), nftTokenId);
    wrappedToken.burn(nftTokenId);

    underlyingToken.safeTransferFrom(address(this), owner, nftTokenId);
  }

  function repay(uint256 nftTokenId, uint256 amount) external override nonReentrant returns (uint256, bool) {
    return _repay(nftTokenId, amount);
  }

  function batchRepay(uint256[] calldata nftTokenIds, uint256[] calldata amounts)
    external
    override
    nonReentrant
    returns (uint256[] memory, bool[] memory)
  {
    require(nftTokenIds.length == amounts.length, "WrapperGateway: inconsistent amounts length");

    uint256[] memory repayAmounts = new uint256[](nftTokenIds.length);
    bool[] memory repayAlls = new bool[](nftTokenIds.length);

    for (uint256 i = 0; i < nftTokenIds.length; i++) {
      (repayAmounts[i], repayAlls[i]) = _repay(nftTokenIds[i], amounts[i]);
    }

    return (repayAmounts, repayAlls);
  }

  function _repay(uint256 nftTokenId, uint256 amount) internal returns (uint256, bool) {
    ILendPool cachedPool = _getLendPool();
    ILendPoolLoan cachedPoolLoan = _getLendPoolLoan();

    uint256 loanId = cachedPoolLoan.getCollateralLoanId(address(wrappedToken), nftTokenId);
    require(loanId != 0, "WrapperGateway: no loan with such nftTokenId");
    (, , address reserve, ) = cachedPoolLoan.getLoanCollateralAndReserve(loanId);
    (, uint256 debt) = cachedPoolLoan.getLoanReserveBorrowAmount(loanId);
    address borrower = cachedPoolLoan.borrowerOf(loanId);

    if (amount > debt) {
      amount = debt;
    }

    IERC20Upgradeable(reserve).transferFrom(msg.sender, address(this), amount);

    (uint256 paybackAmount, bool burn) = cachedPool.repay(address(wrappedToken), nftTokenId, amount);

    if (burn) {
      require(borrower == _msgSender(), "WrapperGateway: caller is not borrower");
      _withdrawUnderlyingToken(nftTokenId, borrower);
    }

    return (paybackAmount, burn);
  }

  function auction(
    uint256 nftTokenId,
    uint256 bidPrice,
    address onBehalfOf
  ) external override nonReentrant {
    _checkValidCallerAndOnBehalfOf(onBehalfOf);

    ILendPool cachedPool = _getLendPool();
    ILendPoolLoan cachedPoolLoan = _getLendPoolLoan();

    uint256 loanId = cachedPoolLoan.getCollateralLoanId(address(wrappedToken), nftTokenId);
    require(loanId != 0, "WrapperGateway: no loan with such nftTokenId");

    (, , address reserve, ) = cachedPoolLoan.getLoanCollateralAndReserve(loanId);

    IERC20Upgradeable(reserve).transferFrom(msg.sender, address(this), bidPrice);

    cachedPool.auction(address(wrappedToken), nftTokenId, bidPrice, onBehalfOf);
  }

  function redeem(
    uint256 nftTokenId,
    uint256 amount,
    uint256 bidFine
  ) external override nonReentrant returns (uint256) {
    ILendPool cachedPool = _getLendPool();
    ILendPoolLoan cachedPoolLoan = _getLendPoolLoan();

    uint256 loanId = cachedPoolLoan.getCollateralLoanId(address(wrappedToken), nftTokenId);
    require(loanId != 0, "WrapperGateway: no loan with such nftTokenId");

    DataTypes.LoanData memory loan = cachedPoolLoan.getLoan(loanId);

    IERC20Upgradeable(loan.reserveAsset).transferFrom(msg.sender, address(this), (amount + bidFine));

    uint256 paybackAmount = cachedPool.redeem(address(wrappedToken), nftTokenId, amount, bidFine);

    if ((amount + bidFine) > paybackAmount) {
      IERC20Upgradeable(loan.reserveAsset).safeTransfer(msg.sender, ((amount + bidFine) - paybackAmount));
    }

    return paybackAmount;
  }

  function liquidate(uint256 nftTokenId, uint256 amount) external override nonReentrant returns (uint256) {
    ILendPool cachedPool = _getLendPool();
    ILendPoolLoan cachedPoolLoan = _getLendPoolLoan();

    uint256 loanId = cachedPoolLoan.getCollateralLoanId(address(wrappedToken), nftTokenId);
    require(loanId != 0, "WrapperGateway: no loan with such nftTokenId");

    DataTypes.LoanData memory loan = cachedPoolLoan.getLoan(loanId);
    require(loan.bidderAddress == _msgSender(), "WrapperGateway: caller is not bidder");

    if (amount > 0) {
      IERC20Upgradeable(loan.reserveAsset).transferFrom(msg.sender, address(this), amount);
    }

    uint256 extraRetAmount = cachedPool.liquidate(address(wrappedToken), nftTokenId, amount);

    _withdrawUnderlyingToken(nftTokenId, loan.bidderAddress);

    if (amount > extraRetAmount) {
      IERC20Upgradeable(loan.reserveAsset).safeTransfer(msg.sender, (amount - extraRetAmount));
    }

    return (extraRetAmount);
  }

  function borrowETH(
    uint256 amount,
    uint256 nftTokenId,
    address onBehalfOf,
    uint16 referralCode
  ) external override nonReentrant {
    _checkValidCallerAndOnBehalfOf(onBehalfOf);

    _depositUnderlyingToken(nftTokenId);

    wethGateway.borrowETH(amount, address(wrappedToken), nftTokenId, onBehalfOf, referralCode);
  }

  function batchBorrowETH(
    uint256[] calldata amounts,
    uint256[] calldata nftTokenIds,
    address onBehalfOf,
    uint16 referralCode
  ) external override nonReentrant {
    require(nftTokenIds.length == amounts.length, "inconsistent amounts length");

    _checkValidCallerAndOnBehalfOf(onBehalfOf);

    address[] memory nftAssets = new address[](nftTokenIds.length);
    for (uint256 i = 0; i < nftTokenIds.length; i++) {
      nftAssets[i] = address(wrappedToken);
      _depositUnderlyingToken(nftTokenIds[i]);
    }

    wethGateway.batchBorrowETH(amounts, nftAssets, nftTokenIds, onBehalfOf, referralCode);
  }

  function repayETH(uint256 nftTokenId, uint256 amount) external payable override nonReentrant returns (uint256, bool) {
    (uint256 paybackAmount, bool burn) = _repayETH(nftTokenId, amount, 0);

    // refund remaining dust eth
    if (msg.value > paybackAmount) {
      _safeTransferETH(msg.sender, msg.value - paybackAmount);
    }

    return (paybackAmount, burn);
  }

  function batchRepayETH(uint256[] calldata nftTokenIds, uint256[] calldata amounts)
    external
    payable
    override
    nonReentrant
    returns (uint256[] memory, bool[] memory)
  {
    require(nftTokenIds.length == amounts.length, "inconsistent amounts length");

    uint256[] memory repayAmounts = new uint256[](nftTokenIds.length);
    bool[] memory repayAlls = new bool[](nftTokenIds.length);
    uint256 allRepayAmount = 0;

    for (uint256 i = 0; i < nftTokenIds.length; i++) {
      (repayAmounts[i], repayAlls[i]) = _repayETH(nftTokenIds[i], amounts[i], allRepayAmount);
      allRepayAmount += repayAmounts[i];
    }

    // refund remaining dust eth
    if (msg.value > allRepayAmount) {
      _safeTransferETH(msg.sender, msg.value - allRepayAmount);
    }

    return (repayAmounts, repayAlls);
  }

  function _repayETH(
    uint256 nftTokenId,
    uint256 amount,
    uint256 accAmount
  ) internal returns (uint256, bool) {
    ILendPoolLoan cachedPoolLoan = _getLendPoolLoan();

    uint256 loanId = cachedPoolLoan.getCollateralLoanId(address(wrappedToken), nftTokenId);
    require(loanId != 0, "WrapperGateway: no loan with such nftTokenId");

    address borrower = cachedPoolLoan.borrowerOf(loanId);
    require(borrower == _msgSender(), "WrapperGateway: caller is not borrower");

    (, uint256 repayDebtAmount) = cachedPoolLoan.getLoanReserveBorrowAmount(loanId);
    if (amount < repayDebtAmount) {
      repayDebtAmount = amount;
    }

    require(msg.value >= (accAmount + repayDebtAmount), "msg.value is less than repay amount");

    (uint256 paybackAmount, bool burn) = wethGateway.repayETH{value: repayDebtAmount}(
      address(wrappedToken),
      nftTokenId,
      amount
    );

    if (burn) {
      _withdrawUnderlyingToken(nftTokenId, borrower);
    }

    return (paybackAmount, burn);
  }

  function auctionETH(uint256 nftTokenId, address onBehalfOf) external payable override nonReentrant {
    _checkValidCallerAndOnBehalfOf(onBehalfOf);

    wethGateway.auctionETH{value: msg.value}(address(wrappedToken), nftTokenId, onBehalfOf);
  }

  function redeemETH(
    uint256 nftTokenId,
    uint256 amount,
    uint256 bidFine
  ) external payable override nonReentrant returns (uint256) {
    ILendPoolLoan cachedPoolLoan = _getLendPoolLoan();

    uint256 loanId = cachedPoolLoan.getCollateralLoanId(address(wrappedToken), nftTokenId);
    require(loanId != 0, "WrapperGateway: no loan with such nftTokenId");

    //DataTypes.LoanData memory loan = cachedPoolLoan.getLoan(loanId);

    uint256 paybackAmount = wethGateway.redeemETH{value: msg.value}(address(wrappedToken), nftTokenId, amount, bidFine);

    // refund remaining dust eth
    if (msg.value > paybackAmount) {
      _safeTransferETH(msg.sender, msg.value - paybackAmount);
    }

    return paybackAmount;
  }

  function liquidateETH(uint256 nftTokenId) external payable override nonReentrant returns (uint256) {
    ILendPoolLoan cachedPoolLoan = _getLendPoolLoan();

    uint256 loanId = cachedPoolLoan.getCollateralLoanId(address(wrappedToken), nftTokenId);
    require(loanId != 0, "WrapperGateway: no loan with such nftTokenId");

    DataTypes.LoanData memory loan = cachedPoolLoan.getLoan(loanId);
    require(loan.bidderAddress == _msgSender(), "WrapperGateway: caller is not bidder");

    uint256 extraAmount = wethGateway.liquidateETH{value: msg.value}(address(wrappedToken), nftTokenId);

    _withdrawUnderlyingToken(nftTokenId, loan.bidderAddress);

    // refund remaining dust eth
    if (msg.value > extraAmount) {
      _safeTransferETH(msg.sender, msg.value - extraAmount);
    }

    return extraAmount;
  }

  /**
   * @dev transfer ETH to an address, revert if it fails.
   * @param to recipient of the transfer
   * @param value the amount to send
   */
  function _safeTransferETH(address to, uint256 value) internal {
    (bool success, ) = to.call{value: value}(new bytes(0));
    require(success, "ETH_TRANSFER_FAILED");
  }

  /**
   * @dev
   */
  receive() external payable {}

  /**
   * @dev Revert fallback calls
   */
  fallback() external payable {
    revert("Fallback not allowed");
  }
}

File 2 of 23 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Context_init_unchained();
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing 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);
    }
    uint256[49] private __gap;
}

File 3 of 23 : IERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721Upgradeable is IERC165Upgradeable {
    /**
     * @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`, 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 be 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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * 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 Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

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

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

File 4 of 23 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @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 `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, 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 `sender` to `recipient` 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 sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

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

File 5 of 23 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable {
    using AddressUpgradeable for address;

    function safeTransfer(
        IERC20Upgradeable token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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));
    }

    function safeIncreaseAllowance(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @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(IERC20Upgradeable 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");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 6 of 23 : ERC721HolderUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol)

pragma solidity ^0.8.0;

import "../IERC721ReceiverUpgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC721Receiver} interface.
 *
 * Accepts all token transfers.
 * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
 */
contract ERC721HolderUpgradeable is Initializable, IERC721ReceiverUpgradeable {
    function __ERC721Holder_init() internal onlyInitializing {
        __ERC721Holder_init_unchained();
    }

    function __ERC721Holder_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC721Receiver-onERC721Received}.
     *
     * Always returns `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address,
        address,
        uint256,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC721Received.selector;
    }
    uint256[50] private __gap;
}

File 7 of 23 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

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

    uint256 private _status;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

        _;

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

File 8 of 23 : Errors.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

/**
 * @title Errors library
 * @author Bend
 * @notice Defines the error messages emitted by the different contracts of the Bend protocol
 */
library Errors {
  enum ReturnCode {
    SUCCESS,
    FAILED
  }

  string public constant SUCCESS = "0";

  //common errors
  string public constant CALLER_NOT_POOL_ADMIN = "100"; // 'The caller must be the pool admin'
  string public constant CALLER_NOT_ADDRESS_PROVIDER = "101";
  string public constant INVALID_FROM_BALANCE_AFTER_TRANSFER = "102";
  string public constant INVALID_TO_BALANCE_AFTER_TRANSFER = "103";
  string public constant CALLER_NOT_ONBEHALFOF_OR_IN_WHITELIST = "104";

  //math library erros
  string public constant MATH_MULTIPLICATION_OVERFLOW = "200";
  string public constant MATH_ADDITION_OVERFLOW = "201";
  string public constant MATH_DIVISION_BY_ZERO = "202";

  //validation & check errors
  string public constant VL_INVALID_AMOUNT = "301"; // 'Amount must be greater than 0'
  string public constant VL_NO_ACTIVE_RESERVE = "302"; // 'Action requires an active reserve'
  string public constant VL_RESERVE_FROZEN = "303"; // 'Action cannot be performed because the reserve is frozen'
  string public constant VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = "304"; // 'User cannot withdraw more than the available balance'
  string public constant VL_BORROWING_NOT_ENABLED = "305"; // 'Borrowing is not enabled'
  string public constant VL_COLLATERAL_BALANCE_IS_0 = "306"; // 'The collateral balance is 0'
  string public constant VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = "307"; // 'Health factor is lesser than the liquidation threshold'
  string public constant VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = "308"; // 'There is not enough collateral to cover a new borrow'
  string public constant VL_NO_DEBT_OF_SELECTED_TYPE = "309"; // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'
  string public constant VL_NO_ACTIVE_NFT = "310";
  string public constant VL_NFT_FROZEN = "311";
  string public constant VL_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = "312"; // 'User did not borrow the specified currency'
  string public constant VL_INVALID_HEALTH_FACTOR = "313";
  string public constant VL_INVALID_ONBEHALFOF_ADDRESS = "314";
  string public constant VL_INVALID_TARGET_ADDRESS = "315";
  string public constant VL_INVALID_RESERVE_ADDRESS = "316";
  string public constant VL_SPECIFIED_LOAN_NOT_BORROWED_BY_USER = "317";
  string public constant VL_SPECIFIED_RESERVE_NOT_BORROWED_BY_USER = "318";
  string public constant VL_HEALTH_FACTOR_HIGHER_THAN_LIQUIDATION_THRESHOLD = "319";

  //lend pool errors
  string public constant LP_CALLER_NOT_LEND_POOL_CONFIGURATOR = "400"; // 'The caller of the function is not the lending pool configurator'
  string public constant LP_IS_PAUSED = "401"; // 'Pool is paused'
  string public constant LP_NO_MORE_RESERVES_ALLOWED = "402";
  string public constant LP_NOT_CONTRACT = "403";
  string public constant LP_BORROW_NOT_EXCEED_LIQUIDATION_THRESHOLD = "404";
  string public constant LP_BORROW_IS_EXCEED_LIQUIDATION_PRICE = "405";
  string public constant LP_NO_MORE_NFTS_ALLOWED = "406";
  string public constant LP_INVALIED_USER_NFT_AMOUNT = "407";
  string public constant LP_INCONSISTENT_PARAMS = "408";
  string public constant LP_NFT_IS_NOT_USED_AS_COLLATERAL = "409";
  string public constant LP_CALLER_MUST_BE_AN_BTOKEN = "410";
  string public constant LP_INVALIED_NFT_AMOUNT = "411";
  string public constant LP_NFT_HAS_USED_AS_COLLATERAL = "412";
  string public constant LP_DELEGATE_CALL_FAILED = "413";
  string public constant LP_AMOUNT_LESS_THAN_EXTRA_DEBT = "414";
  string public constant LP_AMOUNT_LESS_THAN_REDEEM_THRESHOLD = "415";
  string public constant LP_AMOUNT_GREATER_THAN_MAX_REPAY = "416";
  string public constant LP_NFT_TOKEN_ID_EXCEED_MAX_LIMIT = "417";
  string public constant LP_NFT_SUPPLY_NUM_EXCEED_MAX_LIMIT = "418";
  string public constant LP_CALLER_NOT_VALID_INTERCEPTOR = "419";
  string public constant LP_CALLER_NOT_VALID_LOCKER = "420";

  //lend pool loan errors
  string public constant LPL_INVALID_LOAN_STATE = "480";
  string public constant LPL_INVALID_LOAN_AMOUNT = "481";
  string public constant LPL_INVALID_TAKEN_AMOUNT = "482";
  string public constant LPL_AMOUNT_OVERFLOW = "483";
  string public constant LPL_BID_PRICE_LESS_THAN_LIQUIDATION_PRICE = "484";
  string public constant LPL_BID_PRICE_LESS_THAN_HIGHEST_PRICE = "485";
  string public constant LPL_BID_REDEEM_DURATION_HAS_END = "486";
  string public constant LPL_BID_USER_NOT_SAME = "487";
  string public constant LPL_BID_REPAY_AMOUNT_NOT_ENOUGH = "488";
  string public constant LPL_BID_AUCTION_DURATION_HAS_END = "489";
  string public constant LPL_BID_AUCTION_DURATION_NOT_END = "490";
  string public constant LPL_BID_PRICE_LESS_THAN_BORROW = "491";
  string public constant LPL_INVALID_BIDDER_ADDRESS = "492";
  string public constant LPL_AMOUNT_LESS_THAN_BID_FINE = "493";
  string public constant LPL_INVALID_BID_FINE = "494";

  //common token errors
  string public constant CT_CALLER_MUST_BE_LEND_POOL = "500"; // 'The caller of this function must be a lending pool'
  string public constant CT_INVALID_MINT_AMOUNT = "501"; //invalid amount to mint
  string public constant CT_INVALID_BURN_AMOUNT = "502"; //invalid amount to burn
  string public constant CT_BORROW_ALLOWANCE_NOT_ENOUGH = "503";

  //reserve logic errors
  string public constant RL_RESERVE_ALREADY_INITIALIZED = "601"; // 'Reserve has already been initialized'
  string public constant RL_LIQUIDITY_INDEX_OVERFLOW = "602"; //  Liquidity index overflows uint128
  string public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = "603"; //  Variable borrow index overflows uint128
  string public constant RL_LIQUIDITY_RATE_OVERFLOW = "604"; //  Liquidity rate overflows uint128
  string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = "605"; //  Variable borrow rate overflows uint128

  //configure errors
  string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = "700"; // 'The liquidity of the reserve needs to be 0'
  string public constant LPC_INVALID_CONFIGURATION = "701"; // 'Invalid risk parameters for the reserve'
  string public constant LPC_CALLER_NOT_EMERGENCY_ADMIN = "702"; // 'The caller must be the emergency admin'
  string public constant LPC_INVALIED_BNFT_ADDRESS = "703";
  string public constant LPC_INVALIED_LOAN_ADDRESS = "704";
  string public constant LPC_NFT_LIQUIDITY_NOT_0 = "705";

  //reserve config errors
  string public constant RC_INVALID_LTV = "730";
  string public constant RC_INVALID_LIQ_THRESHOLD = "731";
  string public constant RC_INVALID_LIQ_BONUS = "732";
  string public constant RC_INVALID_DECIMALS = "733";
  string public constant RC_INVALID_RESERVE_FACTOR = "734";
  string public constant RC_INVALID_REDEEM_DURATION = "735";
  string public constant RC_INVALID_AUCTION_DURATION = "736";
  string public constant RC_INVALID_REDEEM_FINE = "737";
  string public constant RC_INVALID_REDEEM_THRESHOLD = "738";
  string public constant RC_INVALID_MIN_BID_FINE = "739";
  string public constant RC_INVALID_MAX_BID_FINE = "740";

  //address provider erros
  string public constant LPAPR_PROVIDER_NOT_REGISTERED = "760"; // 'Provider is not registered'
  string public constant LPAPR_INVALID_ADDRESSES_PROVIDER_ID = "761";
}

File 9 of 23 : ILendPool.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

import {ILendPoolAddressesProvider} from "./ILendPoolAddressesProvider.sol";
import {DataTypes} from "../libraries/types/DataTypes.sol";

interface ILendPool {
  /**
   * @dev Emitted on deposit()
   * @param user The address initiating the deposit
   * @param amount The amount deposited
   * @param reserve The address of the underlying asset of the reserve
   * @param onBehalfOf The beneficiary of the deposit, receiving the bTokens
   * @param referral The referral code used
   **/
  event Deposit(
    address user,
    address indexed reserve,
    uint256 amount,
    address indexed onBehalfOf,
    uint16 indexed referral
  );

  /**
   * @dev Emitted on withdraw()
   * @param user The address initiating the withdrawal, owner of bTokens
   * @param reserve The address of the underlyng asset being withdrawn
   * @param amount The amount to be withdrawn
   * @param to Address that will receive the underlying
   **/
  event Withdraw(address indexed user, address indexed reserve, uint256 amount, address indexed to);

  /**
   * @dev Emitted on borrow() when loan needs to be opened
   * @param user The address of the user initiating the borrow(), receiving the funds
   * @param reserve The address of the underlying asset being borrowed
   * @param amount The amount borrowed out
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token id of the underlying NFT used as collateral
   * @param onBehalfOf The address that will be getting the loan
   * @param referral The referral code used
   **/
  event Borrow(
    address user,
    address indexed reserve,
    uint256 amount,
    address nftAsset,
    uint256 nftTokenId,
    address indexed onBehalfOf,
    uint256 borrowRate,
    uint256 loanId,
    uint16 indexed referral
  );

  /**
   * @dev Emitted on repay()
   * @param user The address of the user initiating the repay(), providing the funds
   * @param reserve The address of the underlying asset of the reserve
   * @param amount The amount repaid
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token id of the underlying NFT used as collateral
   * @param borrower The beneficiary of the repayment, getting his debt reduced
   * @param loanId The loan ID of the NFT loans
   **/
  event Repay(
    address user,
    address indexed reserve,
    uint256 amount,
    address indexed nftAsset,
    uint256 nftTokenId,
    address indexed borrower,
    uint256 loanId
  );

  /**
   * @dev Emitted when a borrower's loan is auctioned.
   * @param user The address of the user initiating the auction
   * @param reserve The address of the underlying asset of the reserve
   * @param bidPrice The price of the underlying reserve given by the bidder
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token id of the underlying NFT used as collateral
   * @param onBehalfOf The address that will be getting the NFT
   * @param loanId The loan ID of the NFT loans
   **/
  event Auction(
    address user,
    address indexed reserve,
    uint256 bidPrice,
    address indexed nftAsset,
    uint256 nftTokenId,
    address onBehalfOf,
    address indexed borrower,
    uint256 loanId
  );

  /**
   * @dev Emitted on redeem()
   * @param user The address of the user initiating the redeem(), providing the funds
   * @param reserve The address of the underlying asset of the reserve
   * @param borrowAmount The borrow amount repaid
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token id of the underlying NFT used as collateral
   * @param loanId The loan ID of the NFT loans
   **/
  event Redeem(
    address user,
    address indexed reserve,
    uint256 borrowAmount,
    uint256 fineAmount,
    address indexed nftAsset,
    uint256 nftTokenId,
    address indexed borrower,
    uint256 loanId
  );

  /**
   * @dev Emitted when a borrower's loan is liquidated.
   * @param user The address of the user initiating the auction
   * @param reserve The address of the underlying asset of the reserve
   * @param repayAmount The amount of reserve repaid by the liquidator
   * @param remainAmount The amount of reserve received by the borrower
   * @param loanId The loan ID of the NFT loans
   **/
  event Liquidate(
    address user,
    address indexed reserve,
    uint256 repayAmount,
    uint256 remainAmount,
    address indexed nftAsset,
    uint256 nftTokenId,
    address indexed borrower,
    uint256 loanId
  );

  /**
   * @dev Emitted when the pause is triggered.
   */
  event Paused();

  /**
   * @dev Emitted when the pause is lifted.
   */
  event Unpaused();

  /**
   * @dev Emitted when the pause time is updated.
   */
  event PausedTimeUpdated(uint256 startTime, uint256 durationTime);

  /**
   * @dev Emitted when the state of a reserve is updated. NOTE: This event is actually declared
   * in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal,
   * the event will actually be fired by the LendPool contract. The event is therefore replicated here so it
   * gets added to the LendPool ABI
   * @param reserve The address of the underlying asset of the reserve
   * @param liquidityRate The new liquidity rate
   * @param variableBorrowRate The new variable borrow rate
   * @param liquidityIndex The new liquidity index
   * @param variableBorrowIndex The new variable borrow index
   **/
  event ReserveDataUpdated(
    address indexed reserve,
    uint256 liquidityRate,
    uint256 variableBorrowRate,
    uint256 liquidityIndex,
    uint256 variableBorrowIndex
  );

  /**
   * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying bTokens.
   * - E.g. User deposits 100 USDC and gets in return 100 bUSDC
   * @param reserve The address of the underlying asset to deposit
   * @param amount The amount to be deposited
   * @param onBehalfOf The address that will receive the bTokens, same as msg.sender if the user
   *   wants to receive them on his own wallet, or a different address if the beneficiary of bTokens
   *   is a different wallet
   * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
   *   0 if the action is executed directly by the user, without any middle-man
   **/
  function deposit(
    address reserve,
    uint256 amount,
    address onBehalfOf,
    uint16 referralCode
  ) external;

  /**
   * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent bTokens owned
   * E.g. User has 100 bUSDC, calls withdraw() and receives 100 USDC, burning the 100 bUSDC
   * @param reserve The address of the underlying asset to withdraw
   * @param amount The underlying amount to be withdrawn
   *   - Send the value type(uint256).max in order to withdraw the whole bToken balance
   * @param to Address that will receive the underlying, same as msg.sender if the user
   *   wants to receive it on his own wallet, or a different address if the beneficiary is a
   *   different wallet
   * @return The final amount withdrawn
   **/
  function withdraw(
    address reserve,
    uint256 amount,
    address to
  ) external returns (uint256);

  /**
   * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower
   * already deposited enough collateral
   * - E.g. User borrows 100 USDC, receiving the 100 USDC in his wallet
   *   and lock collateral asset in contract
   * @param reserveAsset The address of the underlying asset to borrow
   * @param amount The amount to be borrowed
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token ID of the underlying NFT used as collateral
   * @param onBehalfOf Address of the user who will receive the loan. Should be the address of the borrower itself
   * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator
   * if he has been given credit delegation allowance
   * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
   *   0 if the action is executed directly by the user, without any middle-man
   **/
  function borrow(
    address reserveAsset,
    uint256 amount,
    address nftAsset,
    uint256 nftTokenId,
    address onBehalfOf,
    uint16 referralCode
  ) external;

  function batchBorrow(
    address[] calldata assets,
    uint256[] calldata amounts,
    address[] calldata nftAssets,
    uint256[] calldata nftTokenIds,
    address onBehalfOf,
    uint16 referralCode
  ) external;

  /**
   * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent loan owned
   * - E.g. User repays 100 USDC, burning loan and receives collateral asset
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token ID of the underlying NFT used as collateral
   * @param amount The amount to repay
   * @return The final amount repaid, loan is burned or not
   **/
  function repay(
    address nftAsset,
    uint256 nftTokenId,
    uint256 amount
  ) external returns (uint256, bool);

  function batchRepay(
    address[] calldata nftAssets,
    uint256[] calldata nftTokenIds,
    uint256[] calldata amounts
  ) external returns (uint256[] memory, bool[] memory);

  /**
   * @dev Function to auction a non-healthy position collateral-wise
   * - The caller (liquidator) want to buy collateral asset of the user getting liquidated
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token ID of the underlying NFT used as collateral
   * @param bidPrice The bid price of the liquidator want to buy the underlying NFT
   * @param onBehalfOf Address of the user who will get the underlying NFT, same as msg.sender if the user
   *   wants to receive them on his own wallet, or a different address if the beneficiary of NFT
   *   is a different wallet
   **/
  function auction(
    address nftAsset,
    uint256 nftTokenId,
    uint256 bidPrice,
    address onBehalfOf
  ) external;

  /**
   * @notice Redeem a NFT loan which state is in Auction
   * - E.g. User repays 100 USDC, burning loan and receives collateral asset
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token ID of the underlying NFT used as collateral
   * @param amount The amount to repay the debt
   * @param bidFine The amount of bid fine
   **/
  function redeem(
    address nftAsset,
    uint256 nftTokenId,
    uint256 amount,
    uint256 bidFine
  ) external returns (uint256);

  /**
   * @dev Function to liquidate a non-healthy position collateral-wise
   * - The caller (liquidator) buy collateral asset of the user getting liquidated, and receives
   *   the collateral asset
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token ID of the underlying NFT used as collateral
   **/
  function liquidate(
    address nftAsset,
    uint256 nftTokenId,
    uint256 amount
  ) external returns (uint256);

  /**
   * @dev Validates and finalizes an bToken transfer
   * - Only callable by the overlying bToken of the `asset`
   * @param asset The address of the underlying asset of the bToken
   * @param from The user from which the bTokens are transferred
   * @param to The user receiving the bTokens
   * @param amount The amount being transferred/withdrawn
   * @param balanceFromBefore The bToken balance of the `from` user before the transfer
   * @param balanceToBefore The bToken balance of the `to` user before the transfer
   */
  function finalizeTransfer(
    address asset,
    address from,
    address to,
    uint256 amount,
    uint256 balanceFromBefore,
    uint256 balanceToBefore
  ) external view;

  function getReserveConfiguration(address asset) external view returns (DataTypes.ReserveConfigurationMap memory);

  function getNftConfiguration(address asset) external view returns (DataTypes.NftConfigurationMap memory);

  /**
   * @dev Returns the normalized income normalized income of the reserve
   * @param asset The address of the underlying asset of the reserve
   * @return The reserve's normalized income
   */
  function getReserveNormalizedIncome(address asset) external view returns (uint256);

  /**
   * @dev Returns the normalized variable debt per unit of asset
   * @param asset The address of the underlying asset of the reserve
   * @return The reserve normalized variable debt
   */
  function getReserveNormalizedVariableDebt(address asset) external view returns (uint256);

  /**
   * @dev Returns the state and configuration of the reserve
   * @param asset The address of the underlying asset of the reserve
   * @return The state of the reserve
   **/
  function getReserveData(address asset) external view returns (DataTypes.ReserveData memory);

  function getReservesList() external view returns (address[] memory);

  function getNftData(address asset) external view returns (DataTypes.NftData memory);

  /**
   * @dev Returns the loan data of the NFT
   * @param nftAsset The address of the NFT
   * @param reserveAsset The address of the Reserve
   * @return totalCollateralInETH the total collateral in ETH of the NFT
   * @return totalCollateralInReserve the total collateral in Reserve of the NFT
   * @return availableBorrowsInETH the borrowing power in ETH of the NFT
   * @return availableBorrowsInReserve the borrowing power in Reserve of the NFT
   * @return ltv the loan to value of the user
   * @return liquidationThreshold the liquidation threshold of the NFT
   * @return liquidationBonus the liquidation bonus of the NFT
   **/
  function getNftCollateralData(address nftAsset, address reserveAsset)
    external
    view
    returns (
      uint256 totalCollateralInETH,
      uint256 totalCollateralInReserve,
      uint256 availableBorrowsInETH,
      uint256 availableBorrowsInReserve,
      uint256 ltv,
      uint256 liquidationThreshold,
      uint256 liquidationBonus
    );

  /**
   * @dev Returns the debt data of the NFT
   * @param nftAsset The address of the NFT
   * @param nftTokenId The token id of the NFT
   * @return loanId the loan id of the NFT
   * @return reserveAsset the address of the Reserve
   * @return totalCollateral the total power of the NFT
   * @return totalDebt the total debt of the NFT
   * @return availableBorrows the borrowing power left of the NFT
   * @return healthFactor the current health factor of the NFT
   **/
  function getNftDebtData(address nftAsset, uint256 nftTokenId)
    external
    view
    returns (
      uint256 loanId,
      address reserveAsset,
      uint256 totalCollateral,
      uint256 totalDebt,
      uint256 availableBorrows,
      uint256 healthFactor
    );

  /**
   * @dev Returns the auction data of the NFT
   * @param nftAsset The address of the NFT
   * @param nftTokenId The token id of the NFT
   * @return loanId the loan id of the NFT
   * @return bidderAddress the highest bidder address of the loan
   * @return bidPrice the highest bid price in Reserve of the loan
   * @return bidBorrowAmount the borrow amount in Reserve of the loan
   * @return bidFine the penalty fine of the loan
   **/
  function getNftAuctionData(address nftAsset, uint256 nftTokenId)
    external
    view
    returns (
      uint256 loanId,
      address bidderAddress,
      uint256 bidPrice,
      uint256 bidBorrowAmount,
      uint256 bidFine
    );

  function getNftAuctionEndTime(address nftAsset, uint256 nftTokenId)
    external
    view
    returns (
      uint256 loanId,
      uint256 bidStartTimestamp,
      uint256 bidEndTimestamp,
      uint256 redeemEndTimestamp
    );

  function getNftLiquidatePrice(address nftAsset, uint256 nftTokenId)
    external
    view
    returns (uint256 liquidatePrice, uint256 paybackAmount);

  function getNftsList() external view returns (address[] memory);

  /**
   * @dev Set the _pause state of a reserve
   * - Only callable by the LendPool contract
   * @param val `true` to pause the reserve, `false` to un-pause it
   */
  function setPause(bool val) external;

  function setPausedTime(uint256 startTime, uint256 durationTime) external;

  /**
   * @dev Returns if the LendPool is paused
   */
  function paused() external view returns (bool);

  function getPausedTime() external view returns (uint256, uint256);

  function getAddressesProvider() external view returns (ILendPoolAddressesProvider);

  function initReserve(
    address asset,
    address bTokenAddress,
    address debtTokenAddress,
    address interestRateAddress
  ) external;

  function initNft(address asset, address bNftAddress) external;

  function setReserveInterestRateAddress(address asset, address rateAddress) external;

  function setReserveConfiguration(address asset, uint256 configuration) external;

  function setNftConfiguration(address asset, uint256 configuration) external;

  function setNftMaxSupplyAndTokenId(
    address asset,
    uint256 maxSupply,
    uint256 maxTokenId
  ) external;

  function setMaxNumberOfReserves(uint256 val) external;

  function setMaxNumberOfNfts(uint256 val) external;

  function getMaxNumberOfReserves() external view returns (uint256);

  function getMaxNumberOfNfts() external view returns (uint256);
}

File 10 of 23 : ILendPoolLoan.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

import {DataTypes} from "../libraries/types/DataTypes.sol";

interface ILendPoolLoan {
  /**
   * @dev Emitted on initialization to share location of dependent notes
   * @param pool The address of the associated lend pool
   */
  event Initialized(address indexed pool);

  /**
   * @dev Emitted when a loan is created
   * @param user The address initiating the action
   */
  event LoanCreated(
    address indexed user,
    address indexed onBehalfOf,
    uint256 indexed loanId,
    address nftAsset,
    uint256 nftTokenId,
    address reserveAsset,
    uint256 amount,
    uint256 borrowIndex
  );

  /**
   * @dev Emitted when a loan is updated
   * @param user The address initiating the action
   */
  event LoanUpdated(
    address indexed user,
    uint256 indexed loanId,
    address nftAsset,
    uint256 nftTokenId,
    address reserveAsset,
    uint256 amountAdded,
    uint256 amountTaken,
    uint256 borrowIndex
  );

  /**
   * @dev Emitted when a loan is repaid by the borrower
   * @param user The address initiating the action
   */
  event LoanRepaid(
    address indexed user,
    uint256 indexed loanId,
    address nftAsset,
    uint256 nftTokenId,
    address reserveAsset,
    uint256 amount,
    uint256 borrowIndex
  );

  /**
   * @dev Emitted when a loan is auction by the liquidator
   * @param user The address initiating the action
   */
  event LoanAuctioned(
    address indexed user,
    uint256 indexed loanId,
    address nftAsset,
    uint256 nftTokenId,
    uint256 amount,
    uint256 borrowIndex,
    address bidder,
    uint256 price,
    address previousBidder,
    uint256 previousPrice
  );

  /**
   * @dev Emitted when a loan is redeemed
   * @param user The address initiating the action
   */
  event LoanRedeemed(
    address indexed user,
    uint256 indexed loanId,
    address nftAsset,
    uint256 nftTokenId,
    address reserveAsset,
    uint256 amountTaken,
    uint256 borrowIndex
  );

  /**
   * @dev Emitted when a loan is liquidate by the liquidator
   * @param user The address initiating the action
   */
  event LoanLiquidated(
    address indexed user,
    uint256 indexed loanId,
    address nftAsset,
    uint256 nftTokenId,
    address reserveAsset,
    uint256 amount,
    uint256 borrowIndex
  );

  event LoanRepaidInterceptorUpdated(address nftAsset, uint256 tokenId, address indexed interceptor, bool approved);

  function initNft(address nftAsset, address bNftAddress) external;

  /**
   * @dev Create store a loan object with some params
   * @param initiator The address of the user initiating the borrow
   * @param onBehalfOf The address receiving the loan
   */
  function createLoan(
    address initiator,
    address onBehalfOf,
    address nftAsset,
    uint256 nftTokenId,
    address bNftAddress,
    address reserveAsset,
    uint256 amount,
    uint256 borrowIndex
  ) external returns (uint256);

  /**
   * @dev Update the given loan with some params
   *
   * Requirements:
   *  - The caller must be a holder of the loan
   *  - The loan must be in state Active
   * @param initiator The address of the user initiating the borrow
   */
  function updateLoan(
    address initiator,
    uint256 loanId,
    uint256 amountAdded,
    uint256 amountTaken,
    uint256 borrowIndex
  ) external;

  /**
   * @dev Repay the given loan
   *
   * Requirements:
   *  - The caller must be a holder of the loan
   *  - The caller must send in principal + interest
   *  - The loan must be in state Active
   *
   * @param initiator The address of the user initiating the repay
   * @param loanId The loan getting burned
   * @param bNftAddress The address of bNFT
   */
  function repayLoan(
    address initiator,
    uint256 loanId,
    address bNftAddress,
    uint256 amount,
    uint256 borrowIndex
  ) external;

  /**
   * @dev Auction the given loan
   *
   * Requirements:
   *  - The price must be greater than current highest price
   *  - The loan must be in state Active or Auction
   *
   * @param initiator The address of the user initiating the auction
   * @param loanId The loan getting auctioned
   * @param bidPrice The bid price of this auction
   */
  function auctionLoan(
    address initiator,
    uint256 loanId,
    address onBehalfOf,
    uint256 bidPrice,
    uint256 borrowAmount,
    uint256 borrowIndex
  ) external;

  /**
   * @dev Redeem the given loan with some params
   *
   * Requirements:
   *  - The caller must be a holder of the loan
   *  - The loan must be in state Auction
   * @param initiator The address of the user initiating the borrow
   */
  function redeemLoan(
    address initiator,
    uint256 loanId,
    uint256 amountTaken,
    uint256 borrowIndex
  ) external;

  /**
   * @dev Liquidate the given loan
   *
   * Requirements:
   *  - The caller must send in principal + interest
   *  - The loan must be in state Active
   *
   * @param initiator The address of the user initiating the auction
   * @param loanId The loan getting burned
   * @param bNftAddress The address of bNFT
   */
  function liquidateLoan(
    address initiator,
    uint256 loanId,
    address bNftAddress,
    uint256 borrowAmount,
    uint256 borrowIndex
  ) external;

  /**
   * @dev Add or remove the interceptor from the whitelist
   * @param interceptor The address of the interceptor contract
   * @param approved add or remove
   */
  function approveLoanRepaidInterceptor(address interceptor, bool approved) external;

  function isLoanRepaidInterceptorApproved(address interceptor) external view returns (bool);

  function purgeLoanRepaidInterceptor(
    address nftAddress,
    uint256[] calldata tokenIds,
    address interceptor
  ) external;

  function addLoanRepaidInterceptor(address nftAsset, uint256 tokenId) external;

  function deleteLoanRepaidInterceptor(address nftAsset, uint256 tokenId) external;

  function getLoanRepaidInterceptors(address nftAsset, uint256 tokenId) external view returns (address[] memory);

  /**
   * @dev Add or remove the locker from the whitelist
   * @param locker The address of the locker contract
   * @param approved add or remove
   */
  function approveFlashLoanLocker(address locker, bool approved) external;

  function isFlashLoanLockerApproved(address locker) external view returns (bool);

  /**
   * @dev Lock or unlock the flash loan caller
   * @param nftAsset The address of the NFT asset
   * @param tokenId The id of the NFT token
   * @param locked lock or unlock
   */
  function setFlashLoanLocking(
    address nftAsset,
    uint256 tokenId,
    bool locked
  ) external;

  function purgeFlashLoanLocking(
    address nftAsset,
    uint256[] calldata tokenIds,
    address locker
  ) external;

  function borrowerOf(uint256 loanId) external view returns (address);

  function getCollateralLoanId(address nftAsset, uint256 nftTokenId) external view returns (uint256);

  function getLoan(uint256 loanId) external view returns (DataTypes.LoanData memory loanData);

  function getLoanCollateralAndReserve(uint256 loanId)
    external
    view
    returns (
      address nftAsset,
      uint256 nftTokenId,
      address reserveAsset,
      uint256 scaledAmount
    );

  function getLoanReserveBorrowScaledAmount(uint256 loanId) external view returns (address, uint256);

  function getLoanReserveBorrowAmount(uint256 loanId) external view returns (address, uint256);

  function getLoanHighestBid(uint256 loanId) external view returns (address, uint256);

  function getNftCollateralAmount(address nftAsset) external view returns (uint256);

  function getUserNftCollateralAmount(address user, address nftAsset) external view returns (uint256);
}

File 11 of 23 : ILendPoolAddressesProvider.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

/**
 * @title LendPoolAddressesProvider contract
 * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles
 * - Acting also as factory of proxies and admin of those, so with right to change its implementations
 * - Owned by the Bend Governance
 * @author Bend
 **/
interface ILendPoolAddressesProvider {
  event MarketIdSet(string newMarketId);
  event LendPoolUpdated(address indexed newAddress, bytes encodedCallData);
  event ConfigurationAdminUpdated(address indexed newAddress);
  event EmergencyAdminUpdated(address indexed newAddress);
  event LendPoolConfiguratorUpdated(address indexed newAddress, bytes encodedCallData);
  event ReserveOracleUpdated(address indexed newAddress);
  event NftOracleUpdated(address indexed newAddress);
  event LendPoolLoanUpdated(address indexed newAddress, bytes encodedCallData);
  event ProxyCreated(bytes32 id, address indexed newAddress);
  event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy, bytes encodedCallData);
  event BNFTRegistryUpdated(address indexed newAddress);
  event IncentivesControllerUpdated(address indexed newAddress);
  event UIDataProviderUpdated(address indexed newAddress);
  event BendDataProviderUpdated(address indexed newAddress);
  event WalletBalanceProviderUpdated(address indexed newAddress);

  function getMarketId() external view returns (string memory);

  function setMarketId(string calldata marketId) external;

  function setAddress(bytes32 id, address newAddress) external;

  function setAddressAsProxy(
    bytes32 id,
    address impl,
    bytes memory encodedCallData
  ) external;

  function getAddress(bytes32 id) external view returns (address);

  function getLendPool() external view returns (address);

  function setLendPoolImpl(address pool, bytes memory encodedCallData) external;

  function getLendPoolConfigurator() external view returns (address);

  function setLendPoolConfiguratorImpl(address configurator, bytes memory encodedCallData) external;

  function getPoolAdmin() external view returns (address);

  function setPoolAdmin(address admin) external;

  function getEmergencyAdmin() external view returns (address);

  function setEmergencyAdmin(address admin) external;

  function getReserveOracle() external view returns (address);

  function setReserveOracle(address reserveOracle) external;

  function getNFTOracle() external view returns (address);

  function setNFTOracle(address nftOracle) external;

  function getLendPoolLoan() external view returns (address);

  function setLendPoolLoanImpl(address loan, bytes memory encodedCallData) external;

  function getBNFTRegistry() external view returns (address);

  function setBNFTRegistry(address factory) external;

  function getIncentivesController() external view returns (address);

  function setIncentivesController(address controller) external;

  function getUIDataProvider() external view returns (address);

  function setUIDataProvider(address provider) external;

  function getBendDataProvider() external view returns (address);

  function setBendDataProvider(address provider) external;

  function getWalletBalanceProvider() external view returns (address);

  function setWalletBalanceProvider(address provider) external;
}

File 12 of 23 : IWrapperGateway.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

interface IWrapperGateway {
  /**
   * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower
   * already deposited enough collateral
   * - E.g. User borrows 100 USDC, receiving the 100 USDC in his wallet
   *   and lock collateral asset in contract
   * @param reserveAsset The address of the underlying asset to borrow
   * @param amount The amount to be borrowed
   * @param nftTokenId The index of the ERC721 used as collteral
   * @param onBehalfOf Address of the user who will receive the loan. Should be the address of the borrower itself
   * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator
   * if he has been given credit delegation allowance
   * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
   *   0 if the action is executed directly by the user, without any middle-man
   **/
  function borrow(
    address reserveAsset,
    uint256 amount,
    uint256 nftTokenId,
    address onBehalfOf,
    uint16 referralCode
  ) external;

  function batchBorrow(
    address[] calldata reserveAssets,
    uint256[] calldata amounts,
    uint256[] calldata nftTokenIds,
    address onBehalfOf,
    uint16 referralCode
  ) external;

  /**
   * @notice Repays a borrowed `amount` on a specific NFT, burning the equivalent loan owned
   * - E.g. User repays 100 USDC, burning loan and receives collateral asset
   * @param nftTokenId The index of the ERC721 used as collteral
   * @param amount The amount to repay
   * @return The final amount repaid, loan is burned or not
   **/
  function repay(uint256 nftTokenId, uint256 amount) external returns (uint256, bool);

  function batchRepay(uint256[] calldata nftTokenIds, uint256[] calldata amounts)
    external
    returns (uint256[] memory, bool[] memory);

  /**
   * @notice auction a unhealth NFT loan with ERC20 reserve
   * @param nftTokenId The index of the ERC721 used as collteral
   * @param bidPrice The bid price
   **/
  function auction(
    uint256 nftTokenId,
    uint256 bidPrice,
    address onBehalfOf
  ) external;

  /**
   * @notice redeem a unhealth NFT loan with ERC20 reserve
   * @param nftTokenId The index of the ERC721 used as collteral
   * @param amount The amount to repay the debt
   * @param bidFine The amount of bid fine
   **/
  function redeem(
    uint256 nftTokenId,
    uint256 amount,
    uint256 bidFine
  ) external returns (uint256);

  /**
   * @notice liquidate a unhealth NFT loan with ERC20 reserve
   * @param nftTokenId The index of the ERC721 used as collteral
   **/
  function liquidate(uint256 nftTokenId, uint256 amount) external returns (uint256);

  /**
   * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower
   * already deposited enough collateral
   * - E.g. User borrows 100 ETH, receiving the 100 ETH in his wallet
   *   and lock collateral asset in contract
   * @param amount The amount to be borrowed
   * @param nftTokenId The index of the ERC721 to deposit
   * @param onBehalfOf Address of the user who will receive the loan. Should be the address of the borrower itself
   * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator
   * if he has been given credit delegation allowance
   * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
   *   0 if the action is executed directly by the user, without any middle-man
   **/
  function borrowETH(
    uint256 amount,
    uint256 nftTokenId,
    address onBehalfOf,
    uint16 referralCode
  ) external;

  function batchBorrowETH(
    uint256[] calldata amounts,
    uint256[] calldata nftTokenIds,
    address onBehalfOf,
    uint16 referralCode
  ) external;

  /**
   * @notice Repays a borrowed `amount` on a specific NFT with native ETH
   * - E.g. User repays 100 ETH, burning loan and receives collateral asset
   * @param nftTokenId The index of the ERC721 to repay
   * @param amount The amount to repay
   * @return The final amount repaid, loan is burned or not
   **/
  function repayETH(uint256 nftTokenId, uint256 amount) external payable returns (uint256, bool);

  function batchRepayETH(uint256[] calldata nftTokenIds, uint256[] calldata amounts)
    external
    payable
    returns (uint256[] memory, bool[] memory);

  /**
   * @notice auction a unhealth NFT loan with native ETH
   * @param nftTokenId The index of the ERC721 to repay
   * @param onBehalfOf Address of the user who will receive the ERC721. Should be the address of the user itself
   * calling the function if he wants to get collateral
   **/
  function auctionETH(uint256 nftTokenId, address onBehalfOf) external payable;

  /**
   * @notice liquidate a unhealth NFT loan with native ETH
   * @param nftTokenId The index of the ERC721 to repay
   * @param amount The amount to repay the debt
   * @param bidFine The amount of bid fine
   **/
  function redeemETH(
    uint256 nftTokenId,
    uint256 amount,
    uint256 bidFine
  ) external payable returns (uint256);

  /**
   * @notice liquidate a unhealth NFT loan with native ETH
   * @param nftTokenId The index of the ERC721 to repay
   **/
  function liquidateETH(uint256 nftTokenId) external payable returns (uint256);
}

File 13 of 23 : IERC721Wrapper.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

import {IERC721MetadataUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/IERC721MetadataUpgradeable.sol";

interface IERC721Wrapper is IERC721MetadataUpgradeable {
  function mint(uint256 tokenId) external;

  function burn(uint256 tokenId) external;
}

File 14 of 23 : DataTypes.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

library DataTypes {
  struct ReserveData {
    //stores the reserve configuration
    ReserveConfigurationMap configuration;
    //the liquidity index. Expressed in ray
    uint128 liquidityIndex;
    //variable borrow index. Expressed in ray
    uint128 variableBorrowIndex;
    //the current supply rate. Expressed in ray
    uint128 currentLiquidityRate;
    //the current variable borrow rate. Expressed in ray
    uint128 currentVariableBorrowRate;
    uint40 lastUpdateTimestamp;
    //tokens addresses
    address bTokenAddress;
    address debtTokenAddress;
    //address of the interest rate strategy
    address interestRateAddress;
    //the id of the reserve. Represents the position in the list of the active reserves
    uint8 id;
  }

  struct NftData {
    //stores the nft configuration
    NftConfigurationMap configuration;
    //address of the bNFT contract
    address bNftAddress;
    //the id of the nft. Represents the position in the list of the active nfts
    uint8 id;
    uint256 maxSupply;
    uint256 maxTokenId;
  }

  struct ReserveConfigurationMap {
    //bit 0-15: LTV
    //bit 16-31: Liq. threshold
    //bit 32-47: Liq. bonus
    //bit 48-55: Decimals
    //bit 56: Reserve is active
    //bit 57: reserve is frozen
    //bit 58: borrowing is enabled
    //bit 59: stable rate borrowing enabled
    //bit 60-63: reserved
    //bit 64-79: reserve factor
    uint256 data;
  }

  struct NftConfigurationMap {
    //bit 0-15: LTV
    //bit 16-31: Liq. threshold
    //bit 32-47: Liq. bonus
    //bit 56: NFT is active
    //bit 57: NFT is frozen
    uint256 data;
  }

  /**
   * @dev Enum describing the current state of a loan
   * State change flow:
   *  Created -> Active -> Repaid
   *                    -> Auction -> Defaulted
   */
  enum LoanState {
    // We need a default that is not 'Created' - this is the zero value
    None,
    // The loan data is stored, but not initiated yet.
    Created,
    // The loan has been initialized, funds have been delivered to the borrower and the collateral is held.
    Active,
    // The loan is in auction, higest price liquidator will got chance to claim it.
    Auction,
    // The loan has been repaid, and the collateral has been returned to the borrower. This is a terminal state.
    Repaid,
    // The loan was delinquent and collateral claimed by the liquidator. This is a terminal state.
    Defaulted
  }

  struct LoanData {
    //the id of the nft loan
    uint256 loanId;
    //the current state of the loan
    LoanState state;
    //address of borrower
    address borrower;
    //address of nft asset token
    address nftAsset;
    //the id of nft token
    uint256 nftTokenId;
    //address of reserve asset token
    address reserveAsset;
    //scaled borrow amount. Expressed in ray
    uint256 scaledAmount;
    //start time of first bid time
    uint256 bidStartTimestamp;
    //bidder address of higest bid
    address bidderAddress;
    //price of higest bid
    uint256 bidPrice;
    //borrow amount of loan
    uint256 bidBorrowAmount;
    //bidder address of first bid
    address firstBidderAddress;
  }

  struct ExecuteDepositParams {
    address initiator;
    address asset;
    uint256 amount;
    address onBehalfOf;
    uint16 referralCode;
  }

  struct ExecuteWithdrawParams {
    address initiator;
    address asset;
    uint256 amount;
    address to;
  }

  struct ExecuteBorrowParams {
    address initiator;
    address asset;
    uint256 amount;
    address nftAsset;
    uint256 nftTokenId;
    address onBehalfOf;
    uint16 referralCode;
  }

  struct ExecuteBatchBorrowParams {
    address initiator;
    address[] assets;
    uint256[] amounts;
    address[] nftAssets;
    uint256[] nftTokenIds;
    address onBehalfOf;
    uint16 referralCode;
  }

  struct ExecuteRepayParams {
    address initiator;
    address nftAsset;
    uint256 nftTokenId;
    uint256 amount;
  }

  struct ExecuteBatchRepayParams {
    address initiator;
    address[] nftAssets;
    uint256[] nftTokenIds;
    uint256[] amounts;
  }

  struct ExecuteAuctionParams {
    address initiator;
    address nftAsset;
    uint256 nftTokenId;
    uint256 bidPrice;
    address onBehalfOf;
  }

  struct ExecuteRedeemParams {
    address initiator;
    address nftAsset;
    uint256 nftTokenId;
    uint256 amount;
    uint256 bidFine;
  }

  struct ExecuteLiquidateParams {
    address initiator;
    address nftAsset;
    uint256 nftTokenId;
    uint256 amount;
  }

  struct ExecuteLendPoolStates {
    uint256 pauseStartTime;
    uint256 pauseDurationTime;
  }
}

File 15 of 23 : IWETHGateway.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

interface IWETHGateway {
  /**
   * @dev deposits WETH into the reserve, using native ETH. A corresponding amount of the overlying asset (bTokens)
   * is minted.
   * @param onBehalfOf address of the user who will receive the bTokens representing the deposit
   * @param referralCode integrators are assigned a referral code and can potentially receive rewards.
   **/
  function depositETH(address onBehalfOf, uint16 referralCode) external payable;

  /**
   * @dev withdraws the WETH _reserves of msg.sender.
   * @param amount amount of bWETH to withdraw and receive native ETH
   * @param to address of the user who will receive native ETH
   */
  function withdrawETH(uint256 amount, address to) external;

  /**
   * @dev borrow WETH, unwraps to ETH and send both the ETH and DebtTokens to msg.sender, via `approveDelegation` and onBehalf argument in `LendPool.borrow`.
   * @param amount the amount of ETH to borrow
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token ID of the underlying NFT used as collateral
   * @param onBehalfOf Address of the user who will receive the loan. Should be the address of the borrower itself
   * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator
   * if he has been given credit delegation allowance
   * @param referralCode integrators are assigned a referral code and can potentially receive rewards
   */
  function borrowETH(
    uint256 amount,
    address nftAsset,
    uint256 nftTokenId,
    address onBehalfOf,
    uint16 referralCode
  ) external;

  function batchBorrowETH(
    uint256[] calldata amounts,
    address[] calldata nftAssets,
    uint256[] calldata nftTokenIds,
    address onBehalfOf,
    uint16 referralCode
  ) external;

  /**
   * @dev repays a borrow on the WETH reserve, for the specified amount (or for the whole amount, if uint256(-1) is specified).
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token ID of the underlying NFT used as collateral
   * @param amount the amount to repay, or uint256(-1) if the user wants to repay everything
   */
  function repayETH(
    address nftAsset,
    uint256 nftTokenId,
    uint256 amount
  ) external payable returns (uint256, bool);

  function batchRepayETH(
    address[] calldata nftAssets,
    uint256[] calldata nftTokenIds,
    uint256[] calldata amounts
  ) external payable returns (uint256[] memory, bool[] memory);

  /**
   * @dev auction a borrow on the WETH reserve
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token ID of the underlying NFT used as collateral
   * @param onBehalfOf Address of the user who will receive the underlying NFT used as collateral.
   * Should be the address of the borrower itself calling the function if he wants to borrow against his own collateral.
   */
  function auctionETH(
    address nftAsset,
    uint256 nftTokenId,
    address onBehalfOf
  ) external payable;

  /**
   * @dev redeems a borrow on the WETH reserve
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token ID of the underlying NFT used as collateral
   * @param amount The amount to repay the debt
   * @param bidFine The amount of bid fine
   */
  function redeemETH(
    address nftAsset,
    uint256 nftTokenId,
    uint256 amount,
    uint256 bidFine
  ) external payable returns (uint256);

  /**
   * @dev liquidates a borrow on the WETH reserve
   * @param nftAsset The address of the underlying NFT used as collateral
   * @param nftTokenId The token ID of the underlying NFT used as collateral
   */
  function liquidateETH(address nftAsset, uint256 nftTokenId) external payable returns (uint256);
}

File 16 of 23 : EmergencyTokenRecoveryUpgradeable.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {IERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";

import {IPunks} from "../interfaces/IPunks.sol";

/**
 * @title EmergencyTokenRecovery
 * @notice Add Emergency Recovery Logic to contract implementation
 * @author Bend
 **/
abstract contract EmergencyTokenRecoveryUpgradeable is OwnableUpgradeable {
  event EmergencyEtherTransfer(address indexed to, uint256 amount);

  function __EmergencyTokenRecovery_init() internal onlyInitializing {
    __Ownable_init();
  }

  /**
   * @dev transfer ERC20 from the utility contract, for ERC20 recovery in case of stuck tokens due
   * direct transfers to the contract address.
   * @param token token to transfer
   * @param to recipient of the transfer
   * @param amount amount to send
   */
  function emergencyERC20Transfer(
    address token,
    address to,
    uint256 amount
  ) external onlyOwner {
    IERC20Upgradeable(token).transfer(to, amount);
  }

  /**
   * @dev transfer ERC721 from the utility contract, for ERC721 recovery in case of stuck tokens due
   * direct transfers to the contract address.
   * @param token token to transfer
   * @param to recipient of the transfer
   * @param id token id to send
   */
  function emergencyERC721Transfer(
    address token,
    address to,
    uint256 id
  ) external onlyOwner {
    IERC721Upgradeable(token).safeTransferFrom(address(this), to, id);
  }

  /**
   * @dev transfer CryptoPunks from the utility contract, for punks recovery in case of stuck punks
   * due direct transfers to the contract address.
   * @param to recipient of the transfer
   * @param index punk index to send
   */
  function emergencyPunksTransfer(
    address punks,
    address to,
    uint256 index
  ) external onlyOwner {
    IPunks(punks).transferPunk(to, index);
  }

  /**
   * @dev transfer native Ether from the utility contract, for native Ether recovery in case of stuck Ether
   * due selfdestructs or transfer ether to pre-computated contract address before deployment.
   * @param to recipient of the transfer
   * @param amount amount to send
   */
  function emergencyEtherTransfer(address to, uint256 amount) external onlyOwner {
    (bool success, ) = to.call{value: amount}(new bytes(0));
    require(success, "ETH_TRANSFER_FAILED");
    emit EmergencyEtherTransfer(to, amount);
  }

  uint256[50] private __gap;
}

File 17 of 23 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
        __Context_init_unchained();
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
    uint256[50] private __gap;
}

File 18 of 23 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} modifier, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

File 19 of 23 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 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://diligence.consensys.net/posts/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.5.11/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 functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 20 of 23 : IERC165Upgradeable.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 IERC165Upgradeable {
    /**
     * @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 21 of 23 : IERC721ReceiverUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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 IERC721ReceiverUpgradeable {
    /**
     * @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 `IERC721.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

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

pragma solidity ^0.8.0;

import "../IERC721Upgradeable.sol";

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

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

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

File 23 of 23 : IPunks.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

/**
 * @dev Interface for a permittable ERC721 contract
 * See https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC72 allowance (see {IERC721-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC721-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IPunks {
  function balanceOf(address account) external view returns (uint256);

  function punkIndexToAddress(uint256 punkIndex) external view returns (address owner);

  function buyPunk(uint256 punkIndex) external;

  function transferPunk(address to, uint256 punkIndex) external;
}

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

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EmergencyEtherTransfer","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"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"addressProvider","outputs":[{"internalType":"contract ILendPoolAddressesProvider","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nftTokenId","type":"uint256"},{"internalType":"uint256","name":"bidPrice","type":"uint256"},{"internalType":"address","name":"onBehalfOf","type":"address"}],"name":"auction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nftTokenId","type":"uint256"},{"internalType":"address","name":"onBehalfOf","type":"address"}],"name":"auctionETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"callers","type":"address[]"},{"internalType":"bool","name":"flag","type":"bool"}],"name":"authorizeCallerWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"authorizeLendPoolERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"reserveAssets","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"uint256[]","name":"nftTokenIds","type":"uint256[]"},{"internalType":"address","name":"onBehalfOf","type":"address"},{"internalType":"uint16","name":"referralCode","type":"uint16"}],"name":"batchBorrow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"uint256[]","name":"nftTokenIds","type":"uint256[]"},{"internalType":"address","name":"onBehalfOf","type":"address"},{"internalType":"uint16","name":"referralCode","type":"uint16"}],"name":"batchBorrowETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"nftTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"batchRepay","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bool[]","name":"","type":"bool[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"nftTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"batchRepayETH","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bool[]","name":"","type":"bool[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"reserveAsset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"nftTokenId","type":"uint256"},{"internalType":"address","name":"onBehalfOf","type":"address"},{"internalType":"uint16","name":"referralCode","type":"uint16"}],"name":"borrow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"nftTokenId","type":"uint256"},{"internalType":"address","name":"onBehalfOf","type":"address"},{"internalType":"uint16","name":"referralCode","type":"uint16"}],"name":"borrowETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"emergencyERC20Transfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"emergencyERC721Transfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"emergencyEtherTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"punks","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"emergencyPunksTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addressProvider_","type":"address"},{"internalType":"address","name":"wethGateway_","type":"address"},{"internalType":"address","name":"underlyingToken_","type":"address"},{"internalType":"address","name":"wrappedToken_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"isCallerInWhitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nftTokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"liquidate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nftTokenId","type":"uint256"}],"name":"liquidateETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nftTokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"bidFine","type":"uint256"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nftTokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"bidFine","type":"uint256"}],"name":"redeemETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nftTokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"repay","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nftTokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"repayETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlyingToken","outputs":[{"internalType":"contract IERC721Upgradeable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wethGateway","outputs":[{"internalType":"contract IWETHGateway","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wrappedToken","outputs":[{"internalType":"contract IERC721Wrapper","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

608060405234801561001057600080fd5b5061431e806100206000396000f3fe6080604052600436106101d15760003560e01c8063996c6cc3116100f7578063d296d1f111610095578063f2fde38b11610064578063f2fde38b146105ac578063f8a3310b146105cc578063f8c8765e146105ec578063ff7039c71461060c576101d8565b8063d296d1f11461052c578063d8a233201461054c578063d8aed1451461056c578063eed88b8d1461058c576101d8565b8063b9e1c75d116100d1578063b9e1c75d146104b9578063c5e10eef146104d9578063cf1c37b2146104f9578063d0554fc61461050c576101d8565b8063996c6cc314610459578063a42fb50914610479578063b819220514610499576101d8565b8063715018a61161016f578063839315231161013e57806383931523146103b05780638da5cb5b146103d057806393c880e5146103ee57806395f3e2381461040f576101d8565b8063715018a6146103405780637194a0ea14610355578063767aef98146103755780637f185c1e14610388576101d8565b806327cb5ed2116101ab57806327cb5ed2146102bf5780632954018c146102df5780635a539647146102ff5780635a9539991461031f576101d8565b8063059398a01461021c578063150b7a021461023e5780632495a59914610287576101d8565b366101d857005b60405162461bcd60e51b815260206004820152601460248201527311985b1b189858dac81b9bdd08185b1b1bddd95960621b60448201526064015b60405180910390fd5b34801561022857600080fd5b5061023c610237366004613791565b61062c565b005b34801561024a57600080fd5b506102696102593660046137d1565b630a85bd0160e11b949350505050565b6040516001600160e01b031990911681526020015b60405180910390f35b34801561029357600080fd5b5060fd546102a7906001600160a01b031681565b6040516001600160a01b03909116815260200161027e565b3480156102cb57600080fd5b5061023c6102da3660046139c5565b6106bb565b3480156102eb57600080fd5b5060fb546102a7906001600160a01b031681565b34801561030b57600080fd5b5061023c61031a366004613986565b6109b0565b61033261032d366004613ad0565b610ae6565b60405161027e929190613f43565b34801561034c57600080fd5b5061023c610d3c565b34801561036157600080fd5b5061023c610370366004613791565b610d72565b61023c610383366004613cd2565b610dcc565b61039b610396366004613d25565b610e77565b6040805192835290151560208301520161027e565b3480156103bc57600080fd5b5061023c6103cb366004613791565b610ed9565b3480156103dc57600080fd5b506097546001600160a01b03166102a7565b6104016103fc366004613ca2565b610f89565b60405190815260200161027e565b34801561041b57600080fd5b5061044961042a3660046136fe565b6001600160a01b0316600090815260ff60208190526040909120541690565b604051901515815260200161027e565b34801561046557600080fd5b5060fe546102a7906001600160a01b031681565b34801561048557600080fd5b5061023c610494366004613d46565b6111d2565b3480156104a557600080fd5b506104016104b4366004613dba565b611449565b3480156104c557600080fd5b5061023c6104d436600461392c565b611728565b3480156104e557600080fd5b5060fc546102a7906001600160a01b031681565b610401610507366004613dba565b61185b565b34801561051857600080fd5b5061023c610527366004613d73565b6119fb565b34801561053857600080fd5b50610401610547366004613d25565b611ac0565b34801561055857600080fd5b5061023c610567366004613a7c565b611da8565b34801561057857600080fd5b5061039b610587366004613d25565b611e83565b34801561059857600080fd5b5061023c6105a736600461388c565b611eb8565b3480156105b857600080fd5b5061023c6105c73660046136fe565b611fdd565b3480156105d857600080fd5b5061023c6105e7366004613b38565b612078565b3480156105f857600080fd5b5061023c610607366004613736565b61221a565b34801561061857600080fd5b50610332610627366004613ad0565b612475565b6097546001600160a01b031633146106565760405162461bcd60e51b815260040161021390614089565b6040516322dca8bb60e21b81526001600160a01b03841690638b72a2ec906106849085908590600401613e59565b600060405180830381600087803b15801561069e57600080fd5b505af11580156106b2573d6000803e3d6000fd5b50505050505050565b600260015414156106de5760405162461bcd60e51b81526004016102139061414d565b600260015582871461074c5760405162461bcd60e51b815260206004820152603160248201527f57726170706572476174657761793a20696e636f6e73697374656e74207265736044820152700cae4ecca82e6e6cae8e640d8cadccee8d607b1b6064820152608401610213565b82851461076b5760405162461bcd60e51b81526004016102139061403e565b61077482612635565b600061077e61269f565b905060005b848110156109a0576107ba8686838181106107ae57634e487b7160e01b600052603260045260246000fd5b90506020020135612721565b816001600160a01b031663b6529aee8b8b848181106107e957634e487b7160e01b600052603260045260246000fd5b90506020020160208101906107fe91906136fe565b8a8a8581811061081e57634e487b7160e01b600052603260045260246000fd5b60fe5460209091029290920135916001600160a01b031690508a8a8781811061085757634e487b7160e01b600052603260045260246000fd5b9050602002013589896040518763ffffffff1660e01b815260040161088196959493929190613e72565b600060405180830381600087803b15801561089b57600080fd5b505af11580156108af573d6000803e3d6000fd5b505050508989828181106108d357634e487b7160e01b600052603260045260246000fd5b90506020020160208101906108e891906136fe565b6001600160a01b031663a9059cbb858a8a8581811061091757634e487b7160e01b600052603260045260246000fd5b905060200201356040518363ffffffff1660e01b815260040161093b929190613e59565b602060405180830381600087803b15801561095557600080fd5b505af1158015610969573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061098d9190613bc5565b50806109988161427e565b915050610783565b5050600180555050505050505050565b600260015414156109d35760405162461bcd60e51b81526004016102139061414d565b60026001556097546001600160a01b03163314610a025760405162461bcd60e51b815260040161021390614089565b60005b81811015610add57828282818110610a2d57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190610a4291906136fe565b6001600160a01b031663095ea7b3610a5861269f565b6000196040518363ffffffff1660e01b8152600401610a78929190613e59565b602060405180830381600087803b158015610a9257600080fd5b505af1158015610aa6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aca9190613bc5565b5080610ad58161427e565b915050610a05565b50506001805550565b60608060026001541415610b0c5760405162461bcd60e51b81526004016102139061414d565b6002600155848314610b605760405162461bcd60e51b815260206004820152601b60248201527f696e636f6e73697374656e7420616d6f756e7473206c656e67746800000000006044820152606401610213565b6000856001600160401b03811115610b8857634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610bb1578160200160208202803683370190505b5090506000866001600160401b03811115610bdc57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610c05578160200160208202803683370190505b5090506000805b88811015610d0e57610c6b8a8a83818110610c3757634e487b7160e01b600052603260045260246000fd5b90506020020135898984818110610c5e57634e487b7160e01b600052603260045260246000fd5b9050602002013584612859565b858381518110610c8b57634e487b7160e01b600052603260045260246000fd5b60200260200101858481518110610cb257634e487b7160e01b600052603260045260246000fd5b602002602001018215151515815250828152505050838181518110610ce757634e487b7160e01b600052603260045260246000fd5b602002602001015182610cfa9190614223565b915080610d068161427e565b915050610c0c565b5080341115610d2a57610d2a33610d25833461423b565b612b59565b50600180559097909650945050505050565b6097546001600160a01b03163314610d665760405162461bcd60e51b815260040161021390614089565b610d706000612c11565b565b6097546001600160a01b03163314610d9c5760405162461bcd60e51b815260040161021390614089565b604051632142170760e11b81526001600160a01b038416906342842e0e9061068490309086908690600401613e35565b60026001541415610def5760405162461bcd60e51b81526004016102139061414d565b6002600155610dfd81612635565b60fc5460fe546040516395d2011560e01b81526001600160a01b0391821660048201526024810185905283821660448201529116906395d201159034906064016000604051808303818588803b158015610e5657600080fd5b505af1158015610e6a573d6000803e3d6000fd5b5050600180555050505050565b60008060026001541415610e9d5760405162461bcd60e51b81526004016102139061414d565b6002600155600080610eb0868683612859565b9150915081341115610eca57610eca33610d25843461423b565b60018055909590945092505050565b6097546001600160a01b03163314610f035760405162461bcd60e51b815260040161021390614089565b60405163a9059cbb60e01b81526001600160a01b0384169063a9059cbb90610f319085908590600401613e59565b602060405180830381600087803b158015610f4b57600080fd5b505af1158015610f5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f839190613bc5565b50505050565b600060026001541415610fae5760405162461bcd60e51b81526004016102139061414d565b60026001556000610fbd612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c92610ff792909116908890600401613e59565b60206040518083038186803b15801561100f57600080fd5b505afa158015611023573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110479190613cba565b9050806110665760405162461bcd60e51b815260040161021390613ff2565b604051632820036560e11b8152600481018290526000906001600160a01b0384169063504006ca906024016101806040518083038186803b1580156110aa57600080fd5b505afa1580156110be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e29190613be1565b6101008101519091506001600160a01b031633146111125760405162461bcd60e51b8152600401610213906140be565b60fc5460fe5460405163a9f1891560e01b81526000926001600160a01b039081169263a9f1891592349261114c9216908b90600401613e59565b6020604051808303818588803b15801561116557600080fd5b505af1158015611179573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061119e9190613cba565b90506111af86836101000151612ca8565b803411156111c5576111c533610d25833461423b565b6001805595945050505050565b600260015414156111f55760405162461bcd60e51b81526004016102139061414d565b600260015561120381612635565b600061120d61269f565b90506000611219612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c9261125392909116908a90600401613e59565b60206040518083038186803b15801561126b57600080fd5b505afa15801561127f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a39190613cba565b9050806112c25760405162461bcd60e51b815260040161021390613ff2565b604051637762b91560e01b8152600481018290526000906001600160a01b03841690637762b9159060240160806040518083038186803b15801561130557600080fd5b505afa158015611319573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061133d91906138e4565b506040516323b872dd60e01b81529093506001600160a01b03841692506323b872dd915061137390339030908b90600401613e35565b602060405180830381600087803b15801561138d57600080fd5b505af11580156113a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113c59190613bc5565b5060fe5460405163a4c0166b60e01b81526001600160a01b039182166004820152602481018990526044810188905286821660648201529085169063a4c0166b906084015b600060405180830381600087803b15801561142457600080fd5b505af1158015611438573d6000803e3d6000fd5b505060018055505050505050505050565b60006002600154141561146e5760405162461bcd60e51b81526004016102139061414d565b6002600155600061147d61269f565b90506000611489612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c926114c392909116908b90600401613e59565b60206040518083038186803b1580156114db57600080fd5b505afa1580156114ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115139190613cba565b9050806115325760405162461bcd60e51b815260040161021390613ff2565b604051632820036560e11b8152600481018290526000906001600160a01b0384169063504006ca906024016101806040518083038186803b15801561157657600080fd5b505afa15801561158a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ae9190613be1565b60a08101519091506001600160a01b03166323b872dd33306115d08a8c614223565b6040518463ffffffff1660e01b81526004016115ee93929190613e35565b602060405180830381600087803b15801561160857600080fd5b505af115801561161c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116409190613bc5565b5060fe5460405163ea2092f360e01b81526001600160a01b039182166004820152602481018a9052604481018990526064810188905260009186169063ea2092f390608401602060405180830381600087803b15801561169f57600080fd5b505af11580156116b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116d79190613cba565b9050806116e4888a614223565b11156117185761171833826116f98a8c614223565b611703919061423b565b60a08501516001600160a01b03169190612ef4565b6001805598975050505050505050565b6002600154141561174b5760405162461bcd60e51b81526004016102139061414d565b600260015561175982612635565b600061176361269f565b905061176e84612721565b60fe54604051635b294d7760e11b81526001600160a01b038084169263b6529aee926117a9928b928b929116908a908a908a90600401613e72565b600060405180830381600087803b1580156117c357600080fd5b505af11580156117d7573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038916925063a9059cbb91506118099086908990600401613e59565b602060405180830381600087803b15801561182357600080fd5b505af1158015611837573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6a9190613bc5565b6000600260015414156118805760405162461bcd60e51b81526004016102139061414d565b6002600155600061188f612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c926118c992909116908a90600401613e59565b60206040518083038186803b1580156118e157600080fd5b505afa1580156118f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119199190613cba565b9050806119385760405162461bcd60e51b815260040161021390613ff2565b60fc5460fe5460405163033ab16360e61b81526001600160a01b039182166004820152602481018990526044810188905260648101879052600092919091169063ceac58c09034906084016020604051808303818588803b15801561199c57600080fd5b505af11580156119b0573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906119d59190613cba565b9050803411156119ed576119ed33610d25833461423b565b600180559695505050505050565b60026001541415611a1e5760405162461bcd60e51b81526004016102139061414d565b6002600155611a2c82612635565b611a3583612721565b60fc5460fe54604051639c748eff60e01b8152600481018790526001600160a01b03918216602482015260448101869052848216606482015261ffff84166084820152911690639c748eff9060a401600060405180830381600087803b158015611a9e57600080fd5b505af1158015611ab2573d6000803e3d6000fd5b505060018055505050505050565b600060026001541415611ae55760405162461bcd60e51b81526004016102139061414d565b60026001556000611af461269f565b90506000611b00612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c92611b3a92909116908a90600401613e59565b60206040518083038186803b158015611b5257600080fd5b505afa158015611b66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b8a9190613cba565b905080611ba95760405162461bcd60e51b815260040161021390613ff2565b604051632820036560e11b8152600481018290526000906001600160a01b0384169063504006ca906024016101806040518083038186803b158015611bed57600080fd5b505afa158015611c01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c259190613be1565b6101008101519091506001600160a01b03163314611c555760405162461bcd60e51b8152600401610213906140be565b8515611ce3578060a001516001600160a01b03166323b872dd3330896040518463ffffffff1660e01b8152600401611c8f93929190613e35565b602060405180830381600087803b158015611ca957600080fd5b505af1158015611cbd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ce19190613bc5565b505b60fe546040516301c40a1760e21b81526001600160a01b0391821660048201526024810189905260448101889052600091861690630710285c90606401602060405180830381600087803b158015611d3a57600080fd5b505af1158015611d4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d729190613cba565b9050611d8388836101000151612ca8565b80871115611d9957611d9933611703838a61423b565b60018055979650505050505050565b60026001541415611dcb5760405162461bcd60e51b81526004016102139061414d565b60026001556097546001600160a01b03163314611dfa5760405162461bcd60e51b815260040161021390614089565b60005b82811015611e79578160ff6000868685818110611e2a57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190611e3f91906136fe565b6001600160a01b031681526020810191909152604001600020805460ff191691151591909117905580611e718161427e565b915050611dfd565b5050600180555050565b60008060026001541415611ea95760405162461bcd60e51b81526004016102139061414d565b6002600155610eca8484612f4a565b6097546001600160a01b03163314611ee25760405162461bcd60e51b815260040161021390614089565b604080516000808252602082019092526001600160a01b038416908390604051611f0c9190613e19565b60006040518083038185875af1925050503d8060008114611f49576040519150601f19603f3d011682016040523d82523d6000602084013e611f4e565b606091505b5050905080611f955760405162461bcd60e51b815260206004820152601360248201527211551217d514905394d1915497d19052531151606a1b6044820152606401610213565b826001600160a01b03167f71c3b69ecd4f336ba362d69703465c0d62d5041f2bbd97d22c847659b60c05b983604051611fd091815260200190565b60405180910390a2505050565b6097546001600160a01b031633146120075760405162461bcd60e51b815260040161021390614089565b6001600160a01b03811661206c5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610213565b61207581612c11565b50565b6002600154141561209b5760405162461bcd60e51b81526004016102139061414d565b60026001558285146120ef5760405162461bcd60e51b815260206004820152601b60248201527f696e636f6e73697374656e7420616d6f756e7473206c656e67746800000000006044820152606401610213565b6120f882612635565b6000836001600160401b0381111561212057634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015612149578160200160208202803683370190505b50905060005b848110156121dd5760fe5482516001600160a01b039091169083908390811061218857634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b0316815250506121cb8686838181106107ae57634e487b7160e01b600052603260045260246000fd5b806121d58161427e565b91505061214f565b5060fc54604051631ab08fbf60e11b81526001600160a01b03909116906335611f7e9061140a908a908a9086908b908b908b908b90600401613eb0565b600054610100900460ff166122355760005460ff1615612239565b303b155b61229c5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610213565b600054610100900460ff161580156122be576000805461ffff19166101011790555b6122c66132f7565b6122ce613326565b6122d6613355565b60fb80546001600160a01b038781166001600160a01b03199283161790925560fc805487841690831617905560fd8054868416908316811790915560fe805493861693909216831790915560405163a22cb46560e01b81526004810192909252600160248301529063a22cb46590604401600060405180830381600087803b15801561236157600080fd5b505af1158015612375573d6000803e3d6000fd5b505060fe546001600160a01b0316915063a22cb465905061239461269f565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260016024820152604401600060405180830381600087803b1580156123dc57600080fd5b505af11580156123f0573d6000803e3d6000fd5b505060fe5460fc5460405163a22cb46560e01b81526001600160a01b039182166004820152600160248201529116925063a22cb4659150604401600060405180830381600087803b15801561244457600080fd5b505af1158015612458573d6000803e3d6000fd5b50505050801561246e576000805461ff00191690555b5050505050565b6060806002600154141561249b5760405162461bcd60e51b81526004016102139061414d565b60026001558483146124bf5760405162461bcd60e51b81526004016102139061403e565b6000856001600160401b038111156124e757634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015612510578160200160208202803683370190505b5090506000866001600160401b0381111561253b57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015612564578160200160208202803683370190505b50905060005b87811015610d2a576125c889898381811061259557634e487b7160e01b600052603260045260246000fd5b905060200201358888848181106125bc57634e487b7160e01b600052603260045260246000fd5b90506020020135612f4a565b8483815181106125e857634e487b7160e01b600052603260045260246000fd5b6020026020010184848151811061260f57634e487b7160e01b600052603260045260246000fd5b92151560209384029190910190920191909152528061262d8161427e565b91505061256a565b6001600160a01b038116331480612661575033600090815260ff60208190526040909120541615156001145b604051806040016040528060038152602001620c4c0d60ea1b8152509061269b5760405162461bcd60e51b81526004016102139190613fbf565b5050565b60fb54604080516311ead9ef60e31b815290516000926001600160a01b031691638f56cf78916004808301926020929190829003018186803b1580156126e457600080fd5b505afa1580156126f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061271c919061371a565b905090565b600061272b612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c9261276592909116908790600401613e59565b60206040518083038186803b15801561277d57600080fd5b505afa158015612791573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127b59190613cba565b905080156127c257505050565b60fd54604051632142170760e11b81526001600160a01b03909116906342842e0e906127f690339030908890600401613e35565b600060405180830381600087803b15801561281057600080fd5b505af1158015612824573d6000803e3d6000fd5b505060fe5460405163140e25ad60e31b8152600481018790526001600160a01b03909116925063a0712d689150602401610684565b6000806000612866612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c926128a092909116908b90600401613e59565b60206040518083038186803b1580156128b857600080fd5b505afa1580156128cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128f09190613cba565b90508061290f5760405162461bcd60e51b815260040161021390613ff2565b604051632a24d53d60e01b8152600481018290526000906001600160a01b03841690632a24d53d9060240160206040518083038186803b15801561295257600080fd5b505afa158015612966573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061298a919061371a565b90506001600160a01b03811633146129b45760405162461bcd60e51b815260040161021390614184565b604051632bf25fe760e11b8152600481018390526000906001600160a01b038516906357e4bfce90602401604080518083038186803b1580156129f657600080fd5b505afa158015612a0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a2e91906138b7565b91505080881015612a3c5750865b612a468188614223565b341015612aa15760405162461bcd60e51b815260206004820152602360248201527f6d73672e76616c7565206973206c657373207468616e20726570617920616d6f6044820152621d5b9d60ea1b6064820152608401610213565b60fc5460fe546040516344e5f32b60e11b81526001600160a01b039182166004820152602481018c9052604481018b9052600092839216906389cbe65690859060640160408051808303818588803b158015612afc57600080fd5b505af1158015612b10573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190612b359190613d01565b915091508015612b4957612b498b85612ca8565b909a909950975050505050505050565b604080516000808252602082019092526001600160a01b038416908390604051612b839190613e19565b60006040518083038185875af1925050503d8060008114612bc0576040519150601f19603f3d011682016040523d82523d6000602084013e612bc5565b606091505b5050905080612c0c5760405162461bcd60e51b815260206004820152601360248201527211551217d514905394d1915497d19052531151606a1b6044820152606401610213565b505050565b609780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60fb546040805163035e6e4d60e41b815290516000926001600160a01b0316916335e6e4d0916004808301926020929190829003018186803b1580156126e457600080fd5b60fe546040516331a9108f60e11b8152600481018490526000916001600160a01b031690636352211e9060240160206040518083038186803b158015612ced57600080fd5b505afa158015612d01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d25919061371a565b90506001600160a01b0381163314612d8b5760405162461bcd60e51b815260206004820152602360248201527f57726170706572476174657761793a2063616c6c6572206973206e6f74206f776044820152623732b960e91b6064820152608401610213565b816001600160a01b0316816001600160a01b031614612dfc5760405162461bcd60e51b815260206004820152602760248201527f57726170706572476174657761793a206f6e426568616c664f66206973206e6f6044820152663a1037bbb732b960c91b6064820152608401610213565b60fe54604051632142170760e11b81526001600160a01b03909116906342842e0e90612e3090859030908890600401613e35565b600060405180830381600087803b158015612e4a57600080fd5b505af1158015612e5e573d6000803e3d6000fd5b505060fe54604051630852cd8d60e31b8152600481018790526001600160a01b0390911692506342966c689150602401600060405180830381600087803b158015612ea857600080fd5b505af1158015612ebc573d6000803e3d6000fd5b505060fd54604051632142170760e11b81526001600160a01b0390911692506342842e0e915061068490309085908890600401613e35565b612c0c8363a9059cbb60e01b8484604051602401612f13929190613e59565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613384565b6000806000612f5761269f565b90506000612f63612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c92612f9d92909116908b90600401613e59565b60206040518083038186803b158015612fb557600080fd5b505afa158015612fc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fed9190613cba565b90508061300c5760405162461bcd60e51b815260040161021390613ff2565b604051637762b91560e01b8152600481018290526000906001600160a01b03841690637762b9159060240160806040518083038186803b15801561304f57600080fd5b505afa158015613063573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061308791906138e4565b50604051632bf25fe760e11b815260048101869052909350600092506001600160a01b03861691506357e4bfce90602401604080518083038186803b1580156130cf57600080fd5b505afa1580156130e3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061310791906138b7565b604051632a24d53d60e01b815260048101869052909250600091506001600160a01b03861690632a24d53d9060240160206040518083038186803b15801561314e57600080fd5b505afa158015613162573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613186919061371a565b905081891115613194578198505b6040516323b872dd60e01b81526001600160a01b038416906323b872dd906131c490339030908e90600401613e35565b602060405180830381600087803b1580156131de57600080fd5b505af11580156131f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132169190613bc5565b5060fe54604051638cd2e0c760e01b81526001600160a01b039182166004820152602481018c9052604481018b9052600091829190891690638cd2e0c7906064016040805180830381600087803b15801561327057600080fd5b505af1158015613284573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132a89190613d01565b9150915080156132e4576001600160a01b03831633146132da5760405162461bcd60e51b815260040161021390614184565b6132e48c84612ca8565b90985096505050505050505b9250929050565b600054610100900460ff1661331e5760405162461bcd60e51b815260040161021390614102565b610d70613456565b600054610100900460ff1661334d5760405162461bcd60e51b815260040161021390614102565b610d70613483565b600054610100900460ff1661337c5760405162461bcd60e51b815260040161021390614102565b610d706134aa565b60006133d9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166134e19092919063ffffffff16565b805190915015612c0c57808060200190518101906133f79190613bc5565b612c0c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610213565b600054610100900460ff1661347d5760405162461bcd60e51b815260040161021390614102565b60018055565b600054610100900460ff16610d705760405162461bcd60e51b815260040161021390614102565b600054610100900460ff166134d15760405162461bcd60e51b815260040161021390614102565b6134d9613483565b610d706134fa565b60606134f0848460008561352a565b90505b9392505050565b600054610100900460ff166135215760405162461bcd60e51b815260040161021390614102565b610d7033612c11565b60608247101561358b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610213565b843b6135d95760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610213565b600080866001600160a01b031685876040516135f59190613e19565b60006040518083038185875af1925050503d8060008114613632576040519150601f19603f3d011682016040523d82523d6000602084013e613637565b606091505b5091509150613647828286613652565b979650505050505050565b606083156136615750816134f3565b8251156136715782518084602001fd5b8160405162461bcd60e51b81526004016102139190613fbf565b8051613696816142c5565b919050565b60008083601f8401126136ac578081fd5b5081356001600160401b038111156136c2578182fd5b6020830191508360208260051b85010111156132f057600080fd5b80516006811061369657600080fd5b803561ffff8116811461369657600080fd5b60006020828403121561370f578081fd5b81356134f3816142c5565b60006020828403121561372b578081fd5b81516134f3816142c5565b6000806000806080858703121561374b578283fd5b8435613756816142c5565b93506020850135613766816142c5565b92506040850135613776816142c5565b91506060850135613786816142c5565b939692955090935050565b6000806000606084860312156137a5578283fd5b83356137b0816142c5565b925060208401356137c0816142c5565b929592945050506040919091013590565b600080600080608085870312156137e6578384fd5b84356137f1816142c5565b9350602085810135613802816142c5565b93506040860135925060608601356001600160401b0380821115613824578384fd5b818801915088601f830112613837578384fd5b813581811115613849576138496142af565b61385b601f8201601f191685016141f3565b91508082528984828501011115613870578485fd5b8084840185840137810190920192909252939692955090935050565b6000806040838503121561389e578182fd5b82356138a9816142c5565b946020939093013593505050565b600080604083850312156138c9578182fd5b82516138d4816142c5565b6020939093015192949293505050565b600080600080608085870312156138f9578384fd5b8451613904816142c5565b60208601516040870151919550935061391c816142c5565b6060959095015193969295505050565b600080600080600060a08688031215613943578283fd5b853561394e816142c5565b94506020860135935060408601359250606086013561396c816142c5565b915061397a608087016136ec565b90509295509295909350565b60008060208385031215613998578182fd5b82356001600160401b038111156139ad578283fd5b6139b98582860161369b565b90969095509350505050565b60008060008060008060008060a0898b0312156139e0578586fd5b88356001600160401b03808211156139f6578788fd5b613a028c838d0161369b565b909a50985060208b0135915080821115613a1a578788fd5b613a268c838d0161369b565b909850965060408b0135915080821115613a3e578485fd5b50613a4b8b828c0161369b565b9095509350506060890135613a5f816142c5565b9150613a6d60808a016136ec565b90509295985092959890939650565b600080600060408486031215613a90578081fd5b83356001600160401b03811115613aa5578182fd5b613ab18682870161369b565b9094509250506020840135613ac5816142da565b809150509250925092565b60008060008060408587031215613ae5578182fd5b84356001600160401b0380821115613afb578384fd5b613b078883890161369b565b90965094506020870135915080821115613b1f578384fd5b50613b2c8782880161369b565b95989497509550505050565b60008060008060008060808789031215613b50578384fd5b86356001600160401b0380821115613b66578586fd5b613b728a838b0161369b565b90985096506020890135915080821115613b8a578586fd5b50613b9789828a0161369b565b9095509350506040870135613bab816142c5565b9150613bb9606088016136ec565b90509295509295509295565b600060208284031215613bd6578081fd5b81516134f3816142da565b60006101808284031215613bf3578081fd5b613bfb6141ca565b82518152613c0b602084016136dd565b6020820152613c1c6040840161368b565b6040820152613c2d6060840161368b565b606082015260808301516080820152613c4860a0840161368b565b60a082015260c083015160c082015260e083015160e0820152610100613c6f81850161368b565b9082015261012083810151908201526101408084015190820152610160613c9781850161368b565b908201529392505050565b600060208284031215613cb3578081fd5b5035919050565b600060208284031215613ccb578081fd5b5051919050565b60008060408385031215613ce4578182fd5b823591506020830135613cf6816142c5565b809150509250929050565b60008060408385031215613d13578182fd5b825191506020830151613cf6816142da565b60008060408385031215613d37578182fd5b50508035926020909101359150565b600080600060608486031215613d5a578081fd5b83359250602084013591506040840135613ac5816142c5565b60008060008060808587031215613d88578182fd5b84359350602085013592506040850135613da1816142c5565b9150613daf606086016136ec565b905092959194509250565b600080600060608486031215613dce578081fd5b505081359360208301359350604090920135919050565b81835260006001600160fb1b03831115613dfd578081fd5b8260051b80836020870137939093016020019283525090919050565b60008251613e2b818460208701614252565b9190910192915050565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039687168152602081019590955292851660408501526060840191909152909216608082015261ffff90911660a082015260c00190565b60a081526000613ec460a08301898b613de5565b828103602084810191909152885180835289820192820190845b81811015613f035784516001600160a01b031683529383019391830191600101613ede565b50508481036040860152613f1881898b613de5565b6001600160a01b039790971660608601525050505061ffff9190911660809091015295945050505050565b604080825283519082018190526000906020906060840190828701845b82811015613f7c57815184529284019290840190600101613f60565b50505083810382850152845180825285830191830190845b81811015613fb2578351151583529284019291840191600101613f94565b5090979650505050505050565b6020815260008251806020840152613fde816040850160208701614252565b601f01601f19169190910160400192915050565b6020808252602c908201527f57726170706572476174657761793a206e6f206c6f616e20776974682073756360408201526b1a081b999d151bdad95b925960a21b606082015260800190565b6020808252602b908201527f57726170706572476174657761793a20696e636f6e73697374656e7420616d6f60408201526a0eadce8e640d8cadccee8d60ab1b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526024908201527f57726170706572476174657761793a2063616c6c6572206973206e6f74206269604082015263323232b960e11b606082015260800190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60208082526026908201527f57726170706572476174657761793a2063616c6c6572206973206e6f7420626f604082015265393937bbb2b960d11b606082015260800190565b60405161018081016001600160401b03811182821017156141ed576141ed6142af565b60405290565b604051601f8201601f191681016001600160401b038111828210171561421b5761421b6142af565b604052919050565b6000821982111561423657614236614299565b500190565b60008282101561424d5761424d614299565b500390565b60005b8381101561426d578181015183820152602001614255565b83811115610f835750506000910152565b600060001982141561429257614292614299565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461207557600080fd5b801515811461207557600080fdfea26469706673582212209e8c4d7c6d08269bd736bb7ef257210e84b122d485d68d30bcb04abe0ef26ffc64736f6c63430008040033

Deployed Bytecode

0x6080604052600436106101d15760003560e01c8063996c6cc3116100f7578063d296d1f111610095578063f2fde38b11610064578063f2fde38b146105ac578063f8a3310b146105cc578063f8c8765e146105ec578063ff7039c71461060c576101d8565b8063d296d1f11461052c578063d8a233201461054c578063d8aed1451461056c578063eed88b8d1461058c576101d8565b8063b9e1c75d116100d1578063b9e1c75d146104b9578063c5e10eef146104d9578063cf1c37b2146104f9578063d0554fc61461050c576101d8565b8063996c6cc314610459578063a42fb50914610479578063b819220514610499576101d8565b8063715018a61161016f578063839315231161013e57806383931523146103b05780638da5cb5b146103d057806393c880e5146103ee57806395f3e2381461040f576101d8565b8063715018a6146103405780637194a0ea14610355578063767aef98146103755780637f185c1e14610388576101d8565b806327cb5ed2116101ab57806327cb5ed2146102bf5780632954018c146102df5780635a539647146102ff5780635a9539991461031f576101d8565b8063059398a01461021c578063150b7a021461023e5780632495a59914610287576101d8565b366101d857005b60405162461bcd60e51b815260206004820152601460248201527311985b1b189858dac81b9bdd08185b1b1bddd95960621b60448201526064015b60405180910390fd5b34801561022857600080fd5b5061023c610237366004613791565b61062c565b005b34801561024a57600080fd5b506102696102593660046137d1565b630a85bd0160e11b949350505050565b6040516001600160e01b031990911681526020015b60405180910390f35b34801561029357600080fd5b5060fd546102a7906001600160a01b031681565b6040516001600160a01b03909116815260200161027e565b3480156102cb57600080fd5b5061023c6102da3660046139c5565b6106bb565b3480156102eb57600080fd5b5060fb546102a7906001600160a01b031681565b34801561030b57600080fd5b5061023c61031a366004613986565b6109b0565b61033261032d366004613ad0565b610ae6565b60405161027e929190613f43565b34801561034c57600080fd5b5061023c610d3c565b34801561036157600080fd5b5061023c610370366004613791565b610d72565b61023c610383366004613cd2565b610dcc565b61039b610396366004613d25565b610e77565b6040805192835290151560208301520161027e565b3480156103bc57600080fd5b5061023c6103cb366004613791565b610ed9565b3480156103dc57600080fd5b506097546001600160a01b03166102a7565b6104016103fc366004613ca2565b610f89565b60405190815260200161027e565b34801561041b57600080fd5b5061044961042a3660046136fe565b6001600160a01b0316600090815260ff60208190526040909120541690565b604051901515815260200161027e565b34801561046557600080fd5b5060fe546102a7906001600160a01b031681565b34801561048557600080fd5b5061023c610494366004613d46565b6111d2565b3480156104a557600080fd5b506104016104b4366004613dba565b611449565b3480156104c557600080fd5b5061023c6104d436600461392c565b611728565b3480156104e557600080fd5b5060fc546102a7906001600160a01b031681565b610401610507366004613dba565b61185b565b34801561051857600080fd5b5061023c610527366004613d73565b6119fb565b34801561053857600080fd5b50610401610547366004613d25565b611ac0565b34801561055857600080fd5b5061023c610567366004613a7c565b611da8565b34801561057857600080fd5b5061039b610587366004613d25565b611e83565b34801561059857600080fd5b5061023c6105a736600461388c565b611eb8565b3480156105b857600080fd5b5061023c6105c73660046136fe565b611fdd565b3480156105d857600080fd5b5061023c6105e7366004613b38565b612078565b3480156105f857600080fd5b5061023c610607366004613736565b61221a565b34801561061857600080fd5b50610332610627366004613ad0565b612475565b6097546001600160a01b031633146106565760405162461bcd60e51b815260040161021390614089565b6040516322dca8bb60e21b81526001600160a01b03841690638b72a2ec906106849085908590600401613e59565b600060405180830381600087803b15801561069e57600080fd5b505af11580156106b2573d6000803e3d6000fd5b50505050505050565b600260015414156106de5760405162461bcd60e51b81526004016102139061414d565b600260015582871461074c5760405162461bcd60e51b815260206004820152603160248201527f57726170706572476174657761793a20696e636f6e73697374656e74207265736044820152700cae4ecca82e6e6cae8e640d8cadccee8d607b1b6064820152608401610213565b82851461076b5760405162461bcd60e51b81526004016102139061403e565b61077482612635565b600061077e61269f565b905060005b848110156109a0576107ba8686838181106107ae57634e487b7160e01b600052603260045260246000fd5b90506020020135612721565b816001600160a01b031663b6529aee8b8b848181106107e957634e487b7160e01b600052603260045260246000fd5b90506020020160208101906107fe91906136fe565b8a8a8581811061081e57634e487b7160e01b600052603260045260246000fd5b60fe5460209091029290920135916001600160a01b031690508a8a8781811061085757634e487b7160e01b600052603260045260246000fd5b9050602002013589896040518763ffffffff1660e01b815260040161088196959493929190613e72565b600060405180830381600087803b15801561089b57600080fd5b505af11580156108af573d6000803e3d6000fd5b505050508989828181106108d357634e487b7160e01b600052603260045260246000fd5b90506020020160208101906108e891906136fe565b6001600160a01b031663a9059cbb858a8a8581811061091757634e487b7160e01b600052603260045260246000fd5b905060200201356040518363ffffffff1660e01b815260040161093b929190613e59565b602060405180830381600087803b15801561095557600080fd5b505af1158015610969573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061098d9190613bc5565b50806109988161427e565b915050610783565b5050600180555050505050505050565b600260015414156109d35760405162461bcd60e51b81526004016102139061414d565b60026001556097546001600160a01b03163314610a025760405162461bcd60e51b815260040161021390614089565b60005b81811015610add57828282818110610a2d57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190610a4291906136fe565b6001600160a01b031663095ea7b3610a5861269f565b6000196040518363ffffffff1660e01b8152600401610a78929190613e59565b602060405180830381600087803b158015610a9257600080fd5b505af1158015610aa6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aca9190613bc5565b5080610ad58161427e565b915050610a05565b50506001805550565b60608060026001541415610b0c5760405162461bcd60e51b81526004016102139061414d565b6002600155848314610b605760405162461bcd60e51b815260206004820152601b60248201527f696e636f6e73697374656e7420616d6f756e7473206c656e67746800000000006044820152606401610213565b6000856001600160401b03811115610b8857634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610bb1578160200160208202803683370190505b5090506000866001600160401b03811115610bdc57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610c05578160200160208202803683370190505b5090506000805b88811015610d0e57610c6b8a8a83818110610c3757634e487b7160e01b600052603260045260246000fd5b90506020020135898984818110610c5e57634e487b7160e01b600052603260045260246000fd5b9050602002013584612859565b858381518110610c8b57634e487b7160e01b600052603260045260246000fd5b60200260200101858481518110610cb257634e487b7160e01b600052603260045260246000fd5b602002602001018215151515815250828152505050838181518110610ce757634e487b7160e01b600052603260045260246000fd5b602002602001015182610cfa9190614223565b915080610d068161427e565b915050610c0c565b5080341115610d2a57610d2a33610d25833461423b565b612b59565b50600180559097909650945050505050565b6097546001600160a01b03163314610d665760405162461bcd60e51b815260040161021390614089565b610d706000612c11565b565b6097546001600160a01b03163314610d9c5760405162461bcd60e51b815260040161021390614089565b604051632142170760e11b81526001600160a01b038416906342842e0e9061068490309086908690600401613e35565b60026001541415610def5760405162461bcd60e51b81526004016102139061414d565b6002600155610dfd81612635565b60fc5460fe546040516395d2011560e01b81526001600160a01b0391821660048201526024810185905283821660448201529116906395d201159034906064016000604051808303818588803b158015610e5657600080fd5b505af1158015610e6a573d6000803e3d6000fd5b5050600180555050505050565b60008060026001541415610e9d5760405162461bcd60e51b81526004016102139061414d565b6002600155600080610eb0868683612859565b9150915081341115610eca57610eca33610d25843461423b565b60018055909590945092505050565b6097546001600160a01b03163314610f035760405162461bcd60e51b815260040161021390614089565b60405163a9059cbb60e01b81526001600160a01b0384169063a9059cbb90610f319085908590600401613e59565b602060405180830381600087803b158015610f4b57600080fd5b505af1158015610f5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f839190613bc5565b50505050565b600060026001541415610fae5760405162461bcd60e51b81526004016102139061414d565b60026001556000610fbd612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c92610ff792909116908890600401613e59565b60206040518083038186803b15801561100f57600080fd5b505afa158015611023573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110479190613cba565b9050806110665760405162461bcd60e51b815260040161021390613ff2565b604051632820036560e11b8152600481018290526000906001600160a01b0384169063504006ca906024016101806040518083038186803b1580156110aa57600080fd5b505afa1580156110be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110e29190613be1565b6101008101519091506001600160a01b031633146111125760405162461bcd60e51b8152600401610213906140be565b60fc5460fe5460405163a9f1891560e01b81526000926001600160a01b039081169263a9f1891592349261114c9216908b90600401613e59565b6020604051808303818588803b15801561116557600080fd5b505af1158015611179573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061119e9190613cba565b90506111af86836101000151612ca8565b803411156111c5576111c533610d25833461423b565b6001805595945050505050565b600260015414156111f55760405162461bcd60e51b81526004016102139061414d565b600260015561120381612635565b600061120d61269f565b90506000611219612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c9261125392909116908a90600401613e59565b60206040518083038186803b15801561126b57600080fd5b505afa15801561127f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a39190613cba565b9050806112c25760405162461bcd60e51b815260040161021390613ff2565b604051637762b91560e01b8152600481018290526000906001600160a01b03841690637762b9159060240160806040518083038186803b15801561130557600080fd5b505afa158015611319573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061133d91906138e4565b506040516323b872dd60e01b81529093506001600160a01b03841692506323b872dd915061137390339030908b90600401613e35565b602060405180830381600087803b15801561138d57600080fd5b505af11580156113a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113c59190613bc5565b5060fe5460405163a4c0166b60e01b81526001600160a01b039182166004820152602481018990526044810188905286821660648201529085169063a4c0166b906084015b600060405180830381600087803b15801561142457600080fd5b505af1158015611438573d6000803e3d6000fd5b505060018055505050505050505050565b60006002600154141561146e5760405162461bcd60e51b81526004016102139061414d565b6002600155600061147d61269f565b90506000611489612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c926114c392909116908b90600401613e59565b60206040518083038186803b1580156114db57600080fd5b505afa1580156114ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115139190613cba565b9050806115325760405162461bcd60e51b815260040161021390613ff2565b604051632820036560e11b8152600481018290526000906001600160a01b0384169063504006ca906024016101806040518083038186803b15801561157657600080fd5b505afa15801561158a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ae9190613be1565b60a08101519091506001600160a01b03166323b872dd33306115d08a8c614223565b6040518463ffffffff1660e01b81526004016115ee93929190613e35565b602060405180830381600087803b15801561160857600080fd5b505af115801561161c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116409190613bc5565b5060fe5460405163ea2092f360e01b81526001600160a01b039182166004820152602481018a9052604481018990526064810188905260009186169063ea2092f390608401602060405180830381600087803b15801561169f57600080fd5b505af11580156116b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116d79190613cba565b9050806116e4888a614223565b11156117185761171833826116f98a8c614223565b611703919061423b565b60a08501516001600160a01b03169190612ef4565b6001805598975050505050505050565b6002600154141561174b5760405162461bcd60e51b81526004016102139061414d565b600260015561175982612635565b600061176361269f565b905061176e84612721565b60fe54604051635b294d7760e11b81526001600160a01b038084169263b6529aee926117a9928b928b929116908a908a908a90600401613e72565b600060405180830381600087803b1580156117c357600080fd5b505af11580156117d7573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038916925063a9059cbb91506118099086908990600401613e59565b602060405180830381600087803b15801561182357600080fd5b505af1158015611837573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6a9190613bc5565b6000600260015414156118805760405162461bcd60e51b81526004016102139061414d565b6002600155600061188f612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c926118c992909116908a90600401613e59565b60206040518083038186803b1580156118e157600080fd5b505afa1580156118f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119199190613cba565b9050806119385760405162461bcd60e51b815260040161021390613ff2565b60fc5460fe5460405163033ab16360e61b81526001600160a01b039182166004820152602481018990526044810188905260648101879052600092919091169063ceac58c09034906084016020604051808303818588803b15801561199c57600080fd5b505af11580156119b0573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906119d59190613cba565b9050803411156119ed576119ed33610d25833461423b565b600180559695505050505050565b60026001541415611a1e5760405162461bcd60e51b81526004016102139061414d565b6002600155611a2c82612635565b611a3583612721565b60fc5460fe54604051639c748eff60e01b8152600481018790526001600160a01b03918216602482015260448101869052848216606482015261ffff84166084820152911690639c748eff9060a401600060405180830381600087803b158015611a9e57600080fd5b505af1158015611ab2573d6000803e3d6000fd5b505060018055505050505050565b600060026001541415611ae55760405162461bcd60e51b81526004016102139061414d565b60026001556000611af461269f565b90506000611b00612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c92611b3a92909116908a90600401613e59565b60206040518083038186803b158015611b5257600080fd5b505afa158015611b66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b8a9190613cba565b905080611ba95760405162461bcd60e51b815260040161021390613ff2565b604051632820036560e11b8152600481018290526000906001600160a01b0384169063504006ca906024016101806040518083038186803b158015611bed57600080fd5b505afa158015611c01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c259190613be1565b6101008101519091506001600160a01b03163314611c555760405162461bcd60e51b8152600401610213906140be565b8515611ce3578060a001516001600160a01b03166323b872dd3330896040518463ffffffff1660e01b8152600401611c8f93929190613e35565b602060405180830381600087803b158015611ca957600080fd5b505af1158015611cbd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ce19190613bc5565b505b60fe546040516301c40a1760e21b81526001600160a01b0391821660048201526024810189905260448101889052600091861690630710285c90606401602060405180830381600087803b158015611d3a57600080fd5b505af1158015611d4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d729190613cba565b9050611d8388836101000151612ca8565b80871115611d9957611d9933611703838a61423b565b60018055979650505050505050565b60026001541415611dcb5760405162461bcd60e51b81526004016102139061414d565b60026001556097546001600160a01b03163314611dfa5760405162461bcd60e51b815260040161021390614089565b60005b82811015611e79578160ff6000868685818110611e2a57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190611e3f91906136fe565b6001600160a01b031681526020810191909152604001600020805460ff191691151591909117905580611e718161427e565b915050611dfd565b5050600180555050565b60008060026001541415611ea95760405162461bcd60e51b81526004016102139061414d565b6002600155610eca8484612f4a565b6097546001600160a01b03163314611ee25760405162461bcd60e51b815260040161021390614089565b604080516000808252602082019092526001600160a01b038416908390604051611f0c9190613e19565b60006040518083038185875af1925050503d8060008114611f49576040519150601f19603f3d011682016040523d82523d6000602084013e611f4e565b606091505b5050905080611f955760405162461bcd60e51b815260206004820152601360248201527211551217d514905394d1915497d19052531151606a1b6044820152606401610213565b826001600160a01b03167f71c3b69ecd4f336ba362d69703465c0d62d5041f2bbd97d22c847659b60c05b983604051611fd091815260200190565b60405180910390a2505050565b6097546001600160a01b031633146120075760405162461bcd60e51b815260040161021390614089565b6001600160a01b03811661206c5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610213565b61207581612c11565b50565b6002600154141561209b5760405162461bcd60e51b81526004016102139061414d565b60026001558285146120ef5760405162461bcd60e51b815260206004820152601b60248201527f696e636f6e73697374656e7420616d6f756e7473206c656e67746800000000006044820152606401610213565b6120f882612635565b6000836001600160401b0381111561212057634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015612149578160200160208202803683370190505b50905060005b848110156121dd5760fe5482516001600160a01b039091169083908390811061218857634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b0316815250506121cb8686838181106107ae57634e487b7160e01b600052603260045260246000fd5b806121d58161427e565b91505061214f565b5060fc54604051631ab08fbf60e11b81526001600160a01b03909116906335611f7e9061140a908a908a9086908b908b908b908b90600401613eb0565b600054610100900460ff166122355760005460ff1615612239565b303b155b61229c5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610213565b600054610100900460ff161580156122be576000805461ffff19166101011790555b6122c66132f7565b6122ce613326565b6122d6613355565b60fb80546001600160a01b038781166001600160a01b03199283161790925560fc805487841690831617905560fd8054868416908316811790915560fe805493861693909216831790915560405163a22cb46560e01b81526004810192909252600160248301529063a22cb46590604401600060405180830381600087803b15801561236157600080fd5b505af1158015612375573d6000803e3d6000fd5b505060fe546001600160a01b0316915063a22cb465905061239461269f565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260016024820152604401600060405180830381600087803b1580156123dc57600080fd5b505af11580156123f0573d6000803e3d6000fd5b505060fe5460fc5460405163a22cb46560e01b81526001600160a01b039182166004820152600160248201529116925063a22cb4659150604401600060405180830381600087803b15801561244457600080fd5b505af1158015612458573d6000803e3d6000fd5b50505050801561246e576000805461ff00191690555b5050505050565b6060806002600154141561249b5760405162461bcd60e51b81526004016102139061414d565b60026001558483146124bf5760405162461bcd60e51b81526004016102139061403e565b6000856001600160401b038111156124e757634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015612510578160200160208202803683370190505b5090506000866001600160401b0381111561253b57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015612564578160200160208202803683370190505b50905060005b87811015610d2a576125c889898381811061259557634e487b7160e01b600052603260045260246000fd5b905060200201358888848181106125bc57634e487b7160e01b600052603260045260246000fd5b90506020020135612f4a565b8483815181106125e857634e487b7160e01b600052603260045260246000fd5b6020026020010184848151811061260f57634e487b7160e01b600052603260045260246000fd5b92151560209384029190910190920191909152528061262d8161427e565b91505061256a565b6001600160a01b038116331480612661575033600090815260ff60208190526040909120541615156001145b604051806040016040528060038152602001620c4c0d60ea1b8152509061269b5760405162461bcd60e51b81526004016102139190613fbf565b5050565b60fb54604080516311ead9ef60e31b815290516000926001600160a01b031691638f56cf78916004808301926020929190829003018186803b1580156126e457600080fd5b505afa1580156126f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061271c919061371a565b905090565b600061272b612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c9261276592909116908790600401613e59565b60206040518083038186803b15801561277d57600080fd5b505afa158015612791573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127b59190613cba565b905080156127c257505050565b60fd54604051632142170760e11b81526001600160a01b03909116906342842e0e906127f690339030908890600401613e35565b600060405180830381600087803b15801561281057600080fd5b505af1158015612824573d6000803e3d6000fd5b505060fe5460405163140e25ad60e31b8152600481018790526001600160a01b03909116925063a0712d689150602401610684565b6000806000612866612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c926128a092909116908b90600401613e59565b60206040518083038186803b1580156128b857600080fd5b505afa1580156128cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128f09190613cba565b90508061290f5760405162461bcd60e51b815260040161021390613ff2565b604051632a24d53d60e01b8152600481018290526000906001600160a01b03841690632a24d53d9060240160206040518083038186803b15801561295257600080fd5b505afa158015612966573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061298a919061371a565b90506001600160a01b03811633146129b45760405162461bcd60e51b815260040161021390614184565b604051632bf25fe760e11b8152600481018390526000906001600160a01b038516906357e4bfce90602401604080518083038186803b1580156129f657600080fd5b505afa158015612a0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a2e91906138b7565b91505080881015612a3c5750865b612a468188614223565b341015612aa15760405162461bcd60e51b815260206004820152602360248201527f6d73672e76616c7565206973206c657373207468616e20726570617920616d6f6044820152621d5b9d60ea1b6064820152608401610213565b60fc5460fe546040516344e5f32b60e11b81526001600160a01b039182166004820152602481018c9052604481018b9052600092839216906389cbe65690859060640160408051808303818588803b158015612afc57600080fd5b505af1158015612b10573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190612b359190613d01565b915091508015612b4957612b498b85612ca8565b909a909950975050505050505050565b604080516000808252602082019092526001600160a01b038416908390604051612b839190613e19565b60006040518083038185875af1925050503d8060008114612bc0576040519150601f19603f3d011682016040523d82523d6000602084013e612bc5565b606091505b5050905080612c0c5760405162461bcd60e51b815260206004820152601360248201527211551217d514905394d1915497d19052531151606a1b6044820152606401610213565b505050565b609780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60fb546040805163035e6e4d60e41b815290516000926001600160a01b0316916335e6e4d0916004808301926020929190829003018186803b1580156126e457600080fd5b60fe546040516331a9108f60e11b8152600481018490526000916001600160a01b031690636352211e9060240160206040518083038186803b158015612ced57600080fd5b505afa158015612d01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d25919061371a565b90506001600160a01b0381163314612d8b5760405162461bcd60e51b815260206004820152602360248201527f57726170706572476174657761793a2063616c6c6572206973206e6f74206f776044820152623732b960e91b6064820152608401610213565b816001600160a01b0316816001600160a01b031614612dfc5760405162461bcd60e51b815260206004820152602760248201527f57726170706572476174657761793a206f6e426568616c664f66206973206e6f6044820152663a1037bbb732b960c91b6064820152608401610213565b60fe54604051632142170760e11b81526001600160a01b03909116906342842e0e90612e3090859030908890600401613e35565b600060405180830381600087803b158015612e4a57600080fd5b505af1158015612e5e573d6000803e3d6000fd5b505060fe54604051630852cd8d60e31b8152600481018790526001600160a01b0390911692506342966c689150602401600060405180830381600087803b158015612ea857600080fd5b505af1158015612ebc573d6000803e3d6000fd5b505060fd54604051632142170760e11b81526001600160a01b0390911692506342842e0e915061068490309085908890600401613e35565b612c0c8363a9059cbb60e01b8484604051602401612f13929190613e59565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613384565b6000806000612f5761269f565b90506000612f63612c63565b60fe5460405163058dcda760e21b81529192506000916001600160a01b0380851692631637369c92612f9d92909116908b90600401613e59565b60206040518083038186803b158015612fb557600080fd5b505afa158015612fc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fed9190613cba565b90508061300c5760405162461bcd60e51b815260040161021390613ff2565b604051637762b91560e01b8152600481018290526000906001600160a01b03841690637762b9159060240160806040518083038186803b15801561304f57600080fd5b505afa158015613063573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061308791906138e4565b50604051632bf25fe760e11b815260048101869052909350600092506001600160a01b03861691506357e4bfce90602401604080518083038186803b1580156130cf57600080fd5b505afa1580156130e3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061310791906138b7565b604051632a24d53d60e01b815260048101869052909250600091506001600160a01b03861690632a24d53d9060240160206040518083038186803b15801561314e57600080fd5b505afa158015613162573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613186919061371a565b905081891115613194578198505b6040516323b872dd60e01b81526001600160a01b038416906323b872dd906131c490339030908e90600401613e35565b602060405180830381600087803b1580156131de57600080fd5b505af11580156131f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132169190613bc5565b5060fe54604051638cd2e0c760e01b81526001600160a01b039182166004820152602481018c9052604481018b9052600091829190891690638cd2e0c7906064016040805180830381600087803b15801561327057600080fd5b505af1158015613284573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132a89190613d01565b9150915080156132e4576001600160a01b03831633146132da5760405162461bcd60e51b815260040161021390614184565b6132e48c84612ca8565b90985096505050505050505b9250929050565b600054610100900460ff1661331e5760405162461bcd60e51b815260040161021390614102565b610d70613456565b600054610100900460ff1661334d5760405162461bcd60e51b815260040161021390614102565b610d70613483565b600054610100900460ff1661337c5760405162461bcd60e51b815260040161021390614102565b610d706134aa565b60006133d9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166134e19092919063ffffffff16565b805190915015612c0c57808060200190518101906133f79190613bc5565b612c0c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610213565b600054610100900460ff1661347d5760405162461bcd60e51b815260040161021390614102565b60018055565b600054610100900460ff16610d705760405162461bcd60e51b815260040161021390614102565b600054610100900460ff166134d15760405162461bcd60e51b815260040161021390614102565b6134d9613483565b610d706134fa565b60606134f0848460008561352a565b90505b9392505050565b600054610100900460ff166135215760405162461bcd60e51b815260040161021390614102565b610d7033612c11565b60608247101561358b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610213565b843b6135d95760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610213565b600080866001600160a01b031685876040516135f59190613e19565b60006040518083038185875af1925050503d8060008114613632576040519150601f19603f3d011682016040523d82523d6000602084013e613637565b606091505b5091509150613647828286613652565b979650505050505050565b606083156136615750816134f3565b8251156136715782518084602001fd5b8160405162461bcd60e51b81526004016102139190613fbf565b8051613696816142c5565b919050565b60008083601f8401126136ac578081fd5b5081356001600160401b038111156136c2578182fd5b6020830191508360208260051b85010111156132f057600080fd5b80516006811061369657600080fd5b803561ffff8116811461369657600080fd5b60006020828403121561370f578081fd5b81356134f3816142c5565b60006020828403121561372b578081fd5b81516134f3816142c5565b6000806000806080858703121561374b578283fd5b8435613756816142c5565b93506020850135613766816142c5565b92506040850135613776816142c5565b91506060850135613786816142c5565b939692955090935050565b6000806000606084860312156137a5578283fd5b83356137b0816142c5565b925060208401356137c0816142c5565b929592945050506040919091013590565b600080600080608085870312156137e6578384fd5b84356137f1816142c5565b9350602085810135613802816142c5565b93506040860135925060608601356001600160401b0380821115613824578384fd5b818801915088601f830112613837578384fd5b813581811115613849576138496142af565b61385b601f8201601f191685016141f3565b91508082528984828501011115613870578485fd5b8084840185840137810190920192909252939692955090935050565b6000806040838503121561389e578182fd5b82356138a9816142c5565b946020939093013593505050565b600080604083850312156138c9578182fd5b82516138d4816142c5565b6020939093015192949293505050565b600080600080608085870312156138f9578384fd5b8451613904816142c5565b60208601516040870151919550935061391c816142c5565b6060959095015193969295505050565b600080600080600060a08688031215613943578283fd5b853561394e816142c5565b94506020860135935060408601359250606086013561396c816142c5565b915061397a608087016136ec565b90509295509295909350565b60008060208385031215613998578182fd5b82356001600160401b038111156139ad578283fd5b6139b98582860161369b565b90969095509350505050565b60008060008060008060008060a0898b0312156139e0578586fd5b88356001600160401b03808211156139f6578788fd5b613a028c838d0161369b565b909a50985060208b0135915080821115613a1a578788fd5b613a268c838d0161369b565b909850965060408b0135915080821115613a3e578485fd5b50613a4b8b828c0161369b565b9095509350506060890135613a5f816142c5565b9150613a6d60808a016136ec565b90509295985092959890939650565b600080600060408486031215613a90578081fd5b83356001600160401b03811115613aa5578182fd5b613ab18682870161369b565b9094509250506020840135613ac5816142da565b809150509250925092565b60008060008060408587031215613ae5578182fd5b84356001600160401b0380821115613afb578384fd5b613b078883890161369b565b90965094506020870135915080821115613b1f578384fd5b50613b2c8782880161369b565b95989497509550505050565b60008060008060008060808789031215613b50578384fd5b86356001600160401b0380821115613b66578586fd5b613b728a838b0161369b565b90985096506020890135915080821115613b8a578586fd5b50613b9789828a0161369b565b9095509350506040870135613bab816142c5565b9150613bb9606088016136ec565b90509295509295509295565b600060208284031215613bd6578081fd5b81516134f3816142da565b60006101808284031215613bf3578081fd5b613bfb6141ca565b82518152613c0b602084016136dd565b6020820152613c1c6040840161368b565b6040820152613c2d6060840161368b565b606082015260808301516080820152613c4860a0840161368b565b60a082015260c083015160c082015260e083015160e0820152610100613c6f81850161368b565b9082015261012083810151908201526101408084015190820152610160613c9781850161368b565b908201529392505050565b600060208284031215613cb3578081fd5b5035919050565b600060208284031215613ccb578081fd5b5051919050565b60008060408385031215613ce4578182fd5b823591506020830135613cf6816142c5565b809150509250929050565b60008060408385031215613d13578182fd5b825191506020830151613cf6816142da565b60008060408385031215613d37578182fd5b50508035926020909101359150565b600080600060608486031215613d5a578081fd5b83359250602084013591506040840135613ac5816142c5565b60008060008060808587031215613d88578182fd5b84359350602085013592506040850135613da1816142c5565b9150613daf606086016136ec565b905092959194509250565b600080600060608486031215613dce578081fd5b505081359360208301359350604090920135919050565b81835260006001600160fb1b03831115613dfd578081fd5b8260051b80836020870137939093016020019283525090919050565b60008251613e2b818460208701614252565b9190910192915050565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039687168152602081019590955292851660408501526060840191909152909216608082015261ffff90911660a082015260c00190565b60a081526000613ec460a08301898b613de5565b828103602084810191909152885180835289820192820190845b81811015613f035784516001600160a01b031683529383019391830191600101613ede565b50508481036040860152613f1881898b613de5565b6001600160a01b039790971660608601525050505061ffff9190911660809091015295945050505050565b604080825283519082018190526000906020906060840190828701845b82811015613f7c57815184529284019290840190600101613f60565b50505083810382850152845180825285830191830190845b81811015613fb2578351151583529284019291840191600101613f94565b5090979650505050505050565b6020815260008251806020840152613fde816040850160208701614252565b601f01601f19169190910160400192915050565b6020808252602c908201527f57726170706572476174657761793a206e6f206c6f616e20776974682073756360408201526b1a081b999d151bdad95b925960a21b606082015260800190565b6020808252602b908201527f57726170706572476174657761793a20696e636f6e73697374656e7420616d6f60408201526a0eadce8e640d8cadccee8d60ab1b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526024908201527f57726170706572476174657761793a2063616c6c6572206973206e6f74206269604082015263323232b960e11b606082015260800190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60208082526026908201527f57726170706572476174657761793a2063616c6c6572206973206e6f7420626f604082015265393937bbb2b960d11b606082015260800190565b60405161018081016001600160401b03811182821017156141ed576141ed6142af565b60405290565b604051601f8201601f191681016001600160401b038111828210171561421b5761421b6142af565b604052919050565b6000821982111561423657614236614299565b500190565b60008282101561424d5761424d614299565b500390565b60005b8381101561426d578181015183820152602001614255565b83811115610f835750506000910152565b600060001982141561429257614292614299565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461207557600080fd5b801515811461207557600080fdfea26469706673582212209e8c4d7c6d08269bd736bb7ef257210e84b122d485d68d30bcb04abe0ef26ffc64736f6c63430008040033

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  ]

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.