Contract 0xF68617900C9f410217A14622Ee4c984A77Ff1A37

 
 
Txn Hash
Method
Block
From
To
Value [Txn Fee]
0x8b2eadc4e4e9a588d3f2505542a27a6784bc03cae32faa8b65b52bd5fade94ed0x60806040407870682023-03-26 10:30:3264 days 7 hrs ago0xe820cc557279acc115d61b7c450f47ff000b4ef6 IN  Create: HTokenHelper0 MATIC0.3331785680
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
HTokenHelper

Compiler Version
v0.8.15+commit.e14f2714

Optimization Enabled:
Yes with 300 runs

Other Settings:
default evmVersion
File 1 of 21 : AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorV3Interface {
  function decimals() external view returns (uint8);

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

  function version() external view returns (uint256);

  // getRoundData and latestRoundData should both raise "No data present"
  // if they do not have data to report, instead of returning unset values
  // which could be misinterpreted as actual reported values.
  function getRoundData(uint80 _roundId)
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
}

File 2 of 21 : IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions 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);
    }
}

File 4 of 21 : IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the amount of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
        external
        view
        returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes calldata data
    ) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata amounts,
        bytes calldata data
    ) external;
}

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

pragma solidity ^0.8.0;

import "../IERC20.sol";

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

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

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

File 6 of 21 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "../IERC721.sol";

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

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

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

File 8 of 21 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

File 9 of 21 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "./math/Math.sol";

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

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

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

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

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

File 13 of 21 : ControllerI.sol
//SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.4;

import "./HTokenI.sol";
import "./PermissionlessOracleI.sol";

/**
 * @title   Interface of Controller
 * @author  Honey Labs Inc.
 * @custom:coauthor     m4rio
 * @custom:contributor  BowTiedPickle
 */
interface ControllerI {
  /**
   * @notice returns the oracle per market
   */
  function oracle(HTokenI _hToken) external view returns (PermissionlessOracleI);

  /**
   * @notice Add assets to be included in account liquidity calculation
   * @param _hTokens The list of addresses of the hToken markets to be enabled
   */
  function enterMarkets(HTokenI[] calldata _hTokens) external;

  /**
   * @notice Removes asset from sender's account liquidity calculation
   * @dev Sender must not have an outstanding borrow balance in the asset,
   *  or be providing necessary collateral for an outstanding borrow.
   * @param _hToken The address of the asset to be removed
   */
  function exitMarket(HTokenI _hToken) external;

  /**
   * @notice Checks if the account should be allowed to deposit underlying in the market
   * @param _hToken The market to verify the redeem against
   * @param _depositor The account which that wants to deposit
   * @param _amount The number of underlying it wants to deposit
   */
  function depositUnderlyingAllowed(
    HTokenI _hToken,
    address _depositor,
    uint256 _amount
  ) external;

  /**
   * @notice Checks if the account should be allowed to borrow the underlying asset of the given market
   * @param _hToken The market to verify the borrow against
   * @param _borrower The account which would borrow the asset
   * @param _collateralId collateral Id, aka the NFT token Id
   * @param _borrowAmount The amount of underlying the account would borrow
   */
  function borrowAllowed(
    HTokenI _hToken,
    address _borrower,
    uint256 _collateralId,
    uint256 _borrowAmount
  ) external;

  /**
   * @notice Checks if the account should be allowed to deposit a collateral
   * @param _hToken The market to verify the deposit of the collateral
   * @param _depositor The account which deposits the collateral
   * @param _collateralId The collateral token id
   */
  function depositCollateralAllowed(
    HTokenI _hToken,
    address _depositor,
    uint256 _collateralId
  ) external;

  /**
   * @notice Checks if the account should be allowed to redeem tokens in the given market
   * @param _hToken The market to verify the redeem against
   * @param _redeemer The account which would redeem the tokens
   * @param _redeemTokens The number of hTokens to exchange for the underlying asset in the market
   */
  function redeemAllowed(
    HTokenI _hToken,
    address _redeemer,
    uint256 _redeemTokens
  ) external view;

  /**
   * @notice Checks if the collateral is at risk of being liquidated
   * @param _hToken The market to verify the liquidation
   * @param _collateralId collateral Id, aka the NFT token Id
   */
  function liquidationAllowed(HTokenI _hToken, uint256 _collateralId) external view;

  /**
   * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed
   * @param _hToken The market to hypothetically redeem/borrow in
   * @param _account The account to determine liquidity for
   * @param _redeemTokens The number of tokens to hypothetically redeem
   * @param _borrowAmount The amount of underlying to hypothetically borrow
   * @param _collateralId collateral Id, aka the NFT token Id
   * @return liquidity - hypothetical account liquidity in excess of collateral requirements
   * @return shortfall - hypothetical account shortfall below collateral requirements
   * @return ltvShortfall - Loan to value shortfall, this is the max a user can borrow
   */
  function getHypotheticalAccountLiquidity(
    HTokenI _hToken,
    address _account,
    uint256 _collateralId,
    uint256 _redeemTokens,
    uint256 _borrowAmount
  )
    external
    view
    returns (
      uint256 liquidity,
      uint256 shortfall,
      uint256 ltvShortfall
    );

  /**
   * @notice Returns whether the given account is entered in the given asset
   * @param _hToken The hToken to check
   * @param _account The address of the account to check
   * @return True if the account is in the asset, otherwise false.
   */
  function checkMembership(HTokenI _hToken, address _account) external view returns (bool);

  /**
   * @notice Checks if the account should be allowed to transfer tokens in the given market
   * @param _hToken The market to verify the transfer against
   */
  function transferAllowed(HTokenI _hToken) external;

  /**
   * @notice Checks if the account should be allowed to repay a borrow in the given market
   * @param _hToken The market to verify the repay against
   * @param _repayAmount The amount of the underlying asset the account would repay
   * @param _collateralId collateral Id, aka the NFT token Id
   */
  function repayBorrowAllowed(
    HTokenI _hToken,
    uint256 _repayAmount,
    uint256 _collateralId
  ) external view;

  /**
   * @notice checks if withdrawal are allowed for this token id
   * @param _hToken The market to verify the withdrawal from
   * @param _collateralId what to pay for
   */
  function withdrawCollateralAllowed(HTokenI _hToken, uint256 _collateralId) external view;

  /**
   * @notice checks if a market exists and it's listed
   * @param _hToken the market we check to see if it exists
   * @return bool true or false
   */
  function marketExists(HTokenI _hToken) external view returns (bool);

  /**
   * @notice Returns market data for a specific market
   * @param _hToken the market we want to retrieved Controller data
   * @return bool If the market is listed
   * @return uint256 MAX Factor Mantissa
   * @return uint256 Collateral Factor Mantissa
   */
  function getMarketData(HTokenI _hToken)
    external
    view
    returns (
      bool,
      uint256,
      uint256
    );

  /**
   * @notice checks if an underlying exists in the market
   * @param _underlying the underlying to check if exists
   * @return bool true or false
   */
  function underlyingExistsInMarkets(address _underlying) external view returns (bool);

  /**
   * @notice checks if a collateral exists in the market
   * @param _collateral the collateral to check if exists
   * @return bool true or false
   */
  function collateralExistsInMarkets(address _collateral) external view returns (bool);

  /**
   * @notice  Checks if a certain action is paused within a market
   * @param   _hToken   The market we want to check if an action is paused
   * @param   _target   The action we want to check if it's paused
   * @return  bool true or false
   */
  function isActionPaused(HTokenI _hToken, uint256 _target) external view returns (bool);

  /**
   * @notice returns the borrow fee per market, accounts for referral
   * @param _hToken the market we want the borrow fee for
   * @param _referral referral code for Referral program of Honey Labs
   * @param _signature signed message provided by Honey Labs
   */
  function getBorrowFeePerMarket(
    HTokenI _hToken,
    string calldata _referral,
    bytes calldata _signature
  ) external view returns (uint256, bool);

  /**
   * @notice returns the borrow fee per market if provided a referral code, accounts for referral
   * @param _hToken the market we want the borrow fee for
   */
  function getReferralBorrowFeePerMarket(HTokenI _hToken) external view returns (uint256);

  // ---------- Permissioned Functions ----------

  function _supportMarket(HTokenI _hToken) external;

  function _setPriceOracle(HTokenI _hToken, PermissionlessOracleI _newOracle) external;

  function _setFactors(
    HTokenI _hToken,
    uint256 _newMaxLTVFactorMantissa,
    uint256 _newCollateralFactorMantissa
  ) external;

  function _setBorrowFeePerMarket(
    HTokenI _market,
    uint256 _fee,
    uint256 _referralFee
  ) external;

  function _pauseComponent(
    HTokenI _hToken,
    bool _state,
    uint256 _target
  ) external;
}

File 14 of 21 : HTokenHelperI.sol
//SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.4;

import ".././interfaces/HTokenI.sol";
import ".././interfaces/PriceOracleI.sol";
import ".././interfaces/ControllerI.sol";

/**
 * @title   Interface for HTokenHelper
 * @author  Honey Labs Inc.
 * @custom:coauthor     m4rio
 * @custom:contributor  BowTiedPickle
 */
interface HTokenHelperI {
  /**
   * @notice Get cash balance of this hToken in the underlying asset
   * @return The quantity of underlying asset owned by this contract
   */
  function getCash(HTokenI _hToken) external view returns (uint256);

  /**
   * @notice Get underlying balance that is available for withdrawal or borrow
   * @return The quantity of underlying not tied up
   */
  function getAvailableUnderlying(HTokenI _hToken) external view returns (uint256);

  /**
   * @notice Get underlying balance for an account
   * @param _account the account to check the balance for
   * @return The quantity of underlying asset owned by this account
   */
  function getAvailableUnderlyingForUser(HTokenI _hToken, address _account) external view returns (uint256);

  /**
   * @notice Get underlying balance that is available to be withdrawn
   * @return The quantity of underlying that can be borrowed
   */
  function getAvailableUnderlyingToBorrow(HTokenI _hToken) external view returns (uint256);

  /**
   * @notice returns different assets per a hToken, helper method to reduce frontend calls
   * @param _hToken the hToken to get the assets for
   * @return total borrows
   * @return total reserves
   * @return total underlying balance
   * @return active coupons
   */
  function getAssets(HTokenI _hToken)
    external
    view
    returns (
      uint256,
      uint256,
      uint256,
      HTokenI.Coupon[] memory
    );

  /**
   * @notice Get all a user's coupons
   * @param _hToken The HToken we want to get the user's coupons from
   * @param _user The user to search for
   * @return Array of all coupons belonging to the user
   */
  function getUserCoupons(HTokenI _hToken, address _user) external view returns (HTokenI.Coupon[] memory);

  /**
   * @notice Get the number of coupons deposited aka active
   * @param _hToken The HToken we want to get the active User Coupons
   * @param _hasDebt if the coupon has debt or not
   * @return Array of all active coupons
   */
  function getActiveCoupons(HTokenI _hToken, bool _hasDebt) external view returns (HTokenI.Coupon[] memory);

  /**
   * @notice Get tokenIds of all a user's coupons
   * @param _hToken The HToken we want to get the User Coupon Indices
   * @param _user The user to search for
   * @return Array of indices of all coupons belonging to the user
   */
  function getUserCouponIndices(HTokenI _hToken, address _user) external view returns (uint256[] memory);

  /**
   * @notice returns prices for a market to reduce frontend calls
   * @param _hToken the hToken to get the prices for
   * @return collection floor price in underlying value
   * @return underlying price in usd
   */
  function getMarketOraclePrices(HTokenI _hToken) external view returns (uint256, uint256);

  /**
   * @notice Returns the borrow fee for a market, it can also return the discounted fee for referred borrow
   * @param _hToken The market we want to get the borrow fee for
   * @param _referred Flag that needs to be true in case we want to get the referred borrow fee
   * @return fee - The borrow fee mantissa denominated in 1e18
   */
  function getMarketBorrowFee(HTokenI _hToken, bool _referred) external view returns (uint256 fee);

  /**
   * @notice returns the collection price floor in usd
   * @param _hToken the hToken to get the price for
   * @return collection floor price in usd
   */
  function getFloorPriceInUSD(HTokenI _hToken) external view returns (uint256);

  /**
   * @notice returns the collection price floor in underlying value
   * @param _hToken the hToken to get the price for
   * @return collection floor price in underlying
   */
  function getFloorPriceInUnderlying(HTokenI _hToken) external view returns (uint256);

  /**
   * @notice get the underlying price in usd for a hToken
   * @param _hToken the hToken to get the price for
   * @return underlying price in usd
   */
  function getUnderlyingPriceInUSD(HTokenI _hToken) external view returns (uint256);

  /**
   * @notice get the max borrowable amount for a market
   * @notice it computes the floor price in usd and take the % of collateral factor that can be max borrowed
   *         then it divides it by the underlying price in usd.
   * @param _hToken the hToken to get the price for
   * @param _hivemind the controller used to get the collateral factor
   * @return underlying price in underlying
   */
  function getMaxBorrowableAmountInUnderlying(HTokenI _hToken, ControllerI _hivemind) external view returns (uint256);

  /**
   * @notice get the max borrowable amount for a market
   * @notice it computes the floor price in usd and take the % of collateral factor that can be max borrowed
   * @param _hToken the hToken to get the price for
   * @param _hivemind the controller used to get the collateral factor
   * @return underlying price in usd
   */
  function getMaxBorrowableAmountInUSD(HTokenI _hToken, ControllerI _hivemind) external view returns (uint256);

  /**
   * @notice get's all the coupons that have deposited collateral
   * @param _hToken market to get the collateral from
   * @param _startTokenId start token id of the collateral collection, as we don't know how big the collection will be we have
   * to do pagination
   * @param _endTokenId end of token id we want to get.
   * @return coupons list of coupons that are active
   */
  function getAllCollateralPerHToken(
    HTokenI _hToken,
    uint256 _startTokenId,
    uint256 _endTokenId
  ) external view returns (HTokenI.Coupon[] memory coupons);

  /**
   * @notice Gets data about a market for frontend display
   * @param _hToken the market we want the data for
   * @return interest rate of the market
   * @return total underlying supplied in a market
   * @return total underlying available to be borrowed
   */
  function getFrontendMarketData(HTokenI _hToken)
    external
    view
    returns (
      uint256,
      uint256,
      uint256
    );

  /**
   * @notice Gets data about a coupon for frontend display
   * @param _hToken   The market we want the coupon for
   * @param _couponId The coupon id we want to get the data for
   * @return debt of this coupon
   * @return allowance - how much liquidity can borrow till hitting LTV
   * @return nft floor price
   */
  function getFrontendCouponData(HTokenI _hToken, uint256 _couponId)
    external
    view
    returns (
      uint256,
      uint256,
      uint256
    );

  /**
   * @notice Gets Liquidation data for a market, for frontend purposes
   * @param _hToken the market we want the data for
   * @return Liquidation threshold of a market (collateral factor)
   * @return Total debt of the market
   * @return TVL of a market which consists of the total coupons that have debt
   */
  function getFrontendLiquidationData(HTokenI _hToken)
    external
    view
    returns (
      uint256,
      uint256,
      uint256
    );

  /**
   * @notice uri function called from the HToken that returns the uri metadata for a coupon
   * @param _id id of the hToken
   * @param _hTokenAddress address of the hToken
   */
  function uri(uint256 _id, address _hTokenAddress) external view returns (string memory);
}

File 15 of 21 : HTokenI.sol
//SPDX-License-Identifier: BUSL-1.1

pragma solidity >=0.8.4;
import "./HTokenInternalI.sol";

/**
 * @title   Interface of HToken
 * @author  Honey Labs Inc.
 * @custom:coauthor BowTiedPickle
 * @custom:coauthor m4rio
 */
interface HTokenI is HTokenInternalI {
  /**
   * @notice  Deposit underlying ERC-20 asset and mint hTokens
   * @dev     Pull pattern, user must approve the contract before calling. If _to is address(0) then it becomes msg.sender
   * @param   _amount   Quantity of underlying ERC-20 to transfer in
   * @param   _to       Target address to mint hTokens to
   */
  function depositUnderlying(uint256 _amount, address _to) external;

  /**
   * @notice  Redeem a specified amount of hTokens for their underlying ERC-20 asset
   * @param   _amount   Quantity of hTokens to redeem for underlying ERC-20
   */
  function redeem(uint256 _amount) external;

  /**
   * @notice  Withdraws the specified amount of underlying ERC-20 asset, consuming the minimum amount of hTokens necessary
   * @param   _amount   Quantity of underlying ERC-20 tokens to withdraw
   */
  function withdraw(uint256 _amount) external;

  /**
   * @notice  Deposit multiple specified tokens of the underlying ERC-721 asset and mint ERC-1155 deposit coupon NFTs
   * @dev     Pull pattern, user must approve the contract before calling.
   * @param   _collateralIds  Token IDs of underlying ERC-721 to be transferred in
   */
  function depositCollateral(uint256[] calldata _collateralIds) external;

  /**
   * @notice  Sender borrows assets from the protocol against the specified collateral asset, without a referral code
   * @dev     Collateral must be deposited first.
   * @param   _borrowAmount   Amount of underlying ERC-20 to borrow
   * @param   _collateralId   Token ID of underlying ERC-721 to be borrowed against
   */
  function borrow(uint256 _borrowAmount, uint256 _collateralId) external;

  /**
   * @notice  Sender borrows assets from the protocol against the specified collateral asset, using a referral code
   * @param   _borrowAmount   Amount of underlying ERC-20 to borrow
   * @param   _collateralId   Token ID of underlying ERC-721 to be borrowed against
   * @param   _referral       Referral code as a plain string
   * @param   _signature      Signed message authorizing the referral, provided by Honey Labs
   */
  function borrowReferred(
    uint256 _borrowAmount,
    uint256 _collateralId,
    string calldata _referral,
    bytes calldata _signature
  ) external;

  /**
   * @notice  Sender repays a borrow taken against the specified collateral asset
   * @dev     Pull pattern, user must approve the contract before calling.
   * @param   _repayAmount    Amount of underlying ERC-20 to repay
   * @param   _collateralId   Token ID of underlying ERC-721 to be repaid against
   */
  function repayBorrow(
    uint256 _repayAmount,
    uint256 _collateralId,
    address _to
  ) external;

  /**
   * @notice  Burn deposit coupon NFTs and withdraw the associated underlying ERC-721 NFTs
   * @param   _collateralIds  Token IDs of underlying ERC-721 to be withdrawn
   */
  function withdrawCollateral(uint256[] calldata _collateralIds) external;

  /**
   * @notice  Trigger transfer of an NFT to the liquidation contract
   * @param   _collateralId   Token ID of underlying ERC-721 to be liquidated
   */
  function liquidateBorrow(uint256 _collateralId) external;

  /**
   * @notice  Pay off the entirety of a liquidated debt position and burn the coupon
   * @dev     May only be called by the liquidator
   * @param   _borrower       Owner of the debt position
   * @param   _collateralId   Token ID of underlying ERC-721 to be closed out
   */
  function closeoutLiquidation(address _borrower, uint256 _collateralId) external;

  /**
   * @notice  Accrues all interest due to the protocol
   * @dev     Call this before performing calculations using 'totalBorrows' or other contract-wide quantities
   */
  function accrueInterest() external;

  // ----- Utility functions -----

  /**
   * @notice  Sweep accidental ERC-20 transfers to this contract.
   * @dev     Tokens are sent to the DAO for later distribution
   * @param   _token  The address of the ERC-20 token to sweep
   */
  function sweepToken(IERC20 _token) external;
}

File 16 of 21 : HTokenInternalI.sol
//SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.4;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/access/IAccessControl.sol";

/**
 * @title   Interface of HToken Internal
 * @author  Honey Labs Inc.
 * @custom:coauthor m4rio
 * @custom:coauthor BowTiedPickle
 */
interface HTokenInternalI is IERC1155, IAccessControl {
  struct Coupon {
    uint32 id; //Coupon's id
    uint8 active; // Coupon activity status
    address owner; // Who is the current owner of this coupon
    uint256 collateralId; // tokenId of the collateral collection that is borrowed against
    uint256 borrowAmount; // Principal borrow balance, denominated in underlying ERC20 token.
    uint256 debtShares; // Debt shares, keeps the shares of total debt by the protocol
  }

  struct Collateral {
    uint256 collateralId; // TokenId of the collateral
    bool active; // Collateral activity status
  }

  // ----- Informational -----

  function decimals() external view returns (uint8);

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

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

  // ----- Addresses -----

  function collateralToken() external view returns (IERC721);

  function underlyingToken() external view returns (IERC20);

  // ----- Protocol Accounting -----

  function totalBorrows() external view returns (uint256);

  function totalReserves() external view returns (uint256);

  function totalSupply() external view returns (uint256);

  function totalFuseFees() external view returns (uint256);

  function totalAdminCommission() external view returns (uint256);

  function accrualBlockNumber() external view returns (uint256);

  function interestIndexStored() external view returns (uint256);

  function totalProtocolCommissions() external view returns (uint256);

  function userToCoupons(address _user) external view returns (uint256);

  function collateralPerBorrowCouponId(uint256 _couponId) external view returns (Collateral memory);

  function borrowCoupons(uint256 _collateralId) external view returns (Coupon memory);

  // ----- Views -----

  /**
   * @notice  Get the outstanding debt of a collateral
   * @dev     Simulates accrual of interest
   * @param   _collateralId   Token ID of underlying ERC-721
   * @return  Outstanding debt in units of underlying ERC-20
   */
  function getDebtForCollateral(uint256 _collateralId) external view returns (uint256);

  /**
   * @notice  Returns the current per-block borrow interest rate for this hToken
   * @return  The borrow interest rate per block, scaled by 1e18
   */
  function borrowRatePerBlock() external view returns (uint256);

  /**
   * @notice  Get the outstanding debt of a coupon
   * @dev     Simulates accrual of interest
   * @param   _couponId   ID of the coupon
   * @return  Outstanding debt in units of underlying ERC-20
   */
  function getDebtForCoupon(uint256 _couponId) external view returns (uint256);

  /**
   * @notice  Gets balance of this contract in terms of the underlying excluding the fees
   * @dev     This excludes the value of the current message, if any
   * @return  The quantity of underlying ERC-20 tokens owned by this contract
   */
  function getCashPrior() external view returns (uint256);

  /**
   * @notice  Get a snapshot of the account's balances, and the cached exchange rate
   * @dev     This is used by controller to more efficiently perform liquidity checks.
   * @param   _account  Address of the account to snapshot
   * @return  (token balance, borrow balance, exchange rate mantissa)
   */
  function getAccountSnapshot(address _account)
    external
    view
    returns (
      uint256,
      uint256,
      uint256
    );

  /**
   * @notice  Get the outstanding debt of the protocol
   * @return  Protocol debt
   */
  function getDebt() external view returns (uint256);

  /**
   * @notice  Returns protocol fees
   * @return  Reserve factor mantissa
   * @return  Admin fee mantissa
   * @return  Hive fee mantissa
   * @return  Initial exchange rate mantissa
   * @return  Maximum borrow rate mantissa
   */
  function getProtocolFees()
    external
    view
    returns (
      uint256,
      uint256,
      uint256,
      uint256,
      uint256
    );

  /**
   * @notice  Returns different addresses of the protocol
   * @return  Liquidator address
   * @return  HTokenHelper address
   * @return  Controller address
   * @return  Admin Fee Receiver address
   * @return  Hive Fee Receiver address
   * @return  Interest Model address
   * @return  Referral Pool address
   * @return  DAO address
   */
  function getAddresses()
    external
    view
    returns (
      address,
      address,
      address,
      address,
      address,
      address,
      address,
      address
    );

  /**
   * @notice  Get the last minted coupon ID
   * @return  The last minted coupon ID
   */
  function idCounter() external view returns (uint256);

  /**
   * @notice  Get the coupon for a specific collateral NFT
   * @param   _collateralId   Token ID of underlying ERC-721
   * @return  Coupon
   */
  function getSpecificCouponByCollateralId(uint256 _collateralId) external view returns (Coupon memory);

  /**
   * @notice  Calculate the prevailing interest due per token of debt principal
   * @return  Mantissa formatted interest rate per token of debt
   */
  function interestIndex() external view returns (uint256);

  /**
   * @notice  Accrue interest then return the up-to-date exchange rate from the ERC-20 underlying to the HToken
   * @return  Calculated exchange rate scaled by 1e18
   */
  function exchangeRateCurrent() external returns (uint256);

  /**
   * @notice  Calculates the exchange rate from the ERC-20 underlying to the HToken
   * @dev     This function does not accrue interest before calculating the exchange rate
   * @return  Calculated exchange rate scaled by 1e18
   */
  function exchangeRateStored() external view returns (uint256);

  /**
   * @notice  Add to or take away from reserves
   * @dev     Accrues interest
   * @param   _amount  Quantity of underlying ERC-20 token to change the reserves by
   */
  function _modifyReserves(uint256 _amount, bool _add) external;

  /**
   * @notice  Set new admin fee mantissas
   * @dev     Accrues interest
   * @param   _newAdminCommissionMantissa        New admin fee mantissa
   */
  function _setAdminCommission(uint256 _newAdminCommissionMantissa) external;

  /**
   * @notice  Set new protocol commission and reserve factor mantissas
   * @dev     Accrues interest
   * @param   _newProtocolCommissionMantissa         New protocol commission mantissa
   * @param   _newReserveFactorMantissa   New reserve factor mantissa
   */
  function _setProtocolFees(uint256 _newProtocolCommissionMantissa, uint256 _newReserveFactorMantissa) external;

  /**
   * @notice  Sets a new admin fee receiver
   * @param   _newAddress   Address of the new admin fee receiver
   * @param   _target       Target ID of the address to be set
   */
  function _setAddressMarketAdmin(address _newAddress, uint256 _target) external;
}

File 17 of 21 : PermissionlessOracleI.sol
//SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.4;

import "./HTokenI.sol";

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

/**
 * @title   PermissionlessOracleI interface for the Permissionless oracle
 * @author  Honey Labs Inc.
 * @custom:coauthor BowTiedPickle
 * @custom:coauthor m4rio
 */
interface PermissionlessOracleI {
  /**
   * @notice returns the price (in eth) for the floor of a collection
   * @param _collection address of the collection
   * @param _decimals adjust decimals of the returned price
   */
  function getFloorPrice(address _collection, uint256 _decimals) external view returns (uint128, uint128);

  /**
   * @notice returns the latest price for a given pair
   * @param _erc20 the erc20 we want to get the price for in USD
   * @param _decimals decimals to denote the result in
   */
  function getUnderlyingPriceInUSD(IERC20 _erc20, uint256 _decimals) external view returns (uint256);

  /**
   * @notice get price of eth
   * @param _decimals adjust decimals of the returned price
   */
  function getEthPrice(uint256 _decimals) external view returns (uint256);

  /**
   * @notice get price feeds for a token
   * @return returns the Chainlink Aggregator interface
   */
  function priceFeeds(IERC20 _token) external view returns (AggregatorV3Interface);

  /**
   * @notice returns the update threshold for a specific _collection
   */
  function updateThreshold(address _collection) external view returns (uint256);

  /**
   * @notice returns the number of floors for a specific _collection
   * @param _address address of the collection
   *
   */
  function getNoOfFloors(address _address) external view returns (uint256);

  /**
   * @notice returns the last updated timestamp for a specific _collection
   * @param _collection address of the collection
   *
   */
  function getLastUpdated(address _collection) external view returns (uint256);
}

File 18 of 21 : PriceOracleI.sol
//SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.4;

import "./HTokenI.sol";

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

/**
 * @title   PriceOracle interface for Chainlink oracles
 * @author  Honey Labs Inc.
 * @custom:coauthor BowTiedPickle
 * @custom:coauthor m4rio
 */
interface PriceOracleI {
  /**
   * @notice returns the underlying price for the floor of a collection
   * @param _collection address of the collection
   * @param _decimals adjust decimals of the returned price
   */
  function getFloorPrice(address _collection, uint256 _decimals) external view returns (uint128, uint128);

  /**
   * @notice returns the underlying price for an individual token id
   * @param _collection address of the collection
   * @param _tokenId token id within this collection
   * @param _decimals adjust decimals of the returned price
   */
  function getUnderlyingIndividualNFTPrice(
    address _collection,
    uint256 _tokenId,
    uint256 _decimals
  ) external view returns (uint256);

  /**
   * @notice returns the latest price for a given pair
   * @param _erc20 the erc20 we want to get the price for in USD
   * @param _decimals decimals to denote the result in
   */
  function getUnderlyingPriceInUSD(IERC20 _erc20, uint256 _decimals) external view returns (uint256);

  /**
   * @notice get price of eth
   * @param _decimals adjust decimals of the returned price
   */
  function getEthPrice(uint256 _decimals) external view returns (uint256);

  /**
   * @notice get price feeds for a token
   * @return returns the Chainlink Aggregator interface
   */
  function priceFeeds(IERC20 _token) external view returns (AggregatorV3Interface);

  /**
   * @notice returns the update threshold
   */
  function updateThreshold() external view returns (uint256);
}

File 19 of 21 : ErrorReporter.sol
//SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.15;

error Unauthorized();
error AccrueInterestError(Error error);
error WrongParams();
error Unexpected(string error);
error InvalidCoupon();
error ControllerError(Error error);
error AdminError(Error error);
error MarketError(Error error);
error HTokenError(Error error);
error LiquidatorError(Error error);
error ControlPanelError(Error error);
error HTokenFactoryError(Error error);
error PausedAction();
error NotOwner();
error ExternalFailure(string error);
error Initialized();
error Uninitialized();
error OracleNotUpdated();
error TransferError();
error StalePrice();

/**
 * @title   Errors reported across Honey Labs Inc. contracts
 * @author  Honey Labs Inc.
 * @custom:coauthor BowTiedPickle
 * @custom:coauthor m4rio
 */
enum Error {
  UNAUTHORIZED, //0
  INSUFFICIENT_LIQUIDITY,
  INVALID_COLLATERAL_FACTOR,
  MAX_MARKETS_IN,
  MARKET_NOT_LISTED,
  MARKET_ALREADY_LISTED, //5
  MARKET_CAP_BORROW_REACHED,
  MARKET_NOT_FRESH,
  PRICE_ERROR,
  BAD_INPUT,
  AMOUNT_ZERO, //10
  NO_DEBT,
  LIQUIDATION_NOT_ALLOWED,
  WITHDRAW_NOT_ALLOWED,
  INITIAL_EXCHANGE_MANTISSA,
  TRANSFER_ERROR, //15
  COUPON_LOOKUP,
  TOKEN_INSUFFICIENT_CASH,
  BORROW_RATE_TOO_BIG,
  NONZERO_BORROW_BALANCE,
  AMOUNT_TOO_BIG, //20
  AUCTION_NOT_ACTIVE,
  AUCTION_FINISHED,
  AUCTION_NOT_FINISHED,
  AUCTION_BID_TOO_LOW,
  AUCTION_NO_BIDS, //25
  CLAWBACK_WINDOW_EXPIRED,
  CLAWBACK_WINDOW_NOT_EXPIRED,
  REFUND_NOT_OWED,
  TOKEN_LOOKUP_ERROR,
  INSUFFICIENT_WINNING_BID, //30
  TOKEN_DEBT_NONEXISTENT,
  AUCTION_SETTLE_FORBIDDEN,
  NFT20_PAIR_NOT_FOUND,
  NFTX_PAIR_NOT_FOUND,
  TOKEN_NOT_PRESENT, //35
  CANCEL_TOO_SOON,
  AUCTION_USER_NOT_FOUND,
  NOT_FOUND,
  INVALID_MAX_LTV_FACTOR,
  BALANCE_INSUFFICIENT, //40
  ORACLE_NOT_SET,
  MARKET_INVALID,
  FACTORY_INVALID_COLLATERAL,
  FACTORY_INVALID_UNDERLYING,
  FACTORY_INVALID_ORACLE, //45
  FACTORY_DEPLOYMENT_FAILED,
  REPAY_NOT_ALLOWED,
  NONZERO_UNDERLYING_BALANCE,
  INVALID_ACTION,
  ORACLE_IS_PRESENT, //50
  FACTORY_INVALID_UNDERLYING_DECIMALS,
  FACTORY_INVALID_INTEREST_RATE_MODEL
}

File 20 of 21 : HTokenHelper.sol
//SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.15;

import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";

import "solidity-json-writer/contracts/JsonWriter.sol";

import ".././interfaces/HTokenI.sol";
import ".././interfaces/ControllerI.sol";
import ".././interfaces/PermissionlessOracleI.sol";
import ".././interfaces/HTokenHelperI.sol";
import ".././utils/ErrorReporter.sol";

/**
 * @title   A hToken helper as the contract started to get big.
 * @notice  This deals with different frontend functions for easy computation on the frontend
 * @dev     Do not use these functions in any contract as they are only created for the frontend purposes
 * @author  Honey Labs Inc.
 * @custom:coauthor     m4rio
 * @custom:contributor  BowTiedPickle
 */
contract HTokenHelper is HTokenHelperI, Ownable {
  using Strings for uint256;
  using JsonWriter for JsonWriter.Json;

  /// @notice Version of the contract. 1_000_000 corresponds to 1.0.0
  uint256 public constant version = 1_000_000;

  uint256 public constant DENOMINATOR = 10_000;

  event OracleChanged(PermissionlessOracleI _oldOracle, PermissionlessOracleI _newOracle);
  event ThresholdUpdated(uint256 _oldThreshold, uint256 _newThreshold);

  /**
   * @notice Get cash balance of this hToken in the underlying asset
   * @return The quantity of underlying asset owned by this contract
   */
  function getCash(HTokenI _hToken) external view override returns (uint256) {
    return _hToken.getCashPrior();
  }

  /**
   * @notice Get underlying balance that is available for withdrawal or borrow
   * @return The quantity of underlying not tied up
   */
  function getAvailableUnderlying(HTokenI _hToken) external view override returns (uint256) {
    return
      _hToken.getCashPrior() -
      _hToken.totalReserves() -
      _hToken.totalAdminCommission() -
      _hToken.totalProtocolCommissions();
  }

  /**
   * @notice Get underlying balance for an account
   * @param _account the account to check the balance for
   * @return The quantity of underlying asset owned by this account
   */
  function getAvailableUnderlyingForUser(HTokenI _hToken, address _account) external view override returns (uint256) {
    return (_hToken.balanceOf(_account, 0) * _hToken.exchangeRateStored()) / 1e18;
  }

  /**
   * @notice Get underlying balance that is available to be withdrawn
   * @return The quantity of underlying that can be borrowed
   */
  function getAvailableUnderlyingToBorrow(HTokenI _hToken) external view override returns (uint256) {
    return _hToken.getCashPrior();
  }

  /**
   * @notice returns different assets per a hToken, helper method to reduce frontend calls
   * @param  _hToken the hToken to get the assets for
   * @return total borrows
   * @return total reserves
   * @return total underlying balance
   * @return active coupons
   */
  function getAssets(HTokenI _hToken)
    external
    view
    override
    returns (
      uint256,
      uint256,
      uint256,
      HTokenI.Coupon[] memory
    )
  {
    uint256 totalBorrow = _hToken.totalBorrows();
    uint256 totalReserves = _hToken.totalReserves();
    uint256 underlyingBalance = _hToken.underlyingToken().balanceOf(address(_hToken));
    HTokenI.Coupon[] memory activeCoupons = getActiveCoupons(_hToken, false);
    return (totalBorrow, totalReserves, underlyingBalance, activeCoupons);
  }

  /**
   * @notice Get all a user's coupons
   * @param  _hToken The HToken we want to get the user's coupons from
   * @param  _user   The user to search for
   * @return Array of all coupons belonging to the user
   */
  function getUserCoupons(HTokenI _hToken, address _user) external view returns (HTokenI.Coupon[] memory) {
    unchecked {
      HTokenI.Coupon[] memory userCoupons = new HTokenI.Coupon[](_hToken.userToCoupons(_user));
      uint256 length = _hToken.idCounter();
      uint256 counter;
      for (uint256 i; i < length; ++i) {
        HTokenI.Collateral memory collateral = _hToken.collateralPerBorrowCouponId(i);
        if (!collateral.active) continue;
        HTokenI.Coupon memory coupon = _hToken.borrowCoupons(collateral.collateralId);

        if (coupon.owner == _user) {
          userCoupons[counter++] = coupon;
        }
      }

      return userCoupons;
    }
  }

  /**
   * @notice Get the number of coupons deposited aka active
   * @param  _hToken The HToken we want to get the active User Coupons
   * @param _hasDebt if the coupon has debt or not
   * @return Array of all active coupons
   */
  function getActiveCoupons(HTokenI _hToken, bool _hasDebt) public view returns (HTokenI.Coupon[] memory) {
    unchecked {
      HTokenI.Coupon[] memory depositedCoupons;
      uint256 length = _hToken.idCounter();
      uint256 deposited;
      for (uint256 i; i < length; ++i) {
        HTokenI.Collateral memory collateral = _hToken.collateralPerBorrowCouponId(i);
        HTokenI.Coupon memory coupon = _hToken.getSpecificCouponByCollateralId(collateral.collateralId);
        if (collateral.active && ((_hasDebt && coupon.borrowAmount > 0) || !_hasDebt)) {
          ++deposited;
        }
      }
      depositedCoupons = new HTokenI.Coupon[](deposited);
      uint256 j;
      for (uint256 i; i < length; ++i) {
        HTokenI.Collateral memory collateral = _hToken.collateralPerBorrowCouponId(i);
        HTokenI.Coupon memory coupon = _hToken.getSpecificCouponByCollateralId(collateral.collateralId);

        if (collateral.active && ((_hasDebt && coupon.borrowAmount > 0) || !_hasDebt)) {
          depositedCoupons[j] = coupon;

          // This condition means "if j == deposited then break, else continue the loop with j + 1".
          // This is a gas optimization to avoid potentially unnecessary storage readings
          if (j++ == deposited) {
            break;
          }
        }
      }
      return depositedCoupons;
    }
  }

  /**
   * @notice Get tokenIds of all a user's coupons
   * @param  _hToken The HToken we want to get the User Coupon Indices
   * @param  _user The user to search for
   * @return Array of indices of all coupons belonging to the user
   */
  function getUserCouponIndices(HTokenI _hToken, address _user) external view returns (uint256[] memory) {
    unchecked {
      uint256[] memory userCoupons = new uint256[](_hToken.userToCoupons(_user));
      uint256 length = _hToken.idCounter();
      uint256 counter;
      for (uint256 i; i < length; ++i) {
        HTokenI.Collateral memory collateral = _hToken.collateralPerBorrowCouponId(i);
        if (!collateral.active) continue;
        HTokenI.Coupon memory coupon = _hToken.borrowCoupons(collateral.collateralId);

        if (coupon.owner == _user) {
          userCoupons[counter++] = i;
        }
      }

      return userCoupons;
    }
  }

  /**
   * @notice returns prices of floor and underlying for a market to reduce frontend calls
   * @param _hToken the hToken to get the prices for
   * @return collection floor price in underlying value
   * @return underlying price in usd
   */
  function getMarketOraclePrices(HTokenI _hToken) external view override returns (uint256, uint256) {
    uint8 decimals = _hToken.decimals();
    address controller;
    (, , controller, , , , , ) = _hToken.getAddresses();
    PermissionlessOracleI cachedOracle = ControllerI(controller).oracle(_hToken);

    (uint128 floorPriceInETH, ) = cachedOracle.getFloorPrice(address(_hToken.collateralToken()), decimals);

    uint256 underlyingPriceInUSD = internalUnderlyingPriceInUSD(_hToken);
    uint256 ethPrice = uint256(cachedOracle.getEthPrice(decimals));

    return (
      ((floorPriceInETH * ethPrice) * DENOMINATOR) / underlyingPriceInUSD / 10**decimals,
      (underlyingPriceInUSD * DENOMINATOR) / 10**decimals
    );
  }

  /**
   * @notice Returns the borrow fee for a market, it can also return the discounted fee for referred borrow
   * @param _hToken The market we want to get the borrow fee for
   * @param _referred Flag that needs to be true in case we want to get the referred borrow fee
   * @return fee - The borrow fee mantissa denominated in 1e18
   */
  function getMarketBorrowFee(HTokenI _hToken, bool _referred) external view override returns (uint256 fee) {
    address controller;
    (, , controller, , , , , ) = _hToken.getAddresses();
    if (!_referred) {
      (fee, ) = ControllerI(controller).getBorrowFeePerMarket(_hToken, "", "");
    } else fee = ControllerI(controller).getReferralBorrowFeePerMarket(_hToken);
  }

  /**
   * @notice returns the collection price floor in usd
   * @param _hToken the hToken to get the price for
   * @return collection floor price in usd
   */
  function getFloorPriceInUSD(HTokenI _hToken) public view override returns (uint256) {
    uint256 floorPrice = internalFloorPriceInUSD(_hToken);
    return (floorPrice * DENOMINATOR) / 1e18;
  }

  /**
   * @notice returns the collection price floor in underlying value
   * @param _hToken the hToken to get the price for
   * @return collection floor price in underlying
   */
  function getFloorPriceInUnderlying(HTokenI _hToken) public view returns (uint256) {
    uint256 floorPrice = internalFloorPriceInUSD(_hToken);
    uint256 underlyingPriceInUSD = internalUnderlyingPriceInUSD(_hToken);
    return (floorPrice * DENOMINATOR) / underlyingPriceInUSD;
  }

  /**
   * @notice get the underlying price in usd for a hToken
   * @param _hToken the hToken to get the price for
   * @return underlying price in usd
   */
  function getUnderlyingPriceInUSD(HTokenI _hToken) public view override returns (uint256) {
    return (internalUnderlyingPriceInUSD(_hToken) * DENOMINATOR) / 10**_hToken.decimals();
  }

  /**
   * @notice get the max borrowable amount for a market
   * @notice it computes the floor price in usd and take the % of collateral factor that can be max borrowed
   *         then it divides it by the underlying price in usd.
   * @param _hToken the hToken to get the price for
   * @param _controller the controller used to get the collateral factor
   * @return underlying price in underlying
   */
  function getMaxBorrowableAmountInUnderlying(HTokenI _hToken, ControllerI _controller)
    external
    view
    returns (uint256)
  {
    uint256 floorPrice = internalFloorPriceInUSD(_hToken);
    uint256 underlyingPriceInUSD = internalUnderlyingPriceInUSD(_hToken);
    (, uint256 LTVfactor, ) = _controller.getMarketData(_hToken);
    // removing mantissa of 1e18
    return ((LTVfactor * floorPrice) * DENOMINATOR) / underlyingPriceInUSD / 1e18;
  }

  /**
   * @notice get the max borrowable amount for a market
   * @notice it computes the floor price in usd and take the % of collateral factor that can be max borrowed
   * @param _hToken the hToken to get the price for
   * @param _controller the controller used to get the collateral factor
   * @return underlying price in usd
   */
  function getMaxBorrowableAmountInUSD(HTokenI _hToken, ControllerI _controller) external view returns (uint256) {
    uint256 floorPrice = internalFloorPriceInUSD(_hToken);
    (, , uint256 collateralFactor) = _controller.getMarketData(_hToken);
    return ((collateralFactor * floorPrice) * DENOMINATOR) / 1e18 / 10**_hToken.decimals();
  }

  /**
   * @notice get's all the coupons that have deposited collateral
   * @param _hToken market to get the collateral from
   * @param _startTokenId start token id of the collateral collection, as we don't know how big the collection will be we have
   * to do pagination
   * @param _endTokenId end of token id we want to get.
   * @return coupons list of coupons that are active
   */
  function getAllCollateralPerHToken(
    HTokenI _hToken,
    uint256 _startTokenId,
    uint256 _endTokenId
  ) external view returns (HTokenI.Coupon[] memory coupons) {
    unchecked {
      coupons = new HTokenI.Coupon[](_endTokenId - _startTokenId);
      for (uint256 i = _startTokenId; i <= _endTokenId; ++i) {
        HTokenI.Coupon memory coupon = _hToken.borrowCoupons(i);
        if (coupon.active == 2) coupons[i - _startTokenId] = coupon;
      }
    }
  }

  /**
   * @notice Gets data about a market for frontend display
   * @param _hToken the market we want the data for
   * @return interest rate of the market
   * @return total underlying supplied in a market
   * @return total underlying available to be borrowed
   */
  function getFrontendMarketData(HTokenI _hToken)
    external
    view
    returns (
      uint256,
      uint256,
      uint256
    )
  {
    uint256 hTokenSupply = _hToken.totalSupply();
    uint256 exchangeRate = _hToken.exchangeRateStored();
    return (5_000, (hTokenSupply * exchangeRate) / 1e18, _hToken.getCashPrior() - _hToken.totalReserves());
  }

  /**
   * @notice Gets data about a coupon for frontend display
   * @param _hToken   The market we want the coupon for
   * @param _couponId The coupon id we want to get the data for
   * @return debt of this coupon
   * @return allowance - how much liquidity can borrow till hitting LTV
   * @return nft floor price
   */
  function getFrontendCouponData(HTokenI _hToken, uint256 _couponId)
    external
    view
    returns (
      uint256,
      uint256,
      uint256
    )
  {
    address controller;
    (, , controller, , , , , ) = _hToken.getAddresses();
    HTokenInternalI.Collateral memory collateral = _hToken.collateralPerBorrowCouponId(_couponId);
    HTokenInternalI.Coupon memory coupon = _hToken.borrowCoupons(collateral.collateralId);

    uint256 liquidityTillLTV;
    (, , liquidityTillLTV) = ControllerI(controller).getHypotheticalAccountLiquidity(
      _hToken,
      coupon.owner,
      collateral.collateralId,
      0,
      0
    );
    return (_hToken.getDebtForCoupon(_couponId), liquidityTillLTV, getFloorPriceInUnderlying(_hToken));
  }

  /**
   * @notice Gets Liquidation data for a market, for frontend purposes
   * @param _hToken the market we want the data for
   * @return Liquidation threshold of a market (collateral factor)
   * @return Total debt of the market
   * @return TVL is an aproximate value of the NFTs deposited within a market, we only count the NFTs that have debt
   */
  function getFrontendLiquidationData(HTokenI _hToken)
    external
    view
    returns (
      uint256,
      uint256,
      uint256
    )
  {
    address controller;
    (, , controller, , , , , ) = _hToken.getAddresses();
    uint256 floorPrice = getFloorPriceInUnderlying(_hToken);
    (, uint256 liquidationThreshold, ) = ControllerI(controller).getMarketData(_hToken);
    uint256 length = _hToken.idCounter();
    uint256 debtCoupons;
    for (uint256 i; i < length; ++i) {
      HTokenI.Collateral memory collateral = _hToken.collateralPerBorrowCouponId(i);
      HTokenI.Coupon memory coupon = _hToken.getSpecificCouponByCollateralId(collateral.collateralId);
      if (collateral.active && coupon.borrowAmount > 0) {
        ++debtCoupons;
      }
    }
    return (liquidationThreshold, _hToken.totalBorrows(), debtCoupons * floorPrice);
  }

  /**
   * @notice uri function called from the HToken that returns the uri metadata for a coupon
   * @param _id id of the hToken
   * @param _hTokenAddress address of the hToken
   */
  function uri(uint256 _id, address _hTokenAddress) external view override returns (string memory) {
    HTokenI _hToken = HTokenI(_hTokenAddress);

    JsonWriter.Json memory writer;
    writer = writer.writeStartObject();
    if (_id > 0) {
      HTokenI.Collateral memory collateral = _hToken.collateralPerBorrowCouponId(_id);

      if (!collateral.active) revert WrongParams();

      HTokenI.Coupon memory coupon = _hToken.borrowCoupons(collateral.collateralId);

      writer = writer.writeStringProperty("name", string.concat("Honey Coupon ", _id.toString()));
      writer = writer.writeStringProperty("description", string.concat("Honey Coupon for Market ", _hToken.symbol()));
      writer = writer.writeStringProperty("external_url", "https://honey.finance");
      writer = writer.writeStringProperty("image", "https://honey.finance");
      writer = writer.writeStartArray("attributes");

      writer = writer.writeStartObject();
      writer = writer.writeStringProperty("trait_type", "BORROW_AMOUNT");
      writer = writer.writeStringProperty("value", coupon.borrowAmount.toString());
      writer = writer.writeEndObject();

      writer = writer.writeStartObject();
      writer = writer.writeStringProperty("trait_type", "DEBT_SHARES");
      writer = writer.writeStringProperty("value", coupon.debtShares.toString());
      writer = writer.writeEndObject();

      writer = writer.writeStartObject();
      writer = writer.writeStringProperty("trait_type", "COLLATERAL_ID");
      writer = writer.writeStringProperty("value", coupon.collateralId.toString());
      writer = writer.writeEndObject();

      writer = writer.writeStartObject();
      writer = writer.writeStringProperty("trait_type", "COLLATERAL_ADDRESS");
      writer = writer.writeStringProperty("value", toString(abi.encodePacked(address(_hToken.collateralToken()))));
      writer = writer.writeEndObject();
    } else {
      writer = writer.writeStringProperty(
        "name",
        string.concat(HTokenInternalI(_hToken).name(), " ", HTokenInternalI(_hToken).symbol())
      );
      writer = writer.writeStringProperty(
        "description",
        string.concat(
          "Honey Market with underlying ",
          IERC20Metadata(address(_hToken.underlyingToken())).name(),
          " and collateral ",
          IERC721Metadata(address(_hToken.collateralToken())).name()
        )
      );
      writer = writer.writeStringProperty("external_url", "https://honey.finance");
      writer = writer.writeStringProperty("image", "https://honey.finance");
      writer = writer.writeStartArray("attributes");

      writer = writer.writeStartObject();
      writer = writer.writeStringProperty("trait_type", "SUPPLY");
      writer = writer.writeStringProperty("value", _hToken.totalSupply().toString());
      writer = writer.writeEndObject();
    }

    writer = writer.writeEndArray();
    writer = writer.writeEndObject();
    return writer.value;
  }

  function toString(bytes memory data) internal pure returns (string memory) {
    bytes memory alphabet = "0123456789abcdef";

    uint256 len = data.length;

    bytes memory str = new bytes(2 + len * 2);
    str[0] = "0";
    str[1] = "x";

    for (uint256 i; i < len; ) {
      str[2 + i * 2] = alphabet[uint256(uint8(data[i] >> 4))];
      str[3 + i * 2] = alphabet[uint256(uint8(data[i] & 0x0f))];
      unchecked {
        ++i;
      }
    }
    return string(str);
  }

  function internalFloorPriceInUSD(HTokenI _hToken) internal view returns (uint256) {
    uint8 decimals = _hToken.decimals();
    address controller;
    (, , controller, , , , , ) = _hToken.getAddresses();
    PermissionlessOracleI cachedOracle = ControllerI(controller).oracle(_hToken);
    (uint128 floorPriceInETH, ) = cachedOracle.getFloorPrice(address(_hToken.collateralToken()), decimals);

    uint256 ethPrice = uint256(cachedOracle.getEthPrice(decimals));

    return (floorPriceInETH * ethPrice) / 10**decimals;
  }

  function internalUnderlyingPriceInUSD(HTokenI _hToken) internal view returns (uint256) {
    address controller;
    (, , controller, , , , , ) = _hToken.getAddresses();
    PermissionlessOracleI cachedOracle = ControllerI(controller).oracle(_hToken);

    return uint256(cachedOracle.getUnderlyingPriceInUSD(_hToken.underlyingToken(), _hToken.decimals()));
  }
}

File 21 of 21 : JsonWriter.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library JsonWriter {

    using JsonWriter for string;

    struct Json {
        int256 depthBitTracker;
        string value;
    }

    bytes1 constant BACKSLASH = bytes1(uint8(92));
    bytes1 constant BACKSPACE = bytes1(uint8(8));
    bytes1 constant CARRIAGE_RETURN = bytes1(uint8(13));
    bytes1 constant DOUBLE_QUOTE = bytes1(uint8(34));
    bytes1 constant FORM_FEED = bytes1(uint8(12));
    bytes1 constant FRONTSLASH = bytes1(uint8(47));
    bytes1 constant HORIZONTAL_TAB = bytes1(uint8(9));
    bytes1 constant NEWLINE = bytes1(uint8(10));

    string constant TRUE = "true";
    string constant FALSE = "false";
    bytes1 constant OPEN_BRACE = "{";
    bytes1 constant CLOSED_BRACE = "}";
    bytes1 constant OPEN_BRACKET = "[";
    bytes1 constant CLOSED_BRACKET = "]";
    bytes1 constant LIST_SEPARATOR = ",";

    int256 constant MAX_INT256 = type(int256).max;

    /**
     * @dev Writes the beginning of a JSON array.
     */
    function writeStartArray(Json memory json) 
        internal
        pure
        returns (Json memory)
    {
        return writeStart(json, OPEN_BRACKET);
    }

    /**
     * @dev Writes the beginning of a JSON array with a property name as the key.
     */
    function writeStartArray(Json memory json, string memory propertyName)
        internal
        pure
        returns (Json memory)
    {
        return writeStart(json, propertyName, OPEN_BRACKET);
    }

    /**
     * @dev Writes the beginning of a JSON object.
     */
    function writeStartObject(Json memory json)
        internal
        pure
        returns (Json memory)
    {
        return writeStart(json, OPEN_BRACE);
    }

    /**
     * @dev Writes the beginning of a JSON object with a property name as the key.
     */
    function writeStartObject(Json memory json, string memory propertyName)
        internal
        pure
        returns (Json memory)
    {
        return writeStart(json, propertyName, OPEN_BRACE);
    }

    /**
     * @dev Writes the end of a JSON array.
     */
    function writeEndArray(Json memory json)
        internal
        pure
        returns (Json memory)
    {
        return writeEnd(json, CLOSED_BRACKET);
    }

    /**
     * @dev Writes the end of a JSON object.
     */
    function writeEndObject(Json memory json)
        internal
        pure
        returns (Json memory)
    {
        return writeEnd(json, CLOSED_BRACE);
    }

    /**
     * @dev Writes the property name and address value (as a JSON string) as part of a name/value pair of a JSON object.
     */
    function writeAddressProperty(
        Json memory json,
        string memory propertyName,
        address value
    ) internal pure returns (Json memory) {
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, '"', propertyName, '": "', addressToString(value), '"'));
        } else {
            json.value = string(abi.encodePacked(json.value, '"', propertyName, '": "', addressToString(value), '"'));
        }

        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the address value (as a JSON string) as an element of a JSON array.
     */
    function writeAddressValue(Json memory json, address value)
        internal
        pure
        returns (Json memory)
    {
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, '"', addressToString(value), '"'));
        } else {
            json.value = string(abi.encodePacked(json.value, '"', addressToString(value), '"'));
        }

        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the property name and boolean value (as a JSON literal "true" or "false") as part of a name/value pair of a JSON object.
     */
    function writeBooleanProperty(
        Json memory json,
        string memory propertyName,
        bool value
    ) internal pure returns (Json memory) {
        string memory strValue;
        if (value) {
            strValue = TRUE;
        } else {
            strValue = FALSE;
        }

        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, '"', propertyName, '": ', strValue));
        } else {
            json.value = string(abi.encodePacked(json.value, '"', propertyName, '": ', strValue));
        }

        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the boolean value (as a JSON literal "true" or "false") as an element of a JSON array.
     */
    function writeBooleanValue(Json memory json, bool value)
        internal
        pure
        returns (Json memory)
    {
        string memory strValue;
        if (value) {
            strValue = TRUE;
        } else {
            strValue = FALSE;
        }

        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, strValue));
        } else {
            json.value = string(abi.encodePacked(json.value, strValue));
        }
        
        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the property name and int value (as a JSON number) as part of a name/value pair of a JSON object.
     */
    function writeIntProperty(
        Json memory json,
        string memory propertyName,
        int256 value
    ) internal pure returns (Json memory) {
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, '"', propertyName, '": ', intToString(value)));
        } else {
            json.value = string(abi.encodePacked(json.value, '"', propertyName, '": ', intToString(value)));
        }

        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the int value (as a JSON number) as an element of a JSON array.
     */
    function writeIntValue(Json memory json, int256 value)
        internal
        pure
        returns (Json memory)
    {
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, intToString(value)));
        } else {
            json.value = string(abi.encodePacked(json.value, intToString(value)));
        }
        
        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the property name and value of null as part of a name/value pair of a JSON object.
     */
    function writeNullProperty(Json memory json, string memory propertyName)
        internal
        pure
        returns (Json memory)
    {
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, '"', propertyName, '": null'));
        } else {
            json.value = string(abi.encodePacked(json.value, '"', propertyName, '": null'));
        }

        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the value of null as an element of a JSON array.
     */
    function writeNullValue(Json memory json)
        internal
        pure
        returns (Json memory)
    {
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, "null"));
        } else {
            json.value = string(abi.encodePacked(json.value, "null"));
        }

        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the string text value (as a JSON string) as an element of a JSON array.
     */
    function writeStringProperty(
        Json memory json,
        string memory propertyName,
        string memory value
    ) internal pure returns (Json memory) {
        string memory jsonEscapedString = escapeJsonString(value);
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, '"', propertyName, '": "', jsonEscapedString, '"'));
        } else {
            json.value = string(abi.encodePacked(json.value, '"', propertyName, '": "', jsonEscapedString, '"'));
        }

        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the property name and string text value (as a JSON string) as part of a name/value pair of a JSON object.
     */
    function writeStringValue(Json memory json, string memory value)
        internal
        pure
        returns (Json memory)
    {
        string memory jsonEscapedString = escapeJsonString(value);
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, '"', jsonEscapedString, '"'));
        } else {
            json.value = string(abi.encodePacked(json.value, '"', jsonEscapedString, '"'));
        }

        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the property name and uint value (as a JSON number) as part of a name/value pair of a JSON object.
     */
    function writeUintProperty(
        Json memory json,
        string memory propertyName,
        uint256 value
    ) internal pure returns (Json memory) {
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, '"', propertyName, '": ', uintToString(value)));
        } else {
            json.value = string(abi.encodePacked(json.value, '"', propertyName, '": ', uintToString(value)));
        }

        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the uint value (as a JSON number) as an element of a JSON array.
     */
    function writeUintValue(Json memory json, uint256 value)
        internal
        pure
        returns (Json memory)
    {
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, uintToString(value)));
        } else {
            json.value = string(abi.encodePacked(json.value, uintToString(value)));
        }

        json.depthBitTracker = setListSeparatorFlag(json);

        return json;
    }

    /**
     * @dev Writes the beginning of a JSON array or object based on the token parameter.
     */
    function writeStart(Json memory json, bytes1 token)
        private
        pure
        returns (Json memory)
    {
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, token));
        } else {
            json.value = string(abi.encodePacked(json.value, token));
        }

        json.depthBitTracker &= MAX_INT256;
        json.depthBitTracker++;

        return json;
    }

    /**
     * @dev Writes the beginning of a JSON array or object based on the token parameter with a property name as the key.
     */
    function writeStart(
        Json memory json,
        string memory propertyName,
        bytes1 token
    ) private pure returns (Json memory) {
        if (json.depthBitTracker < 0) {
            json.value = string(abi.encodePacked(json.value, LIST_SEPARATOR, '"', propertyName, '": ', token));
        } else {
            json.value = string(abi.encodePacked(json.value, '"', propertyName, '": ', token));
        }

        json.depthBitTracker &= MAX_INT256;
        json.depthBitTracker++;

        return json;
    }

    /**
     * @dev Writes the end of a JSON array or object based on the token parameter.
     */
    function writeEnd(Json memory json, bytes1 token)
        private
        pure
        returns (Json memory)
    {
        json.value = string(abi.encodePacked(json.value, token));
        json.depthBitTracker = setListSeparatorFlag(json);
        
        if (getCurrentDepth(json) != 0) {
            json.depthBitTracker--;
        }

        return json;
    }

    /**
     * @dev Escapes any characters that required by JSON to be escaped.
     */
    function escapeJsonString(string memory value)
        private
        pure
        returns (string memory str)
    {
        bytes memory b = bytes(value);
        bool foundEscapeChars;

        for (uint256 i; i < b.length; i++) {
            if (b[i] == BACKSLASH) {
                foundEscapeChars = true;
                break;
            } else if (b[i] == DOUBLE_QUOTE) {
                foundEscapeChars = true;
                break;
            } else if (b[i] == FRONTSLASH) {
                foundEscapeChars = true;
                break;
            } else if (b[i] == HORIZONTAL_TAB) {
                foundEscapeChars = true;
                break;
            } else if (b[i] == FORM_FEED) {
                foundEscapeChars = true;
                break;
            } else if (b[i] == NEWLINE) {
                foundEscapeChars = true;
                break;
            } else if (b[i] == CARRIAGE_RETURN) {
                foundEscapeChars = true;
                break;
            } else if (b[i] == BACKSPACE) {
                foundEscapeChars = true;
                break;
            }
        }

        if (!foundEscapeChars) {
            return value;
        }

        for (uint256 i; i < b.length; i++) {
            if (b[i] == BACKSLASH) {
                str = string(abi.encodePacked(str, "\\\\"));
            } else if (b[i] == DOUBLE_QUOTE) {
                str = string(abi.encodePacked(str, '\\"'));
            } else if (b[i] == FRONTSLASH) {
                str = string(abi.encodePacked(str, "\\/"));
            } else if (b[i] == HORIZONTAL_TAB) {
                str = string(abi.encodePacked(str, "\\t"));
            } else if (b[i] == FORM_FEED) {
                str = string(abi.encodePacked(str, "\\f"));
            } else if (b[i] == NEWLINE) {
                str = string(abi.encodePacked(str, "\\n"));
            } else if (b[i] == CARRIAGE_RETURN) {
                str = string(abi.encodePacked(str, "\\r"));
            } else if (b[i] == BACKSPACE) {
                str = string(abi.encodePacked(str, "\\b"));
            } else {
                str = string(abi.encodePacked(str, b[i]));
            }
        }

        return str;
    }

    /**
     * @dev Tracks the recursive depth of the nested objects / arrays within the JSON text
     * written so far. This provides the depth of the current token.
     */
    function getCurrentDepth(Json memory json) private pure returns (int256) {
        return json.depthBitTracker & MAX_INT256;
    }

    /**
     * @dev The highest order bit of json.depthBitTracker is used to discern whether we are writing the first item in a list or not.
     * if (json.depthBitTracker >> 255) == 1, add a list separator before writing the item
     * else, no list separator is needed since we are writing the first item.
     */
    function setListSeparatorFlag(Json memory json)
        private
        pure
        returns (int256)
    {
        return json.depthBitTracker | (int256(1) << 255);
    }

        /**
     * @dev Converts an address to a string.
     */
    function addressToString(address _address)
        internal
        pure
        returns (string memory)
    {
        bytes32 value = bytes32(uint256(uint160(_address)));
        bytes16 alphabet = "0123456789abcdef";

        bytes memory str = new bytes(42);
        str[0] = "0";
        str[1] = "x";
        for (uint256 i; i < 20; i++) {
            str[2 + i * 2] = alphabet[uint8(value[i + 12] >> 4)];
            str[3 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)];
        }

        return string(str);
    }

    /**
     * @dev Converts an int to a string.
     */
    function intToString(int256 i) internal pure returns (string memory) {
        if (i == 0) {
            return "0";
        }

        if (i == type(int256).min) {
            // hard-coded since int256 min value can't be converted to unsigned
            return "-57896044618658097711785492504343953926634992332820282019728792003956564819968"; 
        }

        bool negative = i < 0;
        uint256 len;
        uint256 j;
        if(!negative) {
            j = uint256(i);
        } else {
            j = uint256(-i);
            ++len; // make room for '-' sign
        }
        
        uint256 l = j;
        while (j != 0) {
            len++;
            j /= 10;
        }

        bytes memory bstr = new bytes(len);
        uint256 k = len;
        while (l != 0) {
            bstr[--k] = bytes1((48 + uint8(l - (l / 10) * 10)));
            l /= 10;
        }

        if (negative) {
            bstr[0] = "-"; // prepend '-'
        }

        return string(bstr);
    }

    /**
     * @dev Converts a uint to a string.
     */
    function uintToString(uint256 _i) internal pure returns (string memory) {
        if (_i == 0) {
            return "0";
        }

        uint256 j = _i;
        uint256 len;
        while (j != 0) {
            len++;
            j /= 10;
        }

        bytes memory bstr = new bytes(len);
        uint256 k = len;
        while (_i != 0) {
            bstr[--k] = bytes1((48 + uint8(_i - (_i / 10) * 10)));
            _i /= 10;
        }

        return string(bstr);
    }
}

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

Contract Security Audit

Contract ABI

[{"inputs":[],"name":"WrongParams","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract PermissionlessOracleI","name":"_oldOracle","type":"address"},{"indexed":false,"internalType":"contract PermissionlessOracleI","name":"_newOracle","type":"address"}],"name":"OracleChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_oldThreshold","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newThreshold","type":"uint256"}],"name":"ThresholdUpdated","type":"event"},{"inputs":[],"name":"DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"bool","name":"_hasDebt","type":"bool"}],"name":"getActiveCoupons","outputs":[{"components":[{"internalType":"uint32","name":"id","type":"uint32"},{"internalType":"uint8","name":"active","type":"uint8"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"collateralId","type":"uint256"},{"internalType":"uint256","name":"borrowAmount","type":"uint256"},{"internalType":"uint256","name":"debtShares","type":"uint256"}],"internalType":"struct HTokenInternalI.Coupon[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_startTokenId","type":"uint256"},{"internalType":"uint256","name":"_endTokenId","type":"uint256"}],"name":"getAllCollateralPerHToken","outputs":[{"components":[{"internalType":"uint32","name":"id","type":"uint32"},{"internalType":"uint8","name":"active","type":"uint8"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"collateralId","type":"uint256"},{"internalType":"uint256","name":"borrowAmount","type":"uint256"},{"internalType":"uint256","name":"debtShares","type":"uint256"}],"internalType":"struct HTokenInternalI.Coupon[]","name":"coupons","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"getAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"components":[{"internalType":"uint32","name":"id","type":"uint32"},{"internalType":"uint8","name":"active","type":"uint8"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"collateralId","type":"uint256"},{"internalType":"uint256","name":"borrowAmount","type":"uint256"},{"internalType":"uint256","name":"debtShares","type":"uint256"}],"internalType":"struct HTokenInternalI.Coupon[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"getAvailableUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"address","name":"_account","type":"address"}],"name":"getAvailableUnderlyingForUser","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"getAvailableUnderlyingToBorrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"getCash","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"getFloorPriceInUSD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"getFloorPriceInUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_couponId","type":"uint256"}],"name":"getFrontendCouponData","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"getFrontendLiquidationData","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"getFrontendMarketData","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"bool","name":"_referred","type":"bool"}],"name":"getMarketBorrowFee","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"getMarketOraclePrices","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"contract ControllerI","name":"_controller","type":"address"}],"name":"getMaxBorrowableAmountInUSD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"contract ControllerI","name":"_controller","type":"address"}],"name":"getMaxBorrowableAmountInUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"getUnderlyingPriceInUSD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"address","name":"_user","type":"address"}],"name":"getUserCouponIndices","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"address","name":"_user","type":"address"}],"name":"getUserCoupons","outputs":[{"components":[{"internalType":"uint32","name":"id","type":"uint32"},{"internalType":"uint8","name":"active","type":"uint8"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"collateralId","type":"uint256"},{"internalType":"uint256","name":"borrowAmount","type":"uint256"},{"internalType":"uint256","name":"debtShares","type":"uint256"}],"internalType":"struct HTokenInternalI.Coupon[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"},{"internalType":"address","name":"_hTokenAddress","type":"address"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

60806040523480156200001157600080fd5b506200001d3362000023565b62000073565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6149e980620000836000396000f3fe608060405234801561001057600080fd5b50600436106101a35760003560e01c80637d174813116100ee578063a256c16f11610097578063d8265a3f11610071578063d8265a3f1461038a578063f2dcb49a1461039d578063f2fde38b146103b0578063fe4341f9146103c357600080fd5b8063a256c16f14610344578063a747a3ea14610357578063ce72a1141461037757600080fd5b80637e8c78bc116100c85780637e8c78bc1461030d5780638da5cb5b14610320578063918f86741461033b57600080fd5b80637d174813146102b25780637d2ac1d9146102c55780637d6e3a78146102ed57600080fd5b80635e6a6db51161015057806373fde90b1161012a57806373fde90b1461024e578063742978da146102615780637861426d1461028457600080fd5b80635e6a6db514610231578063607b463a14610214578063715018a61461024457600080fd5b8063428a69b611610181578063428a69b61461020157806349c766941461021457806354fd4d501461022757600080fd5b80630f195509146101a8578063183aaa63146101ce5780632412f605146101e1575b600080fd5b6101bb6101b6366004613d60565b6103d6565b6040519081526020015b60405180910390f35b6101bb6101dc366004613d99565b6104cf565b6101f46101ef366004613d60565b610503565b6040516101c59190613e37565b6101f461020f366004613e58565b610783565b6101bb610222366004613d99565b610ac7565b6101bb620f424081565b6101f461023f366004613e86565b610b2b565b61024c610c3c565b005b6101bb61025c366004613d99565b610c50565b61027461026f366004613d99565b610df8565b6040516101c59493929190613ebb565b610297610292366004613ee0565b610fbb565b604080519384526020840192909252908201526060016101c5565b6101bb6102c0366004613d99565b611229565b6102d86102d3366004613d99565b6112b8565b604080519283526020830191909152016101c5565b6103006102fb366004613d60565b6115db565b6040516101c59190613f0c565b6101bb61031b366004613e58565b611841565b6000546040516001600160a01b0390911681526020016101c5565b6101bb61271081565b610297610352366004613d99565b6119b9565b61036a610365366004613f50565b611cb9565b6040516101c59190613fa5565b6101bb610385366004613d60565b612814565b6101bb610398366004613d60565b6128e1565b6102976103ab366004613d99565b612a0b565b61024c6103be366004613d99565b612bd8565b6101bb6103d1366004613d99565b612c56565b6000670de0b6b3a7640000836001600160a01b031663182df0f56040518163ffffffff1660e01b8152600401602060405180830381865afa15801561041f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104439190613fd8565b604051627eeac760e11b81526001600160a01b0385811660048301526000602483015286169062fdd58e90604401602060405180830381865afa15801561048e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104b29190613fd8565b6104bc9190614007565b6104c69190614026565b90505b92915050565b6000806104db83612c90565b9050670de0b6b3a76400006104f261271083614007565b6104fc9190614026565b9392505050565b604051633d0b0ac160e21b81526001600160a01b03828116600483015260609160009185169063f42c2b0490602401602060405180830381865afa15801561054f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105739190613fd8565b67ffffffffffffffff81111561058b5761058b614048565b6040519080825280602002602001820160405280156105c457816020015b6105b1613d03565b8152602001906001900390816105a95790505b5090506000846001600160a01b031663eb08ab286040518163ffffffff1660e01b8152600401602060405180830381865afa158015610607573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061062b9190613fd8565b90506000805b82811015610778576040516333483f8f60e01b8152600481018290526000906001600160a01b038916906333483f8f906024016040805180830381865afa158015610680573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106a4919061405e565b905080602001516106b55750610770565b8051604051630fdccbb160e11b81526000916001600160a01b038b1691631fb99762916106e89160040190815260200190565b60c060405180830381865afa158015610705573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072991906140ca565b9050876001600160a01b031681604001516001600160a01b03160361076d578086858060010196508151811061076157610761614166565b60200260200101819052505b50505b600101610631565b509195945050505050565b6060806000846001600160a01b031663eb08ab286040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107ea9190613fd8565b90506000805b82811015610913576040516333483f8f60e01b8152600481018290526000906001600160a01b038916906333483f8f906024016040805180830381865afa15801561083f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610863919061405e565b8051604051634f38d23560e01b815260048101919091529091506000906001600160a01b038a1690634f38d2359060240160c060405180830381865afa1580156108b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108d591906140ca565b9050816020015180156108fd57508780156108f4575060008160800151115b806108fd575087155b15610909578360010193505b50506001016107f0565b508067ffffffffffffffff81111561092d5761092d614048565b60405190808252806020026020018201604052801561096657816020015b610953613d03565b81526020019060019003908161094b5790505b5092506000805b83811015610abb576040516333483f8f60e01b8152600481018290526000906001600160a01b038a16906333483f8f906024016040805180830381865afa1580156109bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109e0919061405e565b8051604051634f38d23560e01b815260048101919091529091506000906001600160a01b038b1690634f38d2359060240160c060405180830381865afa158015610a2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a5291906140ca565b905081602001518015610a7a5750888015610a71575060008160800151115b80610a7a575088155b15610ab15780878581518110610a9257610a92614166565b6020026020010181905250848480600101955003610ab1575050610abb565b505060010161096d565b50929695505050505050565b6000816001600160a01b031663dd5a612c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b07573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104c99190613fd8565b606082820367ffffffffffffffff811115610b4857610b48614048565b604051908082528060200260200182016040528015610b8157816020015b610b6e613d03565b815260200190600190039081610b665790505b509050825b828111610c3457604051630fdccbb160e11b8152600481018290526000906001600160a01b03871690631fb997629060240160c060405180830381865afa158015610bd5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bf991906140ca565b9050806020015160ff16600203610c2b57808386840381518110610c1f57610c1f614166565b60200260200101819052505b50600101610b86565b509392505050565b610c44612f67565b610c4e6000612fc1565b565b6000816001600160a01b0316639a85c3eb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c90573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cb49190613fd8565b826001600160a01b031663ef3f6df16040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d169190613fd8565b836001600160a01b0316638f840ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d54573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d789190613fd8565b846001600160a01b031663dd5a612c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610db6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dda9190613fd8565b610de4919061417c565b610dee919061417c565b6104c9919061417c565b600080600060606000856001600160a01b03166347bd37186040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e639190613fd8565b90506000866001600160a01b0316638f840ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ea5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ec99190613fd8565b90506000876001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f0b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f2f9190614193565b6040516370a0823160e01b81526001600160a01b038a8116600483015291909116906370a0823190602401602060405180830381865afa158015610f77573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f9b9190613fd8565b90506000610faa896000610783565b939992985090965091945092505050565b600080600080856001600160a01b031663a39fac126040518163ffffffff1660e01b815260040161010060405180830381865afa158015611000573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061102491906141b0565b50506040516333483f8f60e01b8152600481018c90529396506000955050506001600160a01b038a1692506333483f8f9160240190506040805180830381865afa158015611076573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109a919061405e565b8051604051630fdccbb160e11b815260048101919091529091506000906001600160a01b03891690631fb997629060240160c060405180830381865afa1580156110e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110c91906140ca565b60408181015184519151637e361b1160e01b81526001600160a01b038c811660048301529182166024820152604481019290925260006064830181905260848301819052929350851690637e361b119060a401606060405180830381865afa15801561117c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a09190614260565b60405163048ddec360e21b8152600481018c90529093506001600160a01b038c1692506312377b0c9150602401602060405180830381865afa1580156111ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061120e9190613fd8565b816112188b612c56565b965096509650505050509250925092565b6000816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611269573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061128d919061428e565b61129890600a61438d565b6127106112a48461301e565b6112ae9190614007565b6104c99190614026565b6000806000836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061131f919061428e565b90506000846001600160a01b031663a39fac126040518163ffffffff1660e01b815260040161010060405180830381865afa158015611362573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061138691906141b0565b505060405163eb37d34960e01b81526001600160a01b038c8116600483015294975060009650938716945063eb37d3499360240192506113c4915050565b602060405180830381865afa1580156113e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114059190614193565b90506000816001600160a01b0316637996eef0886001600160a01b031663b2016bd46040518163ffffffff1660e01b8152600401602060405180830381865afa158015611456573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061147a9190614193565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260ff871660248201526044016040805180830381865afa1580156114c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ea91906143b3565b50905060006114f88861301e565b60405163870d365d60e01b815260ff871660048201529091506000906001600160a01b0385169063870d365d90602401602060405180830381865afa158015611545573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115699190613fd8565b905061157686600a61438d565b8261271061158d846001600160801b038816614007565b6115979190614007565b6115a19190614026565b6115ab9190614026565b6115b687600a61438d565b6115c261271085614007565b6115cc9190614026565b97509750505050505050915091565b604051633d0b0ac160e21b81526001600160a01b03828116600483015260609160009185169063f42c2b0490602401602060405180830381865afa158015611627573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061164b9190613fd8565b67ffffffffffffffff81111561166357611663614048565b60405190808252806020026020018201604052801561168c578160200160208202803683370190505b5090506000846001600160a01b031663eb08ab286040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116f39190613fd8565b90506000805b82811015610778576040516333483f8f60e01b8152600481018290526000906001600160a01b038916906333483f8f906024016040805180830381865afa158015611748573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061176c919061405e565b9050806020015161177d5750611839565b8051604051630fdccbb160e11b81526000916001600160a01b038b1691631fb99762916117b09160040190815260200190565b60c060405180830381865afa1580156117cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117f191906140ca565b9050876001600160a01b031681604001516001600160a01b031603611836578286858060010196508151811061182957611829614166565b6020026020010181815250505b50505b6001016116f9565b600080836001600160a01b031663a39fac126040518163ffffffff1660e01b815260040161010060405180830381865afa158015611883573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118a791906141b0565b509396508895506119459450505050505760405163edf04a7d60e01b81526001600160a01b0385811660048301526060602483015260006064830181905260806044840152608483015282169063edf04a7d9060a4016040805180830381865afa158015611919573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061193d91906143e6565b5091506119b2565b604051632129563760e21b81526001600160a01b0385811660048301528216906384a558dc90602401602060405180830381865afa15801561198b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119af9190613fd8565b91505b5092915050565b600080600080846001600160a01b031663a39fac126040518163ffffffff1660e01b815260040161010060405180830381865afa1580156119fe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a2291906141b0565b5093965060009550611a3b94508a9350612c5692505050565b60405163a30c302d60e01b81526001600160a01b03888116600483015291925060009184169063a30c302d90602401606060405180830381865afa158015611a87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611aab919061440b565b509150506000876001600160a01b031663eb08ab286040518163ffffffff1660e01b8152600401602060405180830381865afa158015611aef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b139190613fd8565b90506000805b82811015611c39576040516333483f8f60e01b8152600481018290526000906001600160a01b038c16906333483f8f906024016040805180830381865afa158015611b68573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b8c919061405e565b8051604051634f38d23560e01b815260048101919091529091506000906001600160a01b038d1690634f38d2359060240160c060405180830381865afa158015611bda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bfe91906140ca565b905081602001518015611c15575060008160800151115b15611c2657611c2384614442565b93505b505080611c3290614442565b9050611b19565b5082896001600160a01b03166347bd37186040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c79573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c9d9190613fd8565b611ca78684614007565b97509750975050505050509193909250565b6040805180820190915260008152606060208201819052908290611cdc81613248565b90508415612311576040516333483f8f60e01b8152600481018690526000906001600160a01b038416906333483f8f906024016040805180830381865afa158015611d2b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d4f919061405e565b90508060200151611d7357604051635863f78960e01b815260040160405180910390fd5b8051604051630fdccbb160e11b81526000916001600160a01b03861691631fb9976291611da69160040190815260200190565b60c060405180830381865afa158015611dc3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611de791906140ca565b9050611e3a604051806040016040528060048152602001636e616d6560e01b815250611e128961326b565b604051602001611e22919061445b565b60408051601f198184030181529190528591906132fe565b9250611ed96040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250856001600160a01b03166395d89b416040518163ffffffff1660e01b8152600401600060405180830381865afa158015611ea1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611ec99190810190614490565b604051602001611e229190614532565b9250611f416040518060400160405280600c81526020016b195e1d195c9b985b17dd5c9b60a21b8152506040518060400160405280601581526020017468747470733a2f2f686f6e65792e66696e616e636560581b815250856132fe9092919063ffffffff16565b9250611fa260405180604001604052806005815260200164696d61676560d81b8152506040518060400160405280601581526020017468747470733a2f2f686f6e65792e66696e616e636560581b815250856132fe9092919063ffffffff16565b9250611fd96040518060400160405280600a8152602001696174747269627574657360b01b815250846133a490919063ffffffff16565b9250611fe483613248565b92506120426040518060400160405280600a81526020016974726169745f7479706560b01b8152506040518060400160405280600d81526020016c1093d49493d5d7d05353d55395609a1b815250856132fe9092919063ffffffff16565b925061207a6040518060400160405280600581526020016476616c756560d81b815250612072836080015161326b565b8591906132fe565b9250612085836133c8565b925061209083613248565b92506120ec6040518060400160405280600a81526020016974726169745f7479706560b01b8152506040518060400160405280600b81526020016a444542545f53484152455360a81b815250856132fe9092919063ffffffff16565b925061211c6040518060400160405280600581526020016476616c756560d81b8152506120728360a0015161326b565b9250612127836133c8565b925061213283613248565b92506121906040518060400160405280600a81526020016974726169745f7479706560b01b8152506040518060400160405280600d81526020016c10d3d31310551154905317d251609a1b815250856132fe9092919063ffffffff16565b92506121c06040518060400160405280600581526020016476616c756560d81b815250612072836060015161326b565b92506121cb836133c8565b92506121d683613248565b92506122396040518060400160405280600a81526020016974726169745f7479706560b01b81525060405180604001604052806012815260200171434f4c4c41544552414c5f4144445245535360701b815250856132fe9092919063ffffffff16565b92506122fd6040518060400160405280600581526020016476616c756560d81b815250612072866001600160a01b031663b2016bd46040518163ffffffff1660e01b8152600401602060405180830381865afa15801561229d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122c19190614193565b6040516020016122e9919060609190911b6bffffffffffffffffffffffff1916815260140190565b6040516020818303038152906040526133eb565b9250612308836133c8565b925050506127f3565b612426604051806040016040528060048152602001636e616d6560e01b815250836001600160a01b03166306fdde036040518163ffffffff1660e01b8152600401600060405180830381865afa15801561236f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526123979190810190614490565b846001600160a01b03166395d89b416040518163ffffffff1660e01b8152600401600060405180830381865afa1580156123d5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526123fd9190810190614490565b60405160200161240e929190614577565b60408051601f198184030181529190528391906132fe565b90506125ee6040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250836001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa15801561248d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124b19190614193565b6001600160a01b03166306fdde036040518163ffffffff1660e01b8152600401600060405180830381865afa1580156124ee573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526125169190810190614490565b846001600160a01b031663b2016bd46040518163ffffffff1660e01b8152600401602060405180830381865afa158015612554573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125789190614193565b6001600160a01b03166306fdde036040518163ffffffff1660e01b8152600401600060405180830381865afa1580156125b5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526125dd9190810190614490565b60405160200161240e9291906145b3565b90506126566040518060400160405280600c81526020016b195e1d195c9b985b17dd5c9b60a21b8152506040518060400160405280601581526020017468747470733a2f2f686f6e65792e66696e616e636560581b815250836132fe9092919063ffffffff16565b90506126b760405180604001604052806005815260200164696d61676560d81b8152506040518060400160405280601581526020017468747470733a2f2f686f6e65792e66696e616e636560581b815250836132fe9092919063ffffffff16565b90506126ee6040518060400160405280600a8152602001696174747269627574657360b01b815250826133a490919063ffffffff16565b90506126f981613248565b90506127506040518060400160405280600a81526020016974726169745f7479706560b01b81525060405180604001604052806006815260200165535550504c5960d01b815250836132fe9092919063ffffffff16565b90506127e56040518060400160405280600581526020016476616c756560d81b8152506127dd846001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156127b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127d89190613fd8565b61326b565b8391906132fe565b90506127f0816133c8565b90505b6127fc816135f9565b9050612807816133c8565b6020015195945050505050565b60008061282084612c90565b9050600061282d8561301e565b60405163a30c302d60e01b81526001600160a01b03878116600483015291925060009186169063a30c302d90602401606060405180830381865afa158015612879573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061289d919061440b565b509150670de0b6b3a76400009050826127106128b98685614007565b6128c39190614007565b6128cd9190614026565b6128d79190614026565b9695505050505050565b6000806128ed84612c90565b60405163a30c302d60e01b81526001600160a01b03868116600483015291925060009185169063a30c302d90602401606060405180830381865afa158015612939573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061295d919061440b565b92505050846001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561299f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129c3919061428e565b6129ce90600a61438d565b670de0b6b3a76400006127106129e48585614007565b6129ee9190614007565b6129f89190614026565b612a029190614026565b95945050505050565b600080600080846001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a4f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a739190613fd8565b90506000856001600160a01b031663182df0f56040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ab5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ad99190613fd8565b9050611388670de0b6b3a7640000612af18385614007565b612afb9190614026565b876001600160a01b0316638f840ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b39573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b5d9190613fd8565b886001600160a01b031663dd5a612c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bbf9190613fd8565b612bc9919061417c565b94509450945050509193909250565b612be0612f67565b6001600160a01b038116612c4a5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084015b60405180910390fd5b612c5381612fc1565b50565b600080612c6283612c90565b90506000612c6f8461301e565b905080612c7e61271084614007565b612c889190614026565b949350505050565b600080826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612cd1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cf5919061428e565b90506000836001600160a01b031663a39fac126040518163ffffffff1660e01b815260040161010060405180830381865afa158015612d38573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d5c91906141b0565b505060405163eb37d34960e01b81526001600160a01b038b8116600483015294975060009650938716945063eb37d349936024019250612d9a915050565b602060405180830381865afa158015612db7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ddb9190614193565b90506000816001600160a01b0316637996eef0876001600160a01b031663b2016bd46040518163ffffffff1660e01b8152600401602060405180830381865afa158015612e2c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e509190614193565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260ff871660248201526044016040805180830381865afa158015612e9c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ec091906143b3565b5060405163870d365d60e01b815260ff861660048201529091506000906001600160a01b0384169063870d365d90602401602060405180830381865afa158015612f0e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f329190613fd8565b9050612f3f85600a61438d565b612f52826001600160801b038516614007565b612f5c9190614026565b979650505050505050565b6000546001600160a01b03163314610c4e5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401612c41565b600080546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080826001600160a01b031663a39fac126040518163ffffffff1660e01b815260040161010060405180830381865afa158015613060573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061308491906141b0565b505060405163eb37d34960e01b81526001600160a01b038a8116600483015294975060009650938716945063eb37d3499360240192506130c2915050565b602060405180830381865afa1580156130df573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131039190614193565b9050806001600160a01b031663297b5180856001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015613152573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131769190614193565b866001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156131b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131d8919061428e565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260ff166024820152604401602060405180830381865afa158015613224573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c889190613fd8565b6040805180820190915260008152606060208201526104c982607b60f81b61361c565b60606000613278836136bd565b600101905060008167ffffffffffffffff81111561329857613298614048565b6040519080825280601f01601f1916602001820160405280156132c2576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846132cc57509392505050565b604080518082019091526000815260606020820152600061331e83613795565b90506000856000015112156133645760208086015160405161334a92600b60fa1b918891869101614627565b60408051601f198184030181529190526020860152613391565b60208086015160405161337b9287918591016146a3565b60408051601f1981840301815291905260208601525b8451600160ff1b17855250929392505050565b6040805180820190915260008152606060208201526104c68383605b60f81b613bf2565b6040805180820190915260008152606060208201526104c982607d60f81b613c98565b60408051808201909152601081526f181899199a1a9b1b9c1cb0b131b232b360811b60208201528151606091906000613425826002614007565b61343090600261470f565b67ffffffffffffffff81111561344857613448614048565b6040519080825280601f01601f191660200182016040528015613472576020820181803683370190505b509050600360fc1b8160008151811061348d5761348d614166565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106134bc576134bc614166565b60200101906001600160f81b031916908160001a90535060005b828110156135f0578360048783815181106134f3576134f3614166565b016020015182516001600160f81b031990911690911c60f81c90811061351b5761351b614166565b01602001516001600160f81b03191682613536836002614007565b61354190600261470f565b8151811061355157613551614166565b60200101906001600160f81b031916908160001a9053508386828151811061357b5761357b614166565b602091010151815160f89190911c600f1690811061359b5761359b614166565b01602001516001600160f81b031916826135b6836002614007565b6135c190600361470f565b815181106135d1576135d1614166565b60200101906001600160f81b031916908160001a9053506001016134d6565b50949350505050565b6040805180820190915260008152606060208201526104c982605d60f81b613c98565b6040805180820190915260008152606060208201528251600013156136705760208084015160405161365692600b60fa1b91869101614727565b60408051601f19818403018152919052602084015261369b565b6020808401516040516136859285910161475a565b60408051601f1981840301815291905260208401525b82516001600160ff1b0316808452836136b382614789565b9052509192915050565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106136fc5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310613728576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061374657662386f26fc10000830492506010015b6305f5e100831061375e576305f5e100830492506008015b612710831061377257612710830492506004015b60648310613784576064830492506002015b600a83106104c95760010192915050565b6060816000805b825181101561396f578251601760fa1b908490839081106137bf576137bf614166565b01602001516001600160f81b031916036137dc576001915061396f565b8251601160f91b908490839081106137f6576137f6614166565b01602001516001600160f81b03191603613813576001915061396f565b8251602f60f81b9084908390811061382d5761382d614166565b01602001516001600160f81b0319160361384a576001915061396f565b8251600960f81b9084908390811061386457613864614166565b01602001516001600160f81b03191603613881576001915061396f565b8251600360fa1b9084908390811061389b5761389b614166565b01602001516001600160f81b031916036138b8576001915061396f565b8251600560f91b908490839081106138d2576138d2614166565b01602001516001600160f81b031916036138ef576001915061396f565b8251600d60f81b9084908390811061390957613909614166565b01602001516001600160f81b03191603613926576001915061396f565b8251600160fb1b9084908390811061394057613940614166565b01602001516001600160f81b0319160361395d576001915061396f565b8061396781614442565b91505061379c565b508061397d57509192915050565b60005b8251811015613bea578251601760fa1b908490839081106139a3576139a3614166565b01602001516001600160f81b031916036139de57836040516020016139c891906147a1565b6040516020818303038152906040529350613bd8565b8251601160f91b908490839081106139f8576139f8614166565b01602001516001600160f81b03191603613a1d57836040516020016139c891906147c7565b8251602f60f81b90849083908110613a3757613a37614166565b01602001516001600160f81b03191603613a5c57836040516020016139c891906147ed565b8251600960f81b90849083908110613a7657613a76614166565b01602001516001600160f81b03191603613a9b57836040516020016139c89190614813565b8251600360fa1b90849083908110613ab557613ab5614166565b01602001516001600160f81b03191603613ada57836040516020016139c89190614839565b8251600560f91b90849083908110613af457613af4614166565b01602001516001600160f81b03191603613b1957836040516020016139c8919061485f565b8251600d60f81b90849083908110613b3357613b33614166565b01602001516001600160f81b03191603613b5857836040516020016139c89190614885565b8251600160fb1b90849083908110613b7257613b72614166565b01602001516001600160f81b03191603613b9757836040516020016139c891906148ab565b83838281518110613baa57613baa614166565b602001015160f81c60f81b604051602001613bc692919061475a565b60405160208183030381529060405293505b80613be281614442565b915050613980565b505050919050565b604080518082019091526000815260606020820152835160001315613c4857602080850151604051613c2e92600b60fa1b9187918791016148d1565b60408051601f198184030181529190526020850152613c75565b602080850151604051613c5f928691869101614938565b60408051601f1981840301815291905260208501525b83516001600160ff1b031680855284613c8d82614789565b905250929392505050565b604080518082019091526000815260606020820152602080840151604051613cc29285910161475a565b60408051808303601f1901815291905260208401528251600160ff1b178084526001600160ff1b031615613cfc578251836136b382614996565b5090919050565b6040518060c00160405280600063ffffffff168152602001600060ff16815260200160006001600160a01b031681526020016000815260200160008152602001600081525090565b6001600160a01b0381168114612c5357600080fd5b60008060408385031215613d7357600080fd5b8235613d7e81613d4b565b91506020830135613d8e81613d4b565b809150509250929050565b600060208284031215613dab57600080fd5b81356104fc81613d4b565b600081518084526020808501945080840160005b83811015613e2c578151805163ffffffff1688528381015160ff16848901526040808201516001600160a01b031690890152606080820151908901526080808201519089015260a0908101519088015260c09096019590820190600101613dca565b509495945050505050565b6020815260006104c66020830184613db6565b8015158114612c5357600080fd5b60008060408385031215613e6b57600080fd5b8235613e7681613d4b565b91506020830135613d8e81613e4a565b600080600060608486031215613e9b57600080fd5b8335613ea681613d4b565b95602085013595506040909401359392505050565b8481528360208201528260408201526080606082015260006128d76080830184613db6565b60008060408385031215613ef357600080fd5b8235613efe81613d4b565b946020939093013593505050565b6020808252825182820181905260009190848201906040850190845b81811015613f4457835183529284019291840191600101613f28565b50909695505050505050565b60008060408385031215613f6357600080fd5b823591506020830135613d8e81613d4b565b60005b83811015613f90578181015183820152602001613f78565b83811115613f9f576000848401525b50505050565b6020815260008251806020840152613fc4816040850160208701613f75565b601f01601f19169190910160400192915050565b600060208284031215613fea57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b600081600019048311821515161561402157614021613ff1565b500290565b60008261404357634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052604160045260246000fd5b60006040828403121561407057600080fd5b6040516040810181811067ffffffffffffffff8211171561409357614093614048565b6040528251815260208301516140a881613e4a565b60208201529392505050565b805160ff811681146140c557600080fd5b919050565b600060c082840312156140dc57600080fd5b60405160c0810181811067ffffffffffffffff821117156140ff576140ff614048565b604052825163ffffffff8116811461411657600080fd5b8152614124602084016140b4565b6020820152604083015161413781613d4b565b80604083015250606083015160608201526080830151608082015260a083015160a08201528091505092915050565b634e487b7160e01b600052603260045260246000fd5b60008282101561418e5761418e613ff1565b500390565b6000602082840312156141a557600080fd5b81516104fc81613d4b565b600080600080600080600080610100898b0312156141cd57600080fd5b88516141d881613d4b565b60208a01519098506141e981613d4b565b60408a01519097506141fa81613d4b565b60608a015190965061420b81613d4b565b60808a015190955061421c81613d4b565b60a08a015190945061422d81613d4b565b60c08a015190935061423e81613d4b565b60e08a015190925061424f81613d4b565b809150509295985092959890939650565b60008060006060848603121561427557600080fd5b8351925060208401519150604084015190509250925092565b6000602082840312156142a057600080fd5b6104c6826140b4565b600181815b808511156142e45781600019048211156142ca576142ca613ff1565b808516156142d757918102915b93841c93908002906142ae565b509250929050565b6000826142fb575060016104c9565b81614308575060006104c9565b816001811461431e576002811461432857614344565b60019150506104c9565b60ff84111561433957614339613ff1565b50506001821b6104c9565b5060208310610133831016604e8410600b8410161715614367575081810a6104c9565b61437183836142a9565b806000190482111561438557614385613ff1565b029392505050565b60006104c660ff8416836142ec565b80516001600160801b03811681146140c557600080fd5b600080604083850312156143c657600080fd5b6143cf8361439c565b91506143dd6020840161439c565b90509250929050565b600080604083850312156143f957600080fd5b825191506020830151613d8e81613e4a565b60008060006060848603121561442057600080fd5b835161442b81613e4a565b602085015160409095015190969495509392505050565b60006001820161445457614454613ff1565b5060010190565b6c02437b732bc9021b7bab837b71609d1b81526000825161448381600d850160208701613f75565b91909101600d0192915050565b6000602082840312156144a257600080fd5b815167ffffffffffffffff808211156144ba57600080fd5b818401915084601f8301126144ce57600080fd5b8151818111156144e0576144e0614048565b604051601f8201601f19908116603f0116810190838211818310171561450857614508614048565b8160405282815287602084870101111561452157600080fd5b612f5c836020830160208801613f75565b7f486f6e657920436f75706f6e20666f72204d61726b657420000000000000000081526000825161456a816018850160208701613f75565b9190910160180192915050565b60008351614589818460208801613f75565b600160fd1b90830190815283516145a7816001840160208801613f75565b01600101949350505050565b7f486f6e6579204d61726b6574207769746820756e6465726c79696e67200000008152600083516145eb81601d850160208801613f75565b6f01030b7321031b7b63630ba32b930b6160851b601d91840191820152835161461b81602d840160208801613f75565b01602d01949350505050565b60008551614639818460208a01613f75565b6001600160f81b03198616908301908152601160f91b600182018190528551614669816002850160208a01613f75565b63111d101160e11b60029390910192830152845161468e816006850160208901613f75565b60069201918201526007019695505050505050565b600084516146b5818460208901613f75565b601160f91b90830181815285519091906146d6816001850160208a01613f75565b63111d101160e11b6001939091019283015284516146fb816005850160208901613f75565b600592019182015260060195945050505050565b6000821982111561472257614722613ff1565b500190565b60008451614739818460208901613f75565b6001600160f81b031994851692019182525091166001820152600201919050565b6000835161476c818460208801613f75565b6001600160f81b0319939093169190920190815260010192915050565b60006001600160ff1b01820161445457614454613ff1565b600082516147b3818460208701613f75565b61171760f21b920191825250600201919050565b600082516147d9818460208701613f75565b612e1160f11b920191825250600201919050565b600082516147ff818460208701613f75565b615c2f60f01b920191825250600201919050565b60008251614825818460208701613f75565b61171d60f21b920191825250600201919050565b6000825161484b818460208701613f75565b612e3360f11b920191825250600201919050565b60008251614871818460208701613f75565b612e3760f11b920191825250600201919050565b60008251614897818460208701613f75565b612e3960f11b920191825250600201919050565b600082516148bd818460208701613f75565b612e3160f11b920191825250600201919050565b600085516148e3818460208a01613f75565b6001600160f81b0319868116918401918252601160f91b60018301528551614912816002850160208a01613f75565b620111d160ed1b6002939091019283015293909316600584015250506006019392505050565b6000845161494a818460208901613f75565b601160f91b9083019081528451614968816001840160208901613f75565b620111d160ed1b600192909101918201526001600160f81b0319939093166004840152505060050192915050565b6000600160ff1b82016149ab576149ab613ff1565b50600019019056fea2646970667358221220437c7986075df3e0d6849ffcf85728a9f837df85d79bd3f46281c30dbf94fb3464736f6c634300080f0033

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.