Contract Overview
My Name Tag:
Not Available, login to update
[ Download CSV Export ]
Contract Name:
Marketplace
Compiler Version
v0.8.15+commit.e14f2714
Optimization Enabled:
Yes with 300 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// 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 ); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(account), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } }
// 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; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
// 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; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// 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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// 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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// 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; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// 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); }
// 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); } } }
// 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); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
pragma solidity >=0.6.2; interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); }
pragma solidity >=0.6.2; import './IUniswapV2Router01.sol'; interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; }
//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; }
//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; }
//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; }
//SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.8.4; import "./INFTXVaultFactory.sol"; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } interface INFTXEligibility { // Read functions. function name() external pure returns (string memory); function finalized() external view returns (bool); function targetAsset() external pure returns (address); function checkAllEligible(uint256[] calldata tokenIds) external view returns (bool); function checkEligible(uint256[] calldata tokenIds) external view returns (bool[] memory); function checkAllIneligible(uint256[] calldata tokenIds) external view returns (bool); function checkIsEligible(uint256 tokenId) external view returns (bool); // Write functions. function __NFTXEligibility_init_bytes(bytes calldata configData) external; function beforeMintHook(uint256[] calldata tokenIds) external; function afterMintHook(uint256[] calldata tokenIds) external; function beforeRedeemHook(uint256[] calldata tokenIds) external; function afterRedeemHook(uint256[] calldata tokenIds) external; } interface INFTXVault is IERC20Upgradeable { function manager() external view returns (address); function assetAddress() external view returns (address); function vaultFactory() external view returns (INFTXVaultFactory); function eligibilityStorage() external view returns (INFTXEligibility); function is1155() external view returns (bool); function allowAllItems() external view returns (bool); function enableMint() external view returns (bool); function enableRandomRedeem() external view returns (bool); function enableTargetRedeem() external view returns (bool); function enableRandomSwap() external view returns (bool); function enableTargetSwap() external view returns (bool); function vaultId() external view returns (uint256); function nftIdAt(uint256 holdingsIndex) external view returns (uint256); function allHoldings() external view returns (uint256[] memory); function totalHoldings() external view returns (uint256); function mintFee() external view returns (uint256); function randomRedeemFee() external view returns (uint256); function targetRedeemFee() external view returns (uint256); function randomSwapFee() external view returns (uint256); function targetSwapFee() external view returns (uint256); function vaultFees() external view returns (uint256, uint256, uint256, uint256, uint256); event VaultInit(uint256 indexed vaultId, address assetAddress, bool is1155, bool allowAllItems); event ManagerSet(address manager); event EligibilityDeployed(uint256 moduleIndex, address eligibilityAddr); // event CustomEligibilityDeployed(address eligibilityAddr); event EnableMintUpdated(bool enabled); event EnableRandomRedeemUpdated(bool enabled); event EnableTargetRedeemUpdated(bool enabled); event EnableRandomSwapUpdated(bool enabled); event EnableTargetSwapUpdated(bool enabled); event Minted(uint256[] nftIds, uint256[] amounts, address to); event Redeemed(uint256[] nftIds, uint256[] specificIds, address to); event Swapped(uint256[] nftIds, uint256[] amounts, uint256[] specificIds, uint256[] redeemedIds, address to); function __NFTXVault_init( string calldata _name, string calldata _symbol, address _assetAddress, bool _is1155, bool _allowAllItems ) external; function finalizeVault() external; function setVaultMetadata(string memory name_, string memory symbol_) external; function setVaultFeatures( bool _enableMint, bool _enableRandomRedeem, bool _enableTargetRedeem, bool _enableRandomSwap, bool _enableTargetSwap ) external; function setFees( uint256 _mintFee, uint256 _randomRedeemFee, uint256 _targetRedeemFee, uint256 _randomSwapFee, uint256 _targetSwapFee ) external; function disableVaultFees() external; // This function allows for an easy setup of any eligibility module contract from the EligibilityManager. // It takes in ABI encoded parameters for the desired module. This is to make sure they can all follow // a similar interface. function deployEligibilityStorage(uint256 moduleIndex, bytes calldata initData) external returns (address); // The manager has control over options like fees and features function setManager(address _manager) external; function mint( uint256[] calldata tokenIds, uint256[] calldata amounts /* ignored for ERC721 vaults */ ) external returns (uint256); function mintTo( uint256[] calldata tokenIds, uint256[] calldata amounts /* ignored for ERC721 vaults */, address to ) external returns (uint256); function redeem(uint256 amount, uint256[] calldata specificIds) external returns (uint256[] calldata); function redeemTo(uint256 amount, uint256[] calldata specificIds, address to) external returns (uint256[] calldata); function swap( uint256[] calldata tokenIds, uint256[] calldata amounts /* ignored for ERC721 vaults */, uint256[] calldata specificIds ) external returns (uint256[] calldata); function swapTo( uint256[] calldata tokenIds, uint256[] calldata amounts /* ignored for ERC721 vaults */, uint256[] calldata specificIds, address to ) external returns (uint256[] calldata); function allValidNFTs(uint256[] calldata tokenIds) external view returns (bool); }
//SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.8.4; interface IBeacon { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function childImplementation() external view returns (address); function upgradeChildTo(address newImplementation) external; } interface INFTXVaultFactory is IBeacon { // Read functions. function numVaults() external view returns (uint256); function zapContract() external view returns (address); function feeDistributor() external view returns (address); function eligibilityManager() external view returns (address); function vault(uint256 vaultId) external view returns (address); function allVaults() external view returns (address[] memory); function vaultsForAsset(address asset) external view returns (address[] memory); function isLocked(uint256 id) external view returns (bool); function excludedFromFees(address addr) external view returns (bool); function factoryMintFee() external view returns (uint64); function factoryRandomRedeemFee() external view returns (uint64); function factoryTargetRedeemFee() external view returns (uint64); function factoryRandomSwapFee() external view returns (uint64); function factoryTargetSwapFee() external view returns (uint64); function vaultFees(uint256 vaultId) external view returns (uint256, uint256, uint256, uint256, uint256); event NewFeeDistributor(address oldDistributor, address newDistributor); event NewZapContract(address oldZap, address newZap); event FeeExclusion(address feeExcluded, bool excluded); event NewEligibilityManager(address oldEligManager, address newEligManager); event NewVault(uint256 indexed vaultId, address vaultAddress, address assetAddress); event UpdateVaultFees( uint256 vaultId, uint256 mintFee, uint256 randomRedeemFee, uint256 targetRedeemFee, uint256 randomSwapFee, uint256 targetSwapFee ); event DisableVaultFees(uint256 vaultId); event UpdateFactoryFees( uint256 mintFee, uint256 randomRedeemFee, uint256 targetRedeemFee, uint256 randomSwapFee, uint256 targetSwapFee ); // Write functions. function __NFTXVaultFactory_init(address _vaultImpl, address _feeDistributor) external; function createVault( string calldata name, string calldata symbol, address _assetAddress, bool is1155, bool allowAllItems ) external returns (uint256); function setFeeDistributor(address _feeDistributor) external; function setEligibilityManager(address _eligibilityManager) external; function setZapContract(address _zapContract) external; function setFeeExclusion(address _excludedAddr, bool excluded) external; function setFactoryFees( uint256 mintFee, uint256 randomRedeemFee, uint256 targetRedeemFee, uint256 randomSwapFee, uint256 targetSwapFee ) external; function setVaultFees( uint256 vaultId, uint256 mintFee, uint256 randomRedeemFee, uint256 targetRedeemFee, uint256 randomSwapFee, uint256 targetSwapFee ) external; function disableVaultFees(uint256 vaultId) external; }
//SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.8.4; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "../interfaces/HTokenI.sol"; /** * @title Interface of Liquidator * @author Honey Labs Inc. * @custom:coauthor BowTiedPickle * @custom:contributor m4rio */ interface LiquidatorI is IERC721Receiver { function isRegisteredUnderlying(address _token) external view returns (bool); function isRegisteredHToken(address _hToken) external view returns (bool); function _initializeHToken(HTokenI _hToken) external; }
//SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.8.4; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import ".././interfaces/HTokenI.sol"; /** * @title Interface of Marketplace * @author Honey Labs Inc. * @custom:coauthor BowTiedPickle * @custom:coauthor m4rio */ interface MarketplaceI { struct Auction { IERC20 underlying; address highestBidder; uint256 highestBid; address[50] bidders; // Arrays are sorted ascending uint256[50] bids; uint256[50] unlockTimes; } function toggleLiquidation( HTokenI _hToken, uint256 _collateralId, bool _enabled ) external; function bidSingle( HTokenI _hToken, uint256 _collateralId, uint256 _amount ) external; function increaseBidSingle( HTokenI _hToken, uint256 _collateralId, uint256 _increaseAmount ) external; function bidCollection(HTokenI _hToken, uint256 _amount) external; function increaseBidCollection(HTokenI _hToken, uint256 _increaseAmount) external; function settleAuction( HTokenI _hToken, address _borrower, uint256 _collateralId ) external; function withdrawRefund(IERC20 _token) external returns (uint256); function cancelBidSingle(HTokenI _hToken, uint256 _collateralId) external; function cancelBidCollection(HTokenI _hToken) external; function viewMinimumNextBidSingle(HTokenI _hToken, uint256 _collateralId) external view returns (uint256); function viewMinimumNextBidCollection(HTokenI _hToken) external view returns (uint256); function viewAuctionSingle(HTokenI _hToken, uint256 _collateralId) external view returns (Auction memory); function viewAuctionCollection(HTokenI _hToken) external view returns (Auction memory); function viewAvailableRefund(IERC20 _token, address _user) external view returns (uint256); function viewUserBidSingle( address _user, HTokenI _hToken, uint256 _collateralId ) external view returns (uint256, uint256); function viewUserBidCollection(address _user, HTokenI _hToken) external view returns (uint256, uint256); function _refundAllBidsPerCollateral(HTokenI _hToken, uint256 _collateralId) external; function _refundAllBidsPerCollection(HTokenI _hToken) external; }
//SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.8.4; interface NFT20Factory { function nftToToken(address) external returns (address); } interface NFT20Pair { function nftAddress() external returns (address); }
//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); }
//SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.15; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol"; import ".././interfaces/HTokenI.sol"; import "./LiquidatorStorage.sol"; import ".././utils/ErrorReporter.sol"; import { NFT20Factory, NFT20Pair } from ".././interfaces/NFT20I.sol"; /** * @title Honey Finance Liquidator Module - NFT20 * @notice Execute liquidations via NFT20 for HToken IRM contracts * @author Honey Labs inc * @custom:coauthor BowTiedPickle * @custom:contributor m4rio */ abstract contract LiquidatorModuleNFT20 is AccessControl, ReentrancyGuard, LiquidatorStorage { using SafeERC20 for IERC20; /// @notice NFT20 pool factory NFT20Factory public niftyFactory; /// @notice HToken to NFT20 pool for that collateral mapping(HTokenI => address) public poolToNiftyPair; event NFTFactoryInitialized(address _factory); event NFT20PairInitialized(address _pair, address _hToken); event NFT20LiquidationExecuted(address indexed _pair, address indexed _hToken, uint256 _collateralId); /** * @notice Initializes the NFT20Factory that will be queried * @dev May only be called once * @param _NFT20Factory address of NFT20 factory proxy contract * @return True on success */ function initializeNFT20Factory( NFT20Factory _NFT20Factory ) external nonReentrant onlyRole(INITIALIZER_ROLE) returns (bool) { // May only initialize once if (address(niftyFactory) != address(0)) revert Unauthorized(); niftyFactory = _NFT20Factory; emit NFTFactoryInitialized(address(_NFT20Factory)); return true; } /** * @notice Setup an NFT20 pair if one exists for the collateral asset underlying the given HToken * @dev Does not create an NFT20 pool if one does not exist. * @param _hToken address of the target hToken. * @return True on success */ function initializeNFT20Pair(HTokenI _hToken) external nonReentrant onlyRole(INITIALIZER_ROLE) returns (bool) { IERC721 collateralToken = _hToken.collateralToken(); // Check for existence of NFT20 pool address pair = niftyFactory.nftToToken(address(collateralToken)); // If NFT20 pair exists, add it to mapping if (pair != address(0)) { // Sanity check if (NFT20Pair(pair).nftAddress() == address(collateralToken)) { poolToNiftyPair[_hToken] = pair; emit NFT20PairInitialized(pair, address(_hToken)); return true; } } return false; } /** * @dev Called before NFT20 liquidation. Should handle auctions, refunding, and any other logic. * @param _hToken Contract address of the hToken * @param _collateralId NFT tokenId * @return (Collateral ERC-721 address, vault address) */ function _NFT20PreLiquidationHook( HTokenI _hToken, uint256 _collateralId ) internal virtual returns (IERC721, address) {} /** * @dev Called before NFTX droplet swap. Should handle auctions, refunding, and any other logic. * @param _hToken Contract address of the hToken * @param _collateralId NFT tokenId * @return (Collateral ERC-721 address, underlying ERC-20 address) */ function _NFT20PreSwapHook(HTokenI _hToken, uint256 _collateralId) internal view virtual returns (IERC721, IERC20) {} /** * @dev Called after DEX swap to ensure we have enough to repay without dipping into protected funds * @param _hToken hToken we're repaying against * @param _underlyingToken ERC-20 token to be used for repayment * @param _collateralId NFT token ID which we are repaying against */ function postSwapHook(HTokenI _hToken, IERC20 _underlyingToken, uint256 _collateralId) internal virtual {} /** * @notice Sends a given NFT to the NFT20 platform in exchange for droplet tokens * @dev This will leave the protocol underwater in ERC20 terms unless the droplets are liquidated. * Business logic needs to understand and account for this. * @param _hToken Contract address of the hToken * @param _collateralId NFT Token ID */ function liquidateViaNFT20( HTokenI _hToken, uint256 _collateralId ) external nonReentrant onlyRole(LIQUIDATOR_ROLE) returns (bool) { // TODO add incentivisation on executing this (IERC721 collateralToken, address pair) = _NFT20PreLiquidationHook(_hToken, _collateralId); // Straight token transfer, IERC721Receiver hook in NFT20 pair will mint pair tokens. collateralToken.safeTransferFrom(address(this), pair, _collateralId); emit NFT20LiquidationExecuted(pair, address(_hToken), _collateralId); return true; } /** * @notice Swap droplets for ERC20 using Uniswap V2 pools, and use the funds to repay a borrow * @param _hToken The hToken contract address * @param _borrower The address of the current owner of the deposit coupon * @param _collateralId Token ID of the collateral token * @param _path Array of tokens to swap through, starting at droplet and ending at HToken's underlying * @param _amountIn Quantity of droplets to liquidate * @param _amountOutMinimum Minimum acceptable output quantity of output token * @return True upon success */ function swapNFT20DropletsAndRepayBorrow( HTokenI _hToken, address _borrower, uint256 _collateralId, address[] memory _path, uint256 _amountIn, uint256 _amountOutMinimum ) external nonReentrant onlyRole(SWAPPER_ROLE) returns (bool) { (, IERC20 underlying) = _NFT20PreSwapHook(_hToken, _collateralId); // Retrieve address address droplet = poolToNiftyPair[_hToken]; // Arbitrary swap path is allowed, but it must start and end in the right place if (_path[0] != droplet) revert WrongParams(); if (_path[_path.length - 1] != address(underlying)) revert WrongParams(); // Set approval address cachedSwapRouter = address(swapRouter); uint256 currentAllowance = IERC20(droplet).allowance(address(this), cachedSwapRouter); if (currentAllowance != _amountIn) { // Decrease to 0 first for tokens mitigating the race condition IERC20(droplet).safeDecreaseAllowance(cachedSwapRouter, currentAllowance); IERC20(droplet).safeIncreaseAllowance(cachedSwapRouter, _amountIn); } // Dex swap swapExactUniV2(_amountIn, _amountOutMinimum, _path); postSwapHook(_hToken, underlying, _collateralId); // Closeout and repay funds _hToken.closeoutLiquidation(_borrower, _collateralId); marketplace.toggleLiquidation(_hToken, _collateralId, false); emit DropletsSwapped(droplet, _path, _amountIn, _amountOutMinimum); emit BorrowRepaid(address(_hToken), _borrower, _collateralId); return true; } function swapExactUniV2( uint256 _amountIn, uint256 _amountOutMin, address[] memory _path ) internal virtual returns (uint256[] memory) { uint256[] memory amounts = swapRouter.swapExactTokensForTokens( _amountIn, _amountOutMin, _path, address(this), block.timestamp ); return amounts; } }
//SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.15; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol"; import ".././interfaces/HTokenI.sol"; import "./LiquidatorStorage.sol"; import ".././utils/ErrorReporter.sol"; import { INFTXVault } from ".././interfaces/INFTXVault.sol"; import { INFTXVaultFactory } from ".././interfaces/INFTXVaultFactory.sol"; /** * @title Honey Finance Liquidator Module - NFTX * @notice Execute liquidations via NFTX for HToken IRM contracts * @author Honey Labs inc * @custom:coauthor BowTiedPickle * @custom:contributor m4rio */ abstract contract LiquidatorModuleNFTX is AccessControl, ReentrancyGuard, LiquidatorStorage { using SafeERC20 for IERC20; /// @notice NFTX pool factory INFTXVaultFactory public NFTXFactory; /// @notice HToken to NFTX vaults for that collateral mapping(HTokenI => address[]) public poolToNFTXVaults; event NFTXFactoryInitialized(address _factory); event NFTXVaultsInitialized(address _pair, address _hToken); event NFTXLiquidationExecuted(address indexed _pair, address indexed _hToken, uint256 _collateralId); /** * @notice Initializes the NFTXFactory that will be queried * @dev May only be called once * @param _NFTXFactory address of NFTX factory proxy contract * @return True on success */ function initializeNFTXFactory( INFTXVaultFactory _NFTXFactory ) external nonReentrant onlyRole(INITIALIZER_ROLE) returns (bool) { // May only initialize once if (address(NFTXFactory) != address(0)) revert Unauthorized(); NFTXFactory = _NFTXFactory; emit NFTXFactoryInitialized(address(_NFTXFactory)); return true; } /** * @notice Setup NFTX vault(s) if they exists for the collateral asset underlying the given HToken * @dev Does not create an NFTX vault if one does not exist. * @param _hToken address of the target hToken. * @return True on success */ function initializeNFTXVault(HTokenI _hToken) external nonReentrant onlyRole(INITIALIZER_ROLE) returns (bool) { IERC721 collateralToken = _hToken.collateralToken(); // Check for existence of NFTX pool address[] memory vaults = NFTXFactory.vaultsForAsset(address(collateralToken)); uint256 length = vaults.length; if (length > 0) { address vault; for (uint256 i; i < length; ) { vault = vaults[i]; // Sanity check if (INFTXVault(vault).assetAddress() == address(collateralToken)) { poolToNFTXVaults[_hToken].push(vault); emit NFTXVaultsInitialized(vault, address(_hToken)); } unchecked { ++i; } } return true; } else { return false; } } /** * @dev Called before NFTX liquidation. Should handle auctions, refunding, and any other logic. * @param _hToken Contract address of the HToken * @param _collateralId NFT tokenId * @param _vaultIndex 0 if only one vault exists, otherwise index of the desired vault in the address[] mapping of poolToNFTXVaults * @return (Collateral ERC-721 address, vault address) */ function _NFTXPreLiquidationHook( HTokenI _hToken, uint256 _collateralId, uint256 _vaultIndex ) internal virtual returns (IERC721, address) {} /** * @dev Called before NFTX droplet swap. Should handle auctions, refunding, and any other logic. * @param _hToken Contract address of the HToken * @param _collateralId NFT tokenId * @return (Collateral ERC-721 address, underlying ERC-20 address) */ function _NFTXPreSwapHook(HTokenI _hToken, uint256 _collateralId) internal virtual returns (IERC721, IERC20) {} /** * @dev Called after dex swap to ensure we have enough to repay without dipping into protected funds * @param _hToken hToken we're repaying against * @param _underlyingToken ERC-20 token to be used for repayment * @param _collateralId NFT tokenId which we are repaying against */ function postSwapHook(HTokenI _hToken, IERC20 _underlyingToken, uint256 _collateralId) internal virtual {} /** * @notice Sends a given NFT to the NFTX platform in exchange for droplet tokens * @dev This will leave the protocol underwater in ERC20 terms unless the droplets are liquidated. Business logic needs to understand and account for this. * @dev May only be called after clawback window expires * @param _hToken Contract address of the HToken * @param _collateralId NFT Token Id * @param _vaultIndex Index of the NFTX vault in poolToNFTXVaults. 0 if only one NFTX vault exists for this collateral. */ function liquidateViaNFTX( HTokenI _hToken, uint256 _collateralId, uint256 _vaultIndex ) external nonReentrant onlyRole(LIQUIDATOR_ROLE) returns (bool) { (IERC721 collateralToken, address pair) = _NFTXPreLiquidationHook(_hToken, _collateralId, _vaultIndex); uint256[] memory assets = new uint256[](1); uint256[] memory amounts = new uint256[](1); assets[0] = _collateralId; amounts[0] = 1; collateralToken.approve(pair, _collateralId); INFTXVault(pair).mint(assets, amounts); emit NFTXLiquidationExecuted(pair, address(_hToken), _collateralId); return true; } /** * @notice Swap droplets for ERC20 using Uniswap V2 pools, and use the funds to repay a borrow * @param _hToken hToken contract address * @param _vaultIndex Which of the NFTX vaults for that collateral should be used * @param _borrower address of the current owner of the deposit coupon * @param _collateralId collateral Id, aka the NFT token ID * @param _path tokens to swap through, starting at droplet and ending at HToken's underlying * @param _amountIn quantity of droplets to liquidate * @param _amountOutMinimum minimum acceptable output quantity of output token * @return True upon success */ function swapNFTXDropletsAndRepayBorrow( HTokenI _hToken, uint256 _vaultIndex, address _borrower, uint256 _collateralId, address[] memory _path, uint256 _amountIn, uint256 _amountOutMinimum ) external nonReentrant onlyRole(SWAPPER_ROLE) returns (bool) { (, IERC20 underlying) = _NFTXPreSwapHook(_hToken, _collateralId); // Retrieve address address droplet = poolToNFTXVaults[_hToken][_vaultIndex]; // Arbitrary swap path is allowed, but it must start and end in the right place if (_path[0] != droplet) revert WrongParams(); if (_path[_path.length - 1] != address(underlying)) revert WrongParams(); // Set approval address cachedSwapRouter = address(swapRouter); uint256 currentAllowance = IERC20(droplet).allowance(address(this), cachedSwapRouter); if (currentAllowance != _amountIn) { // Decrease to 0 first for tokens mitigating the race condition IERC20(droplet).safeDecreaseAllowance(cachedSwapRouter, currentAllowance); IERC20(droplet).safeIncreaseAllowance(cachedSwapRouter, _amountIn); } // Dex swap swapExactUniV2(_amountIn, _amountOutMinimum, _path); postSwapHook(_hToken, underlying, _collateralId); // Closeout and repay funds _hToken.closeoutLiquidation(_borrower, _collateralId); marketplace.toggleLiquidation(_hToken, _collateralId, false); emit DropletsSwapped(droplet, _path, _amountIn, _amountOutMinimum); emit BorrowRepaid(address(_hToken), _borrower, _collateralId); return true; } function swapExactUniV2( uint256 _amountIn, uint256 _amountOutMin, address[] memory _path ) internal virtual returns (uint256[] memory) { uint256[] memory amounts = swapRouter.swapExactTokensForTokens( _amountIn, _amountOutMin, _path, address(this), block.timestamp ); return amounts; } }
//SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.15; import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol"; import ".././interfaces/MarketplaceI.sol"; import ".././utils/ErrorReporter.sol"; /** * @title Liquidator Storage * @author Honey Labs inc * @custom:coauthor BowTiedPickle * @custom:coauthor m4rio */ contract LiquidatorStorage { event DropletsSwapped(address indexed _droplet, address[] _path, uint256 _amountIn, uint256 _amountOut); event BorrowRepaid(address indexed _hToken, address indexed _borrower, uint256 _collateralId); /// @notice Uniswap router used for swapping droplets IUniswapV2Router02 public swapRouter; /// @notice The Marketplace contract used for selling the NFTs MarketplaceI public marketplace; // ----- Roles ----- bytes32 public constant SWAPPER_ROLE = keccak256("SWAPPER_ROLE"); bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); bytes32 public constant INITIALIZER_ROLE = keccak256("INITIALIZER_ROLE"); bytes32 public constant LIQUIDATOR_ROLE = keccak256("LIQUIDATOR_ROLE"); // ----- Constants ----- uint8 internal constant COUPON_UNINITIALIZED = 0; uint8 internal constant COUPON_INACTIVE = 1; uint8 internal constant COUPON_ACTIVE = 2; uint8 internal constant COUPON_LIQUIDATED = 3; constructor() {} }
//SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.15; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol"; import ".././interfaces/HTokenI.sol"; import ".././interfaces/LiquidatorI.sol"; import ".././interfaces/ControllerI.sol"; import ".././interfaces/MarketplaceI.sol"; import "./LiquidatorStorage.sol"; import ".././utils/ErrorReporter.sol"; import "./LiquidatorModuleNFT20.sol"; import "./LiquidatorModuleNFTX.sol"; import ".././utils/Arrays.sol"; /** * @title Honey Finance Marketplace * @notice Allows users to bid to purchase assets liquidated from unhealthy debt positions * @author Honey Labs Inc. * @custom:coauthor BowTiedPickle * @custom:coauthor m4rio */ contract Marketplace is AccessControl, ReentrancyGuard, Pausable, MarketplaceI { using SafeERC20 for IERC20; using EnumerableSet for EnumerableSet.AddressSet; using Arrays for uint256[50]; /// @notice Version of the contract. 1_000_000 corresponds to 1.0.0 uint256 public constant version = 1_000_000; /// @notice Amount that a bid must exceed the preceding bid by when the queue is full uint256 public minimumBidIncrementMantissa = 1e16; // default 1% /// @notice Amount that the first bid must exceed a coupon's debt /// @dev Recommended not to set this very low to avoid bad bids uint256 public reservePricePaddingMantissa = 1e17; // default 10% /// @notice Amount of profits payable to auction settler uint256 public settlementIncentiveMantissa = 1e16; // default 1% /// @notice Amount of time before a bidder can cancel their bid uint256 public bidCooldown = 1 days; bytes32 public constant ACCOUNTANT_ROLE = keccak256("ACCOUNTANT_ROLE"); bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); uint256 public constant maxBidIncrementMantissa = 1e17; // 10% uint256 public constant maxReservePricePaddingMantissa = 5e17; // 50% uint256 public constant maxSettlementIncentiveMantissa = 5e16; // 5% uint256 public constant maxBidCooldown = 2 days; uint256 public constant minBidCooldown = 1 hours; /// @notice Honey Finance Treasury address public treasury; enum SettleType { SINGLE_TOKEN, COLLECTION } struct CachedAuctionParams { address[50] bidders; uint256[50] bids; uint256[50] unlockTimes; uint256 firstNonZero; uint256 minimumBid; uint256 refund; address refundAddress; IERC20 underlying; } /// @notice Maps hTokens to collateralIds to Auctions mapping(HTokenI => mapping(uint256 => Auction)) public poolToTokenToAuction; /// @notice Maps hTokens to collection-wide Auctions mapping(HTokenI => Auction) public poolToAuction; /// @notice Maps hTokens to whether auctions are enabled on them or not mapping(HTokenI => bool) public poolToAuctionDisabled; /// @notice Maps ERC-20 underlying tokens to the total tied up as bids mapping(IERC20 => uint256) public tokenToTotalBids; /// @notice Maps ERC-20 underlying tokens to total owed refunds mapping(IERC20 => uint256) public tokenToTotalRefunds; /// @notice Maps ERC-20 underlying tokens to protocol-attributed profits mapping(IERC20 => uint256) public tokenToTotalProfits; /// @notice Maps ERC-20 underlying tokens to users owed refunds mapping(IERC20 => mapping(address => uint256)) public tokenToUserToRefunds; /// @notice ERC-721 collateral token to tokenId to HToken that asset was received from mapping(IERC721 => mapping(uint256 => HTokenI)) public collectionToTokenToSource; /// @notice ERC-721 collateral token to mapping of tokenIds to timestamp the token entered the contract mapping(IERC721 => mapping(uint256 => uint256)) public collectionToTokenToTimeReceived; /// @notice Protocol liquidation handler contract LiquidatorI public liquidator; /// @notice Honey protocol Controller ControllerI public controller; /** * @param _treasury Address of the Honey Finance treasury * @param _liquidator Address of the liquidation handler contract * @param _controller Address of the Controller */ constructor( address _treasury, LiquidatorI _liquidator, ControllerI _controller ) { if (_treasury == address(0)) revert WrongParams(); if (address(_liquidator) == address(0)) revert WrongParams(); if (address(_controller) == address(0)) revert WrongParams(); treasury = _treasury; liquidator = _liquidator; controller = _controller; _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); _setupRole(ACCOUNTANT_ROLE, msg.sender); _setupRole(PAUSER_ROLE, msg.sender); } // ---------- Liquidator only methods ---------- /** * @notice Enable liquidation for a specific token * @dev Can only be called by the liquidator. This call must happen when a token is transferred to the liquidator. * @param _hToken hToken contract address * @param _collateralId Token ID of the NFT * @param _enabled True for enabled, false for disabled */ function toggleLiquidation( HTokenI _hToken, uint256 _collateralId, bool _enabled ) external override nonReentrant { if (msg.sender != address(liquidator)) revert Unauthorized(); toggleLiquidationInternal(_hToken, _collateralId, _enabled); } // ---------- Public Functions ---------- /** * @notice Place a bid to purchase a specific collateral NFT liquidated from a specific hToken * @dev Bid must exceed the debt of the position collateralized by the NFT by a certain fraction. * @param _hToken hToken contract address * @param _collateralId Token ID of the NFT * @param _amount Bid price, denominated in tokens of the hToken's underlying currency */ function bidSingle( HTokenI _hToken, uint256 _collateralId, uint256 _amount ) external override nonReentrant whenNotPaused { if (!controller.marketExists(_hToken)) revert Uninitialized(); if (poolToAuctionDisabled[_hToken]) revert LiquidatorError(Error.AUCTION_NOT_ACTIVE); _hToken.accrueInterest(); uint256 debt = _hToken.getDebtForCollateral(_collateralId); if (debt == 0) revert LiquidatorError(Error.TOKEN_DEBT_NONEXISTENT); IERC20 underlying = _hToken.underlyingToken(); uint256 transferAmount = doUnderlyingTransferIn(underlying, msg.sender, _amount); if (transferAmount < viewMinimumNextBidSingle(_hToken, _collateralId)) revert LiquidatorError(Error.AUCTION_BID_TOO_LOW); tokenToTotalBids[underlying] += transferAmount; addToAuctionQueue(poolToTokenToAuction[_hToken][_collateralId], _hToken, msg.sender, transferAmount, true); emit SingleBidEntered(address(_hToken), msg.sender, _collateralId, transferAmount); } /** * @notice Place a bid to purchase any collateral NFT liquidated from a specific hToken * @param _hToken hToken contract address * @param _amount Bid price, denominated in tokens of the hToken's underlying currency */ function bidCollection(HTokenI _hToken, uint256 _amount) external override nonReentrant whenNotPaused { if (!controller.marketExists(_hToken)) revert Uninitialized(); if (poolToAuctionDisabled[_hToken]) revert LiquidatorError(Error.AUCTION_NOT_ACTIVE); IERC20 underlying = _hToken.underlyingToken(); uint256 transferAmount = doUnderlyingTransferIn(underlying, msg.sender, _amount); if (transferAmount < viewMinimumNextBidCollection(_hToken)) revert LiquidatorError(Error.AUCTION_BID_TOO_LOW); tokenToTotalBids[underlying] += transferAmount; addToAuctionQueue(poolToAuction[_hToken], _hToken, msg.sender, transferAmount, true); emit CollectionBidEntered(address(_hToken), msg.sender, transferAmount); } /** * @notice Increase an existing bid to purchase a specific collateral NFT liquidated from a specific hToken * @dev The new total bid amount must exceed the debt of the position collateralized by the NFT by a certain fraction. * @param _hToken hToken contract address * @param _collateralId Token ID of the NFT * @param _increaseAmount The amount to increase, denominated in tokens of the hToken's underlying currency */ function increaseBidSingle( HTokenI _hToken, uint256 _collateralId, uint256 _increaseAmount ) external override nonReentrant whenNotPaused { if (!controller.marketExists(_hToken)) revert Uninitialized(); if (poolToAuctionDisabled[_hToken]) revert LiquidatorError(Error.AUCTION_NOT_ACTIVE); _hToken.accrueInterest(); uint256 debt = _hToken.getDebtForCollateral(_collateralId); if (debt == 0) revert LiquidatorError(Error.TOKEN_DEBT_NONEXISTENT); // User must have an active bid in order to increase it Auction storage auction = poolToTokenToAuction[_hToken][_collateralId]; (bool present, uint256 index) = isUserInArray(auction.bidders, msg.sender); if (!present) revert LiquidatorError(Error.AUCTION_USER_NOT_FOUND); uint256 currentBid = auction.bids[index]; IERC20 underlying = _hToken.underlyingToken(); uint256 transferAmount = doUnderlyingTransferIn(underlying, msg.sender, _increaseAmount); if (transferAmount + currentBid < viewMinimumNextBidSingle(_hToken, _collateralId)) revert LiquidatorError(Error.AUCTION_BID_TOO_LOW); tokenToTotalBids[underlying] += transferAmount; addToAuctionQueue( poolToTokenToAuction[_hToken][_collateralId], _hToken, msg.sender, transferAmount + currentBid, false ); emit SingleBidIncreased(address(_hToken), msg.sender, _collateralId, transferAmount); } /** * @notice Increase an existing bid to purchase any collateral NFT liquidated from a specific hToken * @param _hToken hToken contract address * @param _increaseAmount The amount to increase, denominated in tokens of the hToken's underlying currency */ function increaseBidCollection(HTokenI _hToken, uint256 _increaseAmount) external override nonReentrant whenNotPaused { if (!controller.marketExists(_hToken)) revert Uninitialized(); if (poolToAuctionDisabled[_hToken]) revert LiquidatorError(Error.AUCTION_NOT_ACTIVE); // User must have an active bid in order to increase it Auction storage auction = poolToAuction[_hToken]; (bool present, uint256 index) = isUserInArray(auction.bidders, msg.sender); if (!present) revert LiquidatorError(Error.AUCTION_USER_NOT_FOUND); uint256 currentBid = auction.bids[index]; IERC20 underlying = _hToken.underlyingToken(); uint256 transferAmount = doUnderlyingTransferIn(underlying, msg.sender, _increaseAmount); if (transferAmount + currentBid < viewMinimumNextBidCollection(_hToken)) revert LiquidatorError(Error.AUCTION_BID_TOO_LOW); tokenToTotalBids[underlying] += transferAmount; addToAuctionQueue(poolToAuction[_hToken], _hToken, msg.sender, transferAmount + currentBid, false); emit CollectionBidIncreased(address(_hToken), msg.sender, transferAmount); } /** * @notice Settle an auction, sending the NFT to the winning bidder * @dev If enabled, pays an incentive fee to the caller * @dev Repays debt on the hToken * @param _hToken hToken contract address * @param _borrower Address of the debt owner * @param _collateralId Token ID of the NFT */ function settleAuction( HTokenI _hToken, address _borrower, uint256 _collateralId ) external override nonReentrant whenNotPaused { if (!controller.marketExists(_hToken)) revert Uninitialized(); if (poolToAuctionDisabled[_hToken]) revert LiquidatorError(Error.AUCTION_NOT_ACTIVE); IERC721 collateralToken = _hToken.collateralToken(); IERC20 underlyingToken = _hToken.underlyingToken(); if (collectionToTokenToTimeReceived[collateralToken][_collateralId] == 0) revert LiquidatorError(Error.AUCTION_SETTLE_FORBIDDEN); Auction storage singleAuction = poolToTokenToAuction[_hToken][_collateralId]; Auction storage collectionAuction = poolToAuction[_hToken]; address recipient; uint256 winningBid; SettleType settleType; if (singleAuction.highestBidder != address(0) || collectionAuction.highestBidder != address(0)) { // By convention, if token and collection bids are equal we consume the specific token bid settleType = (singleAuction.highestBid >= collectionAuction.highestBid) ? SettleType.SINGLE_TOKEN : SettleType.COLLECTION; } else { revert LiquidatorError(Error.AUCTION_NO_BIDS); } if (settleType == SettleType.SINGLE_TOKEN) { // Consume the single bid recipient = singleAuction.highestBidder; winningBid = singleAuction.highestBid; tokenToTotalBids[underlyingToken] -= singleAuction.highestBid; removeFromAuctionQueue(singleAuction, singleAuction.bids.length - 1, false); } else if (settleType == SettleType.COLLECTION) { // Consume the collection bid recipient = collectionAuction.highestBidder; winningBid = collectionAuction.highestBid; tokenToTotalBids[underlyingToken] -= collectionAuction.highestBid; removeFromAuctionQueue(collectionAuction, collectionAuction.bids.length - 1, false); } // Get current debt _hToken.accrueInterest(); uint256 debt = _hToken.getDebtForCollateral(_collateralId); if (debt > winningBid) revert LiquidatorError(Error.INSUFFICIENT_WINNING_BID); uint256 incentive = ((winningBid - debt) * settlementIncentiveMantissa) / 1e18; tokenToTotalProfits[underlyingToken] += winningBid - debt - incentive; // Reset the liquidation state toggleLiquidationInternal(_hToken, _collateralId, false); // Closeout the borrow _hToken.underlyingToken().safeIncreaseAllowance(address(_hToken), debt); _hToken.closeoutLiquidation(_borrower, _collateralId); // Send incentive to settler if (incentive > 0) { underlyingToken.safeTransfer(msg.sender, incentive); } // Transfer the NFT to the recipient collateralToken.safeTransferFrom(address(liquidator), recipient, _collateralId); emit AuctionSettled(address(_hToken), recipient, _collateralId, winningBid, settleType); } /** * @notice Cancel a bid for a specific single token * @param _hToken hToken contract address * @param _collateralId Token ID of the NFT */ function cancelBidSingle(HTokenI _hToken, uint256 _collateralId) external override nonReentrant whenNotPaused { if (!controller.marketExists(_hToken)) revert Uninitialized(); Auction storage auction = poolToTokenToAuction[_hToken][_collateralId]; (bool present, uint256 index) = isUserInArray(auction.bidders, msg.sender); if (!present) revert LiquidatorError(Error.UNAUTHORIZED); if (block.timestamp < auction.unlockTimes[index]) revert LiquidatorError(Error.CANCEL_TOO_SOON); removeFromAuctionQueue(auction, index, true); emit SingleBidWithdrawn(address(_hToken), msg.sender, _collateralId); } /** * @notice Cancel the winning bid against a collection * @param _hToken hToken contract address */ function cancelBidCollection(HTokenI _hToken) external override nonReentrant whenNotPaused { if (!controller.marketExists(_hToken)) revert Uninitialized(); Auction storage auction = poolToAuction[_hToken]; (bool present, uint256 index) = isUserInArray(auction.bidders, msg.sender); if (!present) revert LiquidatorError(Error.UNAUTHORIZED); if (block.timestamp < auction.unlockTimes[index]) revert LiquidatorError(Error.CANCEL_TOO_SOON); removeFromAuctionQueue(auction, index, true); emit CollectionBidWithdrawn(address(_hToken), msg.sender); } /** * @notice Withdraw all refunds owed to a user from failed or canceled bids, for a specific bid currency * @param _token IERC20 token to refund * @return Amount of refund withdrawn */ function withdrawRefund(IERC20 _token) external override nonReentrant returns (uint256) { uint256 refundDue = tokenToUserToRefunds[_token][msg.sender]; if (refundDue > 0) { tokenToUserToRefunds[_token][msg.sender] = 0; tokenToTotalRefunds[_token] -= refundDue; _token.safeTransfer(msg.sender, refundDue); } else { revert LiquidatorError(Error.REFUND_NOT_OWED); } emit RefundWithdrawn(msg.sender, address(_token), refundDue); return refundDue; } // ---------- View Functions ---------- /** * @notice View the minimum next bid for a single collateral * @param _hToken hToken contract address * @param _collateralId Token ID of the NFT * @return Minimum bid in units of the hToken's underlying token */ function viewMinimumNextBidSingle(HTokenI _hToken, uint256 _collateralId) public view override returns (uint256) { Auction storage auction = poolToTokenToAuction[_hToken][_collateralId]; uint256 firstNonZero = auction.bids.findUpperBound(0); uint256 minimumBid; uint256 debtWithPadding = (_hToken.getDebtForCollateral(_collateralId) * (reservePricePaddingMantissa + 1e18)) / 1e18; if (firstNonZero == 0) { uint256 lowestWithPadding = (auction.bids[firstNonZero] * (minimumBidIncrementMantissa + 1e18)) / 1e18; minimumBid = lowestWithPadding > debtWithPadding ? lowestWithPadding : debtWithPadding; } else { minimumBid = debtWithPadding; } return minimumBid; } /** * @notice View the minimum next bid for a collection * @param _hToken hToken contract address * @return Minimum bid in units of the hToken's underlying token */ function viewMinimumNextBidCollection(HTokenI _hToken) public view override returns (uint256) { Auction storage auction = poolToAuction[_hToken]; uint256 firstNonZero = auction.bids.findUpperBound(0); uint256 minimumBid; if (firstNonZero == 0) { minimumBid = (auction.bids[firstNonZero] * (minimumBidIncrementMantissa + 1e18)) / 1e18; } else { minimumBid = 1; } return minimumBid; } /** * @notice Retrieve a specified single auction * @param _hToken hToken contract address * @param _collateralId Token ID of the NFT * returns Auction struct for the specified auction */ function viewAuctionSingle(HTokenI _hToken, uint256 _collateralId) external view override returns (Auction memory) { return poolToTokenToAuction[_hToken][_collateralId]; } /** * @notice Retrieve a specified collection auction * @param _hToken hToken contract address * returns Auction struct for the specified auction */ function viewAuctionCollection(HTokenI _hToken) external view override returns (Auction memory) { return poolToAuction[_hToken]; } /** * @notice View the available refund for a user * @param _token IERC20 token to refund * @param _user Address of the user to query * @return Amount of refund due, denominated in that token */ function viewAvailableRefund(IERC20 _token, address _user) external view override returns (uint256) { return tokenToUserToRefunds[_token][_user]; } /** * @notice View a user's bid in a particular single auction * @param _user Address of the user to query * @param _hToken hToken contract address * @param _collateralId Token ID of the NFT * @return (bid amount in units of underlying token, bid unlock timestamp in Unix epoch seconds) */ function viewUserBidSingle( address _user, HTokenI _hToken, uint256 _collateralId ) external view override returns (uint256, uint256) { uint256 bid; uint256 unlockTime; Auction storage auction = poolToTokenToAuction[_hToken][_collateralId]; (bool present, uint256 index) = isUserInArray(auction.bidders, _user); if (present) { bid = auction.bids[index]; unlockTime = auction.unlockTimes[index]; } return (bid, unlockTime); } /** * @notice View a user's bid in a particular collection auction * @param _user Address of the user to query * @param _hToken hToken contract address * @return (bid amount in units of underlying token, bid unlock timestamp in Unix epoch seconds) */ function viewUserBidCollection(address _user, HTokenI _hToken) external view override returns (uint256, uint256) { uint256 bid; uint256 unlockTime; Auction storage auction = poolToAuction[_hToken]; (bool present, uint256 index) = isUserInArray(auction.bidders, _user); if (present) { bid = auction.bids[index]; unlockTime = auction.unlockTimes[index]; } return (bid, unlockTime); } // ---------- Internal Functions ---------- /** * @dev Transfer the given amount of the given underlying token to this contract * @dev Requires this contract to be adequately approved to transfer the amount * @param _underlyingToken The ERC20 to transfer * @param _from Address to transfer from * @param _amount Quantity of tokens to transfer * @return Quantity of tokens actually transferred */ function doUnderlyingTransferIn( IERC20 _underlyingToken, address _from, uint256 _amount ) internal returns (uint256) { uint256 balanceBefore = _underlyingToken.balanceOf(address(this)); _underlyingToken.safeTransferFrom(_from, address(this), _amount); uint256 balanceAfter = _underlyingToken.balanceOf(address(this)); if (balanceAfter < balanceBefore) revert Unexpected("Transfer invariant error"); unchecked { return balanceAfter - balanceBefore; } } /** * @dev Adds a bid to an auction queue at the appropriate location by bid amount. Two equal bids are ordered in FIFO. * @dev If a user has an existing bid, it is removed before the new bid is inserted into the queue. * @param _auction Auction to add the bid to * @param _hToken hToken contract address * @param _bidder User making the bid * @param _transferAmount Amount of the bid * @param _refundOnOverwrite Whether to refund a user when overwriting an existing bid */ function addToAuctionQueue( Auction storage _auction, HTokenI _hToken, address _bidder, uint256 _transferAmount, bool _refundOnOverwrite ) internal { CachedAuctionParams memory params; params.bids = _auction.bids; params.bidders = _auction.bidders; params.unlockTimes = _auction.unlockTimes; params.underlying = _auction.underlying; uint256 len = params.bids.length; // If no bids are placed, we don't need to do any sorting or other considerations if (_auction.highestBidder == address(0)) { _auction.highestBidder = _bidder; _auction.highestBid = _transferAmount; _auction.bids[len - 1] = _transferAmount; _auction.bidders[len - 1] = _bidder; _auction.unlockTimes[len - 1] = block.timestamp + bidCooldown; _auction.underlying = _hToken.underlyingToken(); } // If a user already has a bid, we remove it first (bool present, uint256 index) = isUserInArray(params.bidders, _bidder); if (present) { removeFromAuctionQueue(_auction, index, _refundOnOverwrite); params.bids = _auction.bids; params.bidders = _auction.bidders; params.unlockTimes = _auction.unlockTimes; } // Determine where in the array to insert uint256 bound = params.bids.findUpperBound(_transferAmount); // If the new bid is the highest, update if (_auction.highestBid < _transferAmount) { _auction.highestBidder = _bidder; _auction.highestBid = _transferAmount; } params.refundAddress = params.bidders[0]; params.refund = params.bids[0]; // Move down the other elements if (bound - 1 > 0) { for (uint256 i; i < bound - 1; ) { _auction.bids[i] = params.bids[i + 1]; _auction.bidders[i] = params.bidders[i + 1]; _auction.unlockTimes[i] = params.unlockTimes[i + 1]; unchecked { ++i; } } } // Add the new element _auction.bids[bound - 1] = _transferAmount; _auction.bidders[bound - 1] = _bidder; _auction.unlockTimes[bound - 1] = block.timestamp + bidCooldown; _auction.underlying = _hToken.underlyingToken(); // Update state variables if refunding if (params.refund > 0) { tokenToUserToRefunds[params.underlying][params.refundAddress] += params.refund; tokenToTotalRefunds[params.underlying] += params.refund; tokenToTotalBids[params.underlying] -= params.refund; emit Refund(params.refundAddress, address(params.underlying), params.refund); } } /** * @dev Determine if an address is in an auction array * @param _array Auction array * @param _user Address of the user to query * @return (true if present, index of address if present otherwise 0) */ function isUserInArray(address[50] memory _array, address _user) internal pure returns (bool, uint256) { uint256 len = _array.length; for (uint256 i; i < len; ) { if (_array[i] == _user) return (true, i); unchecked { ++i; } } return (false, 0); } /** * @dev Toggle liquidation for a specific collateral */ function toggleLiquidationInternal( HTokenI _hToken, uint256 _collateralId, bool _enabled ) internal { IERC721 collateral = _hToken.collateralToken(); if (_enabled) { collectionToTokenToTimeReceived[collateral][_collateralId] = block.timestamp; // Attribute to an HToken collectionToTokenToSource[collateral][_collateralId] = _hToken; } else { collectionToTokenToTimeReceived[collateral][_collateralId] = 0; // Attribute to an HToken collectionToTokenToSource[collateral][_collateralId] = HTokenI(address(0)); } emit LiquidationToggled(_hToken, _collateralId, _enabled); } /** * @dev Remove an entry from the auction queue * @param _auction Auction being operated on * @param _index Index in the auction array to remove * @param _refund Whether to refund the bidder being removed */ function removeFromAuctionQueue( Auction storage _auction, uint256 _index, bool _refund ) internal returns (Auction memory) { CachedAuctionParams memory params; params.bids = _auction.bids; params.bidders = _auction.bidders; params.unlockTimes = _auction.unlockTimes; params.underlying = _auction.underlying; uint256 len = params.bids.length; // If removing the highest bidder, promote the next highest if any, we need to see if the first zero it's lowest than len - 2 // e.g. [0,0,0,1,2] if we remove last index, then 1 must be promoted as highest bid if (_index == len - 1) { _auction.highestBidder = params.bidders[len - 2]; _auction.highestBid = params.bids[len - 2]; } address removedAddress = params.bidders[_index]; uint256 removedAmount = params.bids[_index]; // Retaining the zero check as a sanity check if (removedAddress != address(0) && _refund) { tokenToUserToRefunds[params.underlying][removedAddress] += removedAmount; tokenToTotalRefunds[params.underlying] += removedAmount; tokenToTotalBids[params.underlying] -= removedAmount; emit Refund(removedAddress, address(params.underlying), removedAmount); } // Move up the other elements for (uint256 i = _index; i > 0; ) { _auction.bids[i] = params.bids[i - 1]; _auction.bidders[i] = params.bidders[i - 1]; _auction.unlockTimes[i] = params.unlockTimes[i - 1]; unchecked { --i; } } // Overwrite the first element with zero _auction.bids[0] = 0; _auction.bidders[0] = address(0); return _auction; } // ---------- Admin Functions ---------- /** * @notice Enable or disable P2P auctions for a particular hToken * @param _hToken The hToken to enable/disable auctions for */ function _setAuctionStatus(HTokenI _hToken, bool _status) external onlyRole(DEFAULT_ADMIN_ROLE) { poolToAuctionDisabled[_hToken] = _status; emit NewAuctionStatus(address(_hToken), _status); } /** * @notice Change the auction minimum bid amount * @param _newMinimumBidIncrement in mantissa format */ function _updateMinimumBidIncrement(uint256 _newMinimumBidIncrement) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_newMinimumBidIncrement > maxBidIncrementMantissa) revert WrongParams(); emit NewMinimumBidIncrement(minimumBidIncrementMantissa, _newMinimumBidIncrement); minimumBidIncrementMantissa = _newMinimumBidIncrement; } /** * @notice Change the auction reserve price padding * @param _newReservePricePadding in mantissa format */ function _updateReservePricePadding(uint256 _newReservePricePadding) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_newReservePricePadding > maxReservePricePaddingMantissa) revert WrongParams(); emit NewReservePricePadding(reservePricePaddingMantissa, _newReservePricePadding); reservePricePaddingMantissa = _newReservePricePadding; } /** * @notice Change the settlement incentive paid to auction settle executor * @param _newSettlementIncentive in mantissa format */ function _updateSettlementIncentive(uint256 _newSettlementIncentive) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_newSettlementIncentive > maxSettlementIncentiveMantissa) revert WrongParams(); emit NewSettlementIncentive(settlementIncentiveMantissa, _newSettlementIncentive); settlementIncentiveMantissa = _newSettlementIncentive; } /** * @notice Change the cooldown before a bid can be canceled * @param _newBidCooldown Cooldown in seconds */ function _updateBidCooldown(uint256 _newBidCooldown) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_newBidCooldown > maxBidCooldown || _newBidCooldown < minBidCooldown) revert WrongParams(); emit NewBidCooldown(bidCooldown, _newBidCooldown); bidCooldown = _newBidCooldown; } /** * @notice Pause bids, settles, and bid cancellations * @param _pausing True for paused, false for unpaused */ function _pauseMarketplace(bool _pausing) external onlyRole(PAUSER_ROLE) { if (_pausing) _pause(); else _unpause(); emit MarketplacePaused(_pausing); } /** * @notice Sweep accidental ERC-20 transfers to this contract, or withdraw droplets for OTC. Tokens are sent to treasury * @dev Cannot be used to withdraw underlying tokens * @dev Start/end indices not used for now. Might be needed to be used if the no. of markets will grow to an OoG error * @param _token Address of the ERC-20 token to sweep */ function _sweepToken(IERC20 _token) external onlyRole(DEFAULT_ADMIN_ROLE) { if (controller.underlyingExistsInMarkets(address(_token))) revert Unauthorized(); uint256 balance = _token.balanceOf(address(this)); if (balance > 0) { _token.safeTransfer(treasury, balance); emit TokenSwept(_token, balance); } } /** * @notice Withdraw the profits earned by the protocol to the treasury * @dev Cannot be used to withdraw dust tokens * @param _hToken hToken contract address */ function _withdrawProfits(HTokenI _hToken) external nonReentrant onlyRole(DEFAULT_ADMIN_ROLE) { if (!controller.marketExists(_hToken)) revert Unauthorized(); IERC20 underlying = _hToken.underlyingToken(); uint256 profits = tokenToTotalProfits[underlying]; // we can not withdraw refunds/bids uint256 maxWithdrawable = underlying.balanceOf(address(this)) - tokenToTotalRefunds[underlying] - tokenToTotalBids[underlying]; if (maxWithdrawable < profits) profits = maxWithdrawable; tokenToTotalProfits[underlying] -= profits; if (profits > 0) { underlying.safeTransfer(treasury, profits); } emit ProfitsWithdrawn(underlying, profits); } /** * @notice Refund all the bids in a single auction * @param _hToken hToken contract address * @param _collateralId Token ID of the NFT */ function _refundAllBidsPerCollateral(HTokenI _hToken, uint256 _collateralId) external override onlyRole(ACCOUNTANT_ROLE) { Auction storage _auction = poolToTokenToAuction[_hToken][_collateralId]; address[50] memory bidders = _auction.bidders; for (uint256 i; i < 50; i++) { if (bidders[i] != address(0)) { removeFromAuctionQueue(_auction, i, true); } } _auction.highestBid = 0; _auction.highestBidder = address(0); emit AuctionFullyRefunded(_hToken, _collateralId); } /** * @notice Refund all the bids in a collection auction * @param _hToken hToken contract address */ function _refundAllBidsPerCollection(HTokenI _hToken) external override onlyRole(ACCOUNTANT_ROLE) { Auction storage _auction = poolToAuction[_hToken]; address[50] memory bidders = _auction.bidders; for (uint256 i; i < 50; i++) { if (bidders[i] != address(0)) { removeFromAuctionQueue(_auction, i, true); } } _auction.highestBid = 0; _auction.highestBidder = address(0); emit AuctionFullyRefunded(_hToken, 0); } /** * @notice Set the marketplace treasury address * @param _newTreasury The new treasury address */ function _setTreasury(address _newTreasury) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_newTreasury == address(0)) revert WrongParams(); emit TreasuryUpdated(treasury, _newTreasury); treasury = _newTreasury; } /** * @notice Set the Controller contract address * @param _newController The new Controller address */ function _setController(ControllerI _newController) external onlyRole(DEFAULT_ADMIN_ROLE) { if (address(_newController) == address(0)) revert WrongParams(); emit ControllerUpdated(controller, _newController); controller = _newController; } // ---------- Events ---------- event SingleBidEntered( address indexed _hToken, address indexed _user, uint256 indexed _collateralId, uint256 _amount ); event SingleBidIncreased( address indexed _hToken, address indexed _user, uint256 indexed _collateralId, uint256 _amount ); event SingleBidWithdrawn(address indexed _hToken, address indexed _user, uint256 indexed _collateralId); event CollectionBidEntered(address indexed _hToken, address indexed _user, uint256 _amount); event CollectionBidIncreased(address indexed _hToken, address indexed _user, uint256 _amount); event CollectionBidWithdrawn(address indexed _hToken, address indexed _user); event AuctionSettled( address indexed _hToken, address indexed _user, uint256 indexed _collateralId, uint256 _amount, SettleType _settleType ); event Refund(address indexed _user, address indexed _token, uint256 _amount); event RefundWithdrawn(address indexed _user, address indexed _token, uint256 _amount); event NewAuctionStatus(address indexed _hToken, bool _status); event NewMinimumBidIncrement(uint256 _oldIncrement, uint256 _newIncrement); event NewReservePricePadding(uint256 _oldPadding, uint256 _newPadding); event NewSettlementIncentive(uint256 _oldIncentive, uint256 _newIncentive); event NewBidCooldown(uint256 _oldCooldown, uint256 _newCooldown); event TreasuryUpdated(address _oldTreasury, address _newTreasury); event ControllerUpdated(ControllerI _oldController, ControllerI _newController); event TokenSwept(IERC20 indexed _token, uint256 _qty); event ProfitsWithdrawn(IERC20 indexed _token, uint256 _qty); event LiquidationToggled(HTokenI indexed _hToken, uint256 indexed _collateralId, bool _enabled); event AuctionFullyRefunded(HTokenI indexed _hToken, uint256 indexed _collateralId); event CollectionAuctionFullyRefunded(HTokenI indexed _hToken); event MarketplacePaused(bool _paused); }
//SPDX-License-Identifier: BUSL-1.1 // OpenZeppelin Contracts v4.4.1 (utils/Arrays.sol) pragma solidity ^0.8.0; // import "./math/Math.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; /** * @dev Collection of functions related to array types. */ library Arrays { /** * @dev Searches a sorted `array` and returns the first index that contains * a value greater or equal to `element`. If no such index exists (i.e. all * values in the array are strictly less than `element`), the array length is * returned. Time complexity O(log n). * * `array` is expected to be sorted in ascending order, and to contain no * repeated elements. */ function findUpperBound(uint256[50] memory array, uint256 element) internal pure returns (uint256) { if (array.length == 0) { return 0; } uint256 low = 0; uint256 high = array.length; while (low < high) { uint256 mid = Math.average(low, high); // Note that mid will always be strictly less than high (i.e. it will be a valid array index) // because Math.average rounds down (it does integer division with truncation). if (array[mid] > element && array[mid] > 0) { high = mid; } else { low = mid + 1; } } // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound. if (low > 0 && array[low - 1] == element) { return low - 1; } else { return low; } } }
//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 }
{ "optimizer": { "enabled": true, "runs": 300 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_treasury","type":"address"},{"internalType":"contract LiquidatorI","name":"_liquidator","type":"address"},{"internalType":"contract ControllerI","name":"_controller","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Error","name":"error","type":"uint8"}],"name":"LiquidatorError","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[{"internalType":"string","name":"error","type":"string"}],"name":"Unexpected","type":"error"},{"inputs":[],"name":"Uninitialized","type":"error"},{"inputs":[],"name":"WrongParams","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"indexed":true,"internalType":"uint256","name":"_collateralId","type":"uint256"}],"name":"AuctionFullyRefunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_hToken","type":"address"},{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":true,"internalType":"uint256","name":"_collateralId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"},{"indexed":false,"internalType":"enum Marketplace.SettleType","name":"_settleType","type":"uint8"}],"name":"AuctionSettled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"CollectionAuctionFullyRefunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_hToken","type":"address"},{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"CollectionBidEntered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_hToken","type":"address"},{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"CollectionBidIncreased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_hToken","type":"address"},{"indexed":true,"internalType":"address","name":"_user","type":"address"}],"name":"CollectionBidWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract ControllerI","name":"_oldController","type":"address"},{"indexed":false,"internalType":"contract ControllerI","name":"_newController","type":"address"}],"name":"ControllerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"indexed":true,"internalType":"uint256","name":"_collateralId","type":"uint256"},{"indexed":false,"internalType":"bool","name":"_enabled","type":"bool"}],"name":"LiquidationToggled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"_paused","type":"bool"}],"name":"MarketplacePaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_hToken","type":"address"},{"indexed":false,"internalType":"bool","name":"_status","type":"bool"}],"name":"NewAuctionStatus","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_oldCooldown","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newCooldown","type":"uint256"}],"name":"NewBidCooldown","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_oldIncrement","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newIncrement","type":"uint256"}],"name":"NewMinimumBidIncrement","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_oldPadding","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newPadding","type":"uint256"}],"name":"NewReservePricePadding","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_oldIncentive","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newIncentive","type":"uint256"}],"name":"NewSettlementIncentive","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_qty","type":"uint256"}],"name":"ProfitsWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"Refund","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"RefundWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_hToken","type":"address"},{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":true,"internalType":"uint256","name":"_collateralId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"SingleBidEntered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_hToken","type":"address"},{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":true,"internalType":"uint256","name":"_collateralId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"SingleBidIncreased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_hToken","type":"address"},{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":true,"internalType":"uint256","name":"_collateralId","type":"uint256"}],"name":"SingleBidWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_qty","type":"uint256"}],"name":"TokenSwept","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldTreasury","type":"address"},{"indexed":false,"internalType":"address","name":"_newTreasury","type":"address"}],"name":"TreasuryUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"ACCOUNTANT_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_pausing","type":"bool"}],"name":"_pauseMarketplace","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_collateralId","type":"uint256"}],"name":"_refundAllBidsPerCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"_refundAllBidsPerCollection","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"_setAuctionStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ControllerI","name":"_newController","type":"address"}],"name":"_setController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newTreasury","type":"address"}],"name":"_setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"}],"name":"_sweepToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newBidCooldown","type":"uint256"}],"name":"_updateBidCooldown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newMinimumBidIncrement","type":"uint256"}],"name":"_updateMinimumBidIncrement","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newReservePricePadding","type":"uint256"}],"name":"_updateReservePricePadding","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newSettlementIncentive","type":"uint256"}],"name":"_updateSettlementIncentive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"_withdrawProfits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"bidCollection","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"bidCooldown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_collateralId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"bidSingle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"cancelBidCollection","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_collateralId","type":"uint256"}],"name":"cancelBidSingle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC721","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"collectionToTokenToSource","outputs":[{"internalType":"contract HTokenI","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC721","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"collectionToTokenToTimeReceived","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"controller","outputs":[{"internalType":"contract ControllerI","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_increaseAmount","type":"uint256"}],"name":"increaseBidCollection","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_collateralId","type":"uint256"},{"internalType":"uint256","name":"_increaseAmount","type":"uint256"}],"name":"increaseBidSingle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liquidator","outputs":[{"internalType":"contract LiquidatorI","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxBidCooldown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxBidIncrementMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxReservePricePaddingMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSettlementIncentiveMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minBidCooldown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumBidIncrementMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"","type":"address"}],"name":"poolToAuction","outputs":[{"internalType":"contract IERC20","name":"underlying","type":"address"},{"internalType":"address","name":"highestBidder","type":"address"},{"internalType":"uint256","name":"highestBid","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"","type":"address"}],"name":"poolToAuctionDisabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"poolToTokenToAuction","outputs":[{"internalType":"contract IERC20","name":"underlying","type":"address"},{"internalType":"address","name":"highestBidder","type":"address"},{"internalType":"uint256","name":"highestBid","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"reservePricePaddingMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"uint256","name":"_collateralId","type":"uint256"}],"name":"settleAuction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"settlementIncentiveMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_collateralId","type":"uint256"},{"internalType":"bool","name":"_enabled","type":"bool"}],"name":"toggleLiquidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"name":"tokenToTotalBids","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"name":"tokenToTotalProfits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"name":"tokenToTotalRefunds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"tokenToUserToRefunds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"viewAuctionCollection","outputs":[{"components":[{"internalType":"contract IERC20","name":"underlying","type":"address"},{"internalType":"address","name":"highestBidder","type":"address"},{"internalType":"uint256","name":"highestBid","type":"uint256"},{"internalType":"address[50]","name":"bidders","type":"address[50]"},{"internalType":"uint256[50]","name":"bids","type":"uint256[50]"},{"internalType":"uint256[50]","name":"unlockTimes","type":"uint256[50]"}],"internalType":"struct MarketplaceI.Auction","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_collateralId","type":"uint256"}],"name":"viewAuctionSingle","outputs":[{"components":[{"internalType":"contract IERC20","name":"underlying","type":"address"},{"internalType":"address","name":"highestBidder","type":"address"},{"internalType":"uint256","name":"highestBid","type":"uint256"},{"internalType":"address[50]","name":"bidders","type":"address[50]"},{"internalType":"uint256[50]","name":"bids","type":"uint256[50]"},{"internalType":"uint256[50]","name":"unlockTimes","type":"uint256[50]"}],"internalType":"struct MarketplaceI.Auction","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"},{"internalType":"address","name":"_user","type":"address"}],"name":"viewAvailableRefund","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"viewMinimumNextBidCollection","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_collateralId","type":"uint256"}],"name":"viewMinimumNextBidSingle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"contract HTokenI","name":"_hToken","type":"address"}],"name":"viewUserBidCollection","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"contract HTokenI","name":"_hToken","type":"address"},{"internalType":"uint256","name":"_collateralId","type":"uint256"}],"name":"viewUserBidSingle","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"}],"name":"withdrawRefund","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
6080604052662386f26fc1000060035567016345785d8a0000600455662386f26fc10000600555620151806006553480156200003a57600080fd5b5060405162005181380380620051818339810160408190526200005d9162000257565b600180556002805460ff191690556001600160a01b0383166200009357604051635863f78960e01b815260040160405180910390fd5b6001600160a01b038216620000bb57604051635863f78960e01b815260040160405180910390fd5b6001600160a01b038116620000e357604051635863f78960e01b815260040160405180910390fd5b600780546001600160a01b038086166001600160a01b0319928316179092556011805485841690831617905560128054928416929091169190911790556200012d6000336200018e565b620001597f369da55721ba2b3acddd63aac7d6512c3e5762a78fa01c44f423f97868330c34336200018e565b620001857f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a336200018e565b505050620002ab565b6200019a82826200019e565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166200019a576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620001fa3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6001600160a01b03811681146200025457600080fd5b50565b6000806000606084860312156200026d57600080fd5b83516200027a816200023e565b60208501519093506200028d816200023e565b6040850151909250620002a0816200023e565b809150509250925092565b614ec680620002bb6000396000f3fe608060405234801561001057600080fd5b50600436106103a35760003560e01c80636a82958f116101e9578063bc2426aa1161010f578063e2238cba116100ad578063f77c47911161007c578063f77c479114610937578063fdbc98201461094a578063fe019d871461095d578063fe0505b51461097057600080fd5b8063e2238cba146108e0578063e468f511146108ea578063e63ab1e9146108fd578063f261a7c11461092457600080fd5b8063becbbc77116100e9578063becbbc771461087c578063cd36176d1461088f578063d547741f146108ba578063da981b16146108cd57600080fd5b8063bc2426aa14610811578063bd3c2b4c14610820578063be179ae31461085c57600080fd5b806391d1485411610187578063a217fddf11610156578063a217fddf146107bc578063ab1efbab146107c4578063ac8575c8146107eb578063b014f5ec146107fe57600080fd5b806391d148541461073f578063975cd1b314610776578063a16c86f714610796578063a20bf780146107a957600080fd5b80637abdfa8e116101c35780637abdfa8e146106f757806383de424e1461070a57806389bf6f061461071d57806390c600771461073057600080fd5b80636a82958f146106be57806373cf05b3146106d15780637a9672fe146106e457600080fd5b806334f66648116102ce5780634d45f2b91161026c5780635fc985291161023b5780635fc985291461067957806361d027b314610699578063665c48b8146106ac5780636a19544a146106b557600080fd5b80634d45f2b9146105e4578063518a2976146105f757806354fd4d50146106645780635c975abb1461066e57600080fd5b80633e5a179f116102a85780633e5a179f146105385780634046ebae1461056057806342e2c48e1461058b57806349b75fb1146105ab57600080fd5b806334f666481461050957806336568abe146105125780633e1d56a21461052557600080fd5b80632230354f116103465780632a08922c116103155780632a08922c146104bd5780632afc512e146104d05780632f2ff15d146104e3578063330d33a5146104f657600080fd5b80632230354f1461045b578063248a9ca31461047e578063259bdcb7146104a157806329c63eed146104aa57600080fd5b8063070b824111610382578063070b824114610401578063071cb03e1461041457806316c5d3661461043f57806317f2edc41461045257600080fd5b8062333cd5146103a857806301ffc9a7146103bd57806303e8f0d6146103e5575b600080fd5b6103bb6103b6366004614959565b6109a4565b005b6103d06103cb366004614972565b610a1a565b60405190151581526020015b60405180910390f35b6103f366b1a2bc2ec5000081565b6040519081526020016103dc565b6103bb61040f3660046149b1565b610a51565b6103f36104223660046149dd565b600e60209081526000928352604080842090915290825290205481565b6103bb61044d366004614a24565b610b86565b6103f360035481565b6103d0610469366004614a52565b600a6020526000908152604090205460ff1681565b6103f361048c366004614959565b60009081526020819052604090206001015490565b6103f360065481565b6103bb6104b8366004614959565b610bf2565b6103bb6104cb366004614a52565b610c67565b6103bb6104de366004614a52565b610d03565b6103bb6104f1366004614a6f565b610f5a565b6103bb610504366004614a94565b610f84565b6103f360045481565b6103bb610520366004614a6f565b611365565b6103bb6105333660046149b1565b6113e3565b61054b6105463660046149dd565b6115fa565b604080519283526020830191909152016103dc565b601154610573906001600160a01b031681565b6040516001600160a01b0390911681526020016103dc565b6103f3610599366004614a52565b600c6020526000908152604090205481565b6103f36105b93660046149dd565b6001600160a01b039182166000908152600e6020908152604080832093909416825291909152205490565b6103f36105f2366004614a52565b6116b1565b61063e6106053660046149b1565b60086020908152600092835260408084209091529082529020805460018201546002909201546001600160a01b03918216929091169083565b604080516001600160a01b039485168152939092166020840152908201526060016103dc565b6103f3620f424081565b60025460ff166103d0565b61068c610687366004614a52565b61177a565b6040516103dc9190614aec565b600754610573906001600160a01b031681565b6103f3610e1081565b6103f360055481565b6103bb6106cc366004614959565b611884565b6103bb6106df366004614a52565b6118fa565b6103bb6106f2366004614959565b611a22565b6103bb610705366004614b77565b611a9f565b6103bb610718366004614a52565b611b1d565b6103bb61072b3660046149b1565b611bb9565b6103f367016345785d8a000081565b6103d061074d366004614a6f565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6103f3610784366004614a52565b600b6020526000908152604090205481565b6103f36107a4366004614a52565b611d62565b6103bb6107b7366004614a94565b611e61565b6103f3600081565b6103f37f369da55721ba2b3acddd63aac7d6512c3e5762a78fa01c44f423f97868330c3481565b6103bb6107f9366004614b94565b612178565b6103bb61080c366004614a52565b6121be565b6103f36706f05b59d3b2000081565b61063e61082e366004614a52565b6009602052600090815260409020805460018201546002909201546001600160a01b03918216929091169083565b6103f361086a366004614a52565b600d6020526000908152604090205481565b6103f361088a3660046149b1565b61231c565b6103f361089d3660046149b1565b601060209081526000928352604080842090915290825290205481565b6103bb6108c8366004614a6f565b6124a1565b61054b6108db366004614bd6565b6124c6565b6103f36202a30081565b6103bb6108f83660046149b1565b612587565b6103f37f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a81565b61068c6109323660046149b1565b612843565b601254610573906001600160a01b031681565b6103bb610958366004614bd6565b612956565b6103bb61096b366004614a52565b612fe6565b61057361097e3660046149b1565b600f6020908152600092835260408084209091529082529020546001600160a01b031681565b60006109af81613185565b67016345785d8a00008211156109d857604051635863f78960e01b815260040160405180910390fd5b60035460408051918252602082018490527f8b0a2001fd09df457eb280e100779701a28d9c696e7c2bfe9d64685af0c4978c910160405180910390a150600355565b60006001600160e01b03198216637965db0b60e01b1480610a4b57506301ffc9a760e01b6001600160e01b03198316145b92915050565b7f369da55721ba2b3acddd63aac7d6512c3e5762a78fa01c44f423f97868330c34610a7b81613185565b6001600160a01b03831660009081526008602090815260408083208584529091528082208151610640810192839052909291600384019060329082845b81546001600160a01b03168152600190910190602001808311610ab8575050505050905060005b6032811015610b2f576000828260328110610afc57610afc614c17565b60200201516001600160a01b031614610b1d57610b1b8382600161318f565b505b80610b2781614c43565b915050610adf565b506000600283018190556001830180546001600160a01b031916905560405185916001600160a01b038816917f638dfd3cbe18d0b1c928a88a5616cd3ec0087157f3b03103b3b7303e08f7aa939190a35050505050565b6000610b9181613185565b6001600160a01b0383166000818152600a6020908152604091829020805460ff191686151590811790915591519182527f97d1c8b407ac277efa62294660376a4b16914a38dae9a24fda0090eaf8550c3391015b60405180910390a2505050565b6000610bfd81613185565b66b1a2bc2ec50000821115610c2557604051635863f78960e01b815260040160405180910390fd5b60055460408051918252602082018490527f08549cc68fc086109ac325b32d9c1e3c9233af0244febf5af8164583359b2193910160405180910390a150600555565b6000610c7281613185565b6001600160a01b038216610c9957604051635863f78960e01b815260040160405180910390fd5b600754604080516001600160a01b03928316815291841660208301527f4ab5be82436d353e61ca18726e984e561f5c1cc7c6d38b29d2553c790434705a910160405180910390a150600780546001600160a01b0319166001600160a01b0392909216919091179055565b610d0b613613565b6000610d1681613185565b601254604051630e25940360e31b81526001600160a01b0384811660048301529091169063712ca01890602401602060405180830381865afa158015610d60573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d849190614c5c565b610da0576040516282b42960e81b815260040160405180910390fd5b6000826001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015610de0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e049190614c79565b6001600160a01b0381166000818152600d6020908152604080832054600b835281842054600c9093528184205491516370a0823160e01b815230600482015295965094929391929091906370a0823190602401602060405180830381865afa158015610e74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e989190614c96565b610ea29190614caf565b610eac9190614caf565b905081811015610eba578091505b6001600160a01b0383166000908152600d602052604081208054849290610ee2908490614caf565b90915550508115610f0757600754610f07906001600160a01b0385811691168461366c565b826001600160a01b03167f124fd12bda4dcb813885ca782fb4ea9350d4f752b1a881cadf8742d8f128bb8e83604051610f4291815260200190565b60405180910390a250505050610f5760018055565b50565b600082815260208190526040902060010154610f7581613185565b610f7f83836136cf565b505050565b610f8c613613565b610f9461376d565b601254604051630e25940360e31b81526001600160a01b0385811660048301529091169063712ca01890602401602060405180830381865afa158015610fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110029190614c5c565b61101f5760405163071cbeb560e21b815260040160405180910390fd5b6001600160a01b0383166000908152600a602052604090205460ff161561106557601560405163023ba7b360e51b815260040161105c9190614cdc565b60405180910390fd5b826001600160a01b031663a6afed956040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156110a057600080fd5b505af11580156110b4573d6000803e3d6000fd5b50506040516305b71aed60e51b815260048101859052600092506001600160a01b038616915063b6e35da090602401602060405180830381865afa158015611100573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111249190614c96565b90508060000361114a57601f60405163023ba7b360e51b815260040161105c9190614cdc565b6001600160a01b0384166000908152600860209081526040808320868452909152808220815161064081019283905290929182916111b591600386019060329082845b81546001600160a01b0316815260019091019060200180831161118d575050505050336137b5565b91509150816111da57602560405163023ba7b360e51b815260040161105c9190614cdc565b60008360350182603281106111f1576111f1614c17565b015490506000886001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015611235573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112599190614c79565b9050600061126882338a613816565b90506112748a8a61231c565b61127e8483614cf6565b10156112a057601860405163023ba7b360e51b815260040161105c9190614cdc565b6001600160a01b0382166000908152600b6020526040812080548392906112c8908490614cf6565b90915550506001600160a01b038a1660009081526008602090815260408083208c84529091529020611307908b336113008786614cf6565b6000613961565b88336001600160a01b03168b6001600160a01b03167f6ef5bbedd5dabb64b430d9153f4b7e8cde806efc15add4838e39a7fd5d7816a68460405161134d91815260200190565b60405180910390a450505050505050610f7f60018055565b6001600160a01b03811633146113d55760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161105c565b6113df8282613fd6565b5050565b6113eb613613565b6113f361376d565b601254604051630e25940360e31b81526001600160a01b0384811660048301529091169063712ca01890602401602060405180830381865afa15801561143d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114619190614c5c565b61147e5760405163071cbeb560e21b815260040160405180910390fd5b6001600160a01b0382166000908152600a602052604090205460ff16156114bb57601560405163023ba7b360e51b815260040161105c9190614cdc565b6000826001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061151f9190614c79565b9050600061152e823385613816565b9050611539846116b1565b81101561155c57601860405163023ba7b360e51b815260040161105c9190614cdc565b6001600160a01b0382166000908152600b602052604081208054839290611584908490614cf6565b90915550506001600160a01b03841660009081526009602052604090206115af908533846001613961565b60405181815233906001600160a01b038616907f0b0dda892a6a3a26deb0823b62fd279a37ac078d8f29f3ab19aa032a80e487869060200160405180910390a350506113df60018055565b6001600160a01b0381166000908152600960205260408082208151610640810190925282918291829182908190611663906003850160328282826020028201915b81546001600160a01b0316815260019091019060200180831161163b5750505050508a6137b5565b9150915081156116a05782603501816032811061168257611682614c17565b0154945082606701816032811061169b5761169b614c17565b015493505b5092945090925050505b9250929050565b6001600160a01b03811660009081526009602052604080822081516106408101928390529091839161171191839190603586019060329082845b8154815260200190600101908083116116eb57505050505061405590919063ffffffff16565b905060008160000361176e57670de0b6b3a7640000600354670de0b6b3a764000061173c9190614cf6565b84603501846032811061175157611751614c17565b015461175d9190614d0e565b6117679190614d2d565b9050611772565b5060015b949350505050565b611782614878565b6001600160a01b03828116600090815260096020908152604091829020825160c08101845281548516815260018201549094169184019190915260028101548383015281516106408101928390529091606084019190600384019060329082845b81546001600160a01b031681526001909101906020018083116117e35750505091835250506040805161064081019182905260209092019190603584019060329082845b8154815260200190600101908083116118275750505091835250506040805161064081019182905260209092019190606784019060329082845b815481526020019060010190808311611861575050505050815250509050919050565b600061188f81613185565b6706f05b59d3b200008211156118b857604051635863f78960e01b815260040160405180910390fd5b60045460408051918252602082018490527f238f2a5b71925c2db762a47738ba91939de19c8963dfb6120580366c53bb27ca910160405180910390a150600455565b7f369da55721ba2b3acddd63aac7d6512c3e5762a78fa01c44f423f97868330c3461192481613185565b6001600160a01b0382166000908152600960205260408082208151610640810192839052909291600384019060329082845b81546001600160a01b03168152600190910190602001808311611956575050505050905060005b60328110156119cd57600082826032811061199a5761199a614c17565b60200201516001600160a01b0316146119bb576119b98382600161318f565b505b806119c581614c43565b91505061197d565b506000600283018190556001830180546001600160a01b03191690556040516001600160a01b038616907f638dfd3cbe18d0b1c928a88a5616cd3ec0087157f3b03103b3b7303e08f7aa93908390a350505050565b6000611a2d81613185565b6202a300821180611a3f5750610e1082105b15611a5d57604051635863f78960e01b815260040160405180910390fd5b60065460408051918252602082018490527fa5bbda498262a74d84a3a338ed91b80807fed2b95a48de45473c6db26eba609d910160405180910390a150600655565b7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a611ac981613185565b8115611adc57611ad761411d565b611ae4565b611ae4614177565b60405182151581527f2d8cb32b79ced32c38fb4a61d8482c40627602feb2cc34b50d9b55eea376d88c9060200160405180910390a15050565b6000611b2881613185565b6001600160a01b038216611b4f57604051635863f78960e01b815260040160405180910390fd5b601254604080516001600160a01b03928316815291841660208301527f1c87e2bbc4e5fa5d7f6f8c44d66cb241dff224b8602eb5435ca2076d2a5c6fc2910160405180910390a150601280546001600160a01b0319166001600160a01b0392909216919091179055565b611bc1613613565b611bc961376d565b601254604051630e25940360e31b81526001600160a01b0384811660048301529091169063712ca01890602401602060405180830381865afa158015611c13573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c379190614c5c565b611c545760405163071cbeb560e21b815260040160405180910390fd5b6001600160a01b03828116600090815260086020908152604080832085845282528083208151610640810192839052600382018054909616815290948493611cb2936032916004890190850180831161118d575050505050336137b5565b9150915081611cd757600060405163023ba7b360e51b815260040161105c9190614cdc565b826067018160328110611cec57611cec614c17565b0154421015611d1157602460405163023ba7b360e51b815260040161105c9190614cdc565b611d1d8382600161318f565b50604051849033906001600160a01b038816907fea8a2bf7c4fb83cec4668a5ff2ca498dcf6ba1434e7776e767839a35912ad8ef90600090a45050506113df60018055565b6000611d6c613613565b6001600160a01b0382166000908152600e602090815260408083203384529091529020548015611df5576001600160a01b0383166000818152600e602090815260408083203384528252808320839055928252600c90529081208054839290611dd6908490614caf565b90915550611df090506001600160a01b038416338361366c565b611e11565b601c60405163023ba7b360e51b815260040161105c9190614cdc565b6040518181526001600160a01b0384169033907fd55b5fe81317b854ac11454adf7e5a9a0adf69184d643ef9ae6bfda6a015c5bc9060200160405180910390a39050611e5c60018055565b919050565b611e69613613565b611e7161376d565b601254604051630e25940360e31b81526001600160a01b0385811660048301529091169063712ca01890602401602060405180830381865afa158015611ebb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611edf9190614c5c565b611efc5760405163071cbeb560e21b815260040160405180910390fd5b6001600160a01b0383166000908152600a602052604090205460ff1615611f3957601560405163023ba7b360e51b815260040161105c9190614cdc565b826001600160a01b031663a6afed956040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611f7457600080fd5b505af1158015611f88573d6000803e3d6000fd5b50506040516305b71aed60e51b815260048101859052600092506001600160a01b038616915063b6e35da090602401602060405180830381865afa158015611fd4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ff89190614c96565b90508060000361201e57601f60405163023ba7b360e51b815260040161105c9190614cdc565b6000846001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa15801561205e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120829190614c79565b90506000612091823386613816565b905061209d868661231c565b8110156120c057601860405163023ba7b360e51b815260040161105c9190614cdc565b6001600160a01b0382166000908152600b6020526040812080548392906120e8908490614cf6565b90915550506001600160a01b0386166000908152600860209081526040808320888452909152902061211e908733846001613961565b84336001600160a01b0316876001600160a01b03167febad2c1937151932483543623cc17f75edc43440eab3d8363d47da8c9fa02bad8460405161216491815260200190565b60405180910390a4505050610f7f60018055565b612180613613565b6011546001600160a01b031633146121aa576040516282b42960e81b815260040160405180910390fd5b6121b58383836141b0565b610f7f60018055565b60006121c981613185565b60125460405163a9f70f1560e01b81526001600160a01b0384811660048301529091169063a9f70f1590602401602060405180830381865afa158015612213573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122379190614c5c565b15612254576040516282b42960e81b815260040160405180910390fd5b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa15801561229b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122bf9190614c96565b90508015610f7f576007546122e1906001600160a01b0385811691168361366c565b826001600160a01b03167fe501bb37b6bef3426625fab8c3a24d8b13c03875431d7da0ac09609ce80d1f4c82604051610be591815260200190565b6001600160a01b038216600090815260086020908152604080832084845282528083208151610640810192839052603582018054825291938593612383938593929091603291603689019085018083116116eb57505050505061405590919063ffffffff16565b9050600080670de0b6b3a7640000600454670de0b6b3a76400006123a79190614cf6565b6040516305b71aed60e51b8152600481018990526001600160a01b038a169063b6e35da090602401602060405180830381865afa1580156123ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124109190614c96565b61241a9190614d0e565b6124249190614d2d565b905082600003612493576000670de0b6b3a7640000600354670de0b6b3a764000061244f9190614cf6565b86603501866032811061246457612464614c17565b01546124709190614d0e565b61247a9190614d2d565b9050818111612489578161248b565b805b925050612497565b8091505b5095945050505050565b6000828152602081905260409020600101546124bc81613185565b610f7f8383613fd6565b6001600160a01b0382166000908152600860209081526040808320848452909152808220815161064081019092528291829182918290819061253a906003850160328282826020028201915b81546001600160a01b031681526001909101906020018083116125125750505050508b6137b5565b9150915081156125775782603501816032811061255957612559614c17565b0154945082606701816032811061257257612572614c17565b015493505b5092989197509095505050505050565b61258f613613565b61259761376d565b601254604051630e25940360e31b81526001600160a01b0384811660048301529091169063712ca01890602401602060405180830381865afa1580156125e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126059190614c5c565b6126225760405163071cbeb560e21b815260040160405180910390fd5b6001600160a01b0382166000908152600a602052604090205460ff161561265f57601560405163023ba7b360e51b815260040161105c9190614cdc565b6001600160a01b03828116600090815260096020908152604080832081516106408101928390526003820180549096168152909484936126b5936032916004890190850180831161118d575050505050336137b5565b91509150816126da57602560405163023ba7b360e51b815260040161105c9190614cdc565b60008360350182603281106126f1576126f1614c17565b015490506000866001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015612735573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127599190614c79565b90506000612768823389613816565b9050612773886116b1565b61277d8483614cf6565b101561279f57601860405163023ba7b360e51b815260040161105c9190614cdc565b6001600160a01b0382166000908152600b6020526040812080548392906127c7908490614cf6565b90915550506001600160a01b03881660009081526009602052604090206127f49089336113008786614cf6565b60405181815233906001600160a01b038a16907f6592adba96093b3116408ea64bca4c08eca1af760bd402796059abc6c25c55dd9060200160405180910390a35050505050506113df60018055565b61284b614878565b6001600160a01b038381166000908152600860209081526040808320868452825291829020825160c08101845281548516815260018201549094169184019190915260028101548383015281516106408101928390529091606084019190600384019060329082845b81546001600160a01b031681526001909101906020018083116128b45750505091835250506040805161064081019182905260209092019190603584019060329082845b8154815260200190600101908083116128f85750505091835250506040805161064081019182905260209092019190606784019060329082845b81548152602001906001019080831161293257505050505081525050905092915050565b61295e613613565b61296661376d565b601254604051630e25940360e31b81526001600160a01b0385811660048301529091169063712ca01890602401602060405180830381865afa1580156129b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129d49190614c5c565b6129f15760405163071cbeb560e21b815260040160405180910390fd5b6001600160a01b0383166000908152600a602052604090205460ff1615612a2e57601560405163023ba7b360e51b815260040161105c9190614cdc565b6000836001600160a01b031663b2016bd46040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a929190614c79565b90506000846001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ad4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612af89190614c79565b6001600160a01b038316600090815260106020908152604080832087845290915281205491925003612b4057602060405163023ba7b360e51b815260040161105c9190614cdc565b6001600160a01b0380861660008181526008602090815260408083208884528252808320938352600990915281206001830154929390928291829116151580612b95575060018401546001600160a01b031615155b15612bbb57836002015485600201541015612bb1576001612bb4565b60005b9050612bd7565b601960405163023ba7b360e51b815260040161105c9190614cdc565b6000816001811115612beb57612beb614cc6565b03612c5057600185015460028601546001600160a01b038881166000908152600b60205260408120805492909416965091945084929190612c2d908490614caf565b90915550612c4a905085612c4360016032614caf565b600061318f565b50612cbe565b6001816001811115612c6457612c64614cc6565b03612cbe57600184015460028501546001600160a01b038881166000908152600b60205260408120805492909416965091945084929190612ca6908490614caf565b90915550612cbc905084612c4360016032614caf565b505b896001600160a01b031663a6afed956040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612cf957600080fd5b505af1158015612d0d573d6000803e3d6000fd5b50506040516305b71aed60e51b8152600481018b9052600092506001600160a01b038d16915063b6e35da090602401602060405180830381865afa158015612d59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d7d9190614c96565b905082811115612da357601e60405163023ba7b360e51b815260040161105c9190614cdc565b6000670de0b6b3a76400006005548386612dbd9190614caf565b612dc79190614d0e565b612dd19190614d2d565b905080612dde8386614caf565b612de89190614caf565b6001600160a01b0389166000908152600d602052604081208054909190612e10908490614cf6565b90915550612e2290508c8b60006141b0565b612e998c838e6001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015612e65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e899190614c79565b6001600160a01b031691906142fe565b604051633208a6db60e21b81526001600160a01b038c81166004830152602482018c90528d169063c8229b6c90604401600060405180830381600087803b158015612ee357600080fd5b505af1158015612ef7573d6000803e3d6000fd5b505050506000811115612f1857612f186001600160a01b038916338361366c565b601154604051632142170760e11b81526001600160a01b0391821660048201528682166024820152604481018c9052908a16906342842e0e90606401600060405180830381600087803b158015612f6e57600080fd5b505af1158015612f82573d6000803e3d6000fd5b5050505089856001600160a01b03168d6001600160a01b03167fc9834d03b38dcd5e1442b3cd63c802144e7777ad415b6e941f51b79e8a1ce7168787604051612fcc929190614d4f565b60405180910390a4505050505050505050610f7f60018055565b612fee613613565b612ff661376d565b601254604051630e25940360e31b81526001600160a01b0383811660048301529091169063712ca01890602401602060405180830381865afa158015613040573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130649190614c5c565b6130815760405163071cbeb560e21b815260040160405180910390fd5b6001600160a01b03818116600090815260096020908152604080832081516106408101928390526003820180549096168152909484936130d7936032916004890190850180831161118d575050505050336137b5565b91509150816130fc57600060405163023ba7b360e51b815260040161105c9190614cdc565b82606701816032811061311157613111614c17565b015442101561313657602460405163023ba7b360e51b815260040161105c9190614cdc565b6131428382600161318f565b5060405133906001600160a01b038616907f8550bec1f643391291be443bdc85123e52e26ba487881aa33752c3be778733b490600090a3505050610f5760018055565b610f5781336143b6565b613197614878565b61319f6148d1565b6040805161064081019182905290603587019060329082845b8154815260200190600101908083116131b857505050505060208201526040805161064081019182905290600387019060329082845b81546001600160a01b031681526001909101906020018083116131ee5750505091835250506040805161064081019182905290606787019060329082845b81548152602001906001019080831161322c575050505050604082015284546001600160a01b031660e08201526032613266600182614caf565b85036132dd578151613279600283614caf565b6032811061328957613289614c17565b602090810291909101516001880180546001600160a01b0319166001600160a01b039092169190911790558201516132c2600283614caf565b603281106132d2576132d2614c17565b602002015160028701555b815160009086603281106132f3576132f3614c17565b6020020151905060008360200151876032811061331257613312614c17565b602002015190506001600160a01b0382161580159061332e5750855b1561342a5760e08401516001600160a01b039081166000908152600e602090815260408083209386168352929052908120805483929061336f908490614cf6565b909155505060e08401516001600160a01b03166000908152600c6020526040812080548392906133a0908490614cf6565b909155505060e08401516001600160a01b03166000908152600b6020526040812080548392906133d1908490614caf565b925050819055508360e001516001600160a01b0316826001600160a01b03167ff40cc8c1a1d17359049ba500cfc894596a692cffc9d03943cd92ec2e159cf6ae8360405161342191815260200190565b60405180910390a35b865b8015613509576020850151613442600183614caf565b6032811061345257613452614c17565b602002015189603501826032811061346c5761346c614c17565b0155845161347b600183614caf565b6032811061348b5761348b614c17565b60200201518960030182603281106134a5576134a5614c17565b0180546001600160a01b0319166001600160a01b039290921691909117905560408501516134d4600183614caf565b603281106134e4576134e4614c17565b60200201518960670182603281106134fe576134fe614c17565b01556000190161342c565b50600060358901556003880180546001600160a01b03191681556040805160c0810182528a546001600160a01b03908116825260018c015416602082015260028b015481830152815161064081019283905290928b926060850192919060329082845b81546001600160a01b0316815260019091019060200180831161356c5750505091835250506040805161064081019182905260209092019190603584019060329082845b8154815260200190600101908083116135b05750505091835250506040805161064081019182905260209092019190606784019060329082845b8154815260200190600101908083116135ea575050505050815250509450505050509392505050565b6002600154036136655760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161105c565b6002600155565b6040516001600160a01b038316602482015260448101829052610f7f90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614429565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166113df576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556137293390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60025460ff16156137b35760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161105c565b565b6000806032815b8181101561380857846001600160a01b03168682603281106137e0576137e0614c17565b60200201516001600160a01b031603613800576001935091506116aa9050565b6001016137bc565b506000958695509350505050565b6040516370a0823160e01b815230600482015260009081906001600160a01b038616906370a0823190602401602060405180830381865afa15801561385f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138839190614c96565b905061389a6001600160a01b0386168530866144fb565b6040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa1580156138e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139059190614c96565b9050818110156139585760405163c83ad1cd60e01b815260206004820152601860248201527f5472616e7366657220696e76617269616e74206572726f720000000000000000604482015260640161105c565b03949350505050565b6139696148d1565b6040805161064081019182905290603588019060329082845b81548152602001906001019080831161398257505050505060208201526040805161064081019182905290600388019060329082845b81546001600160a01b031681526001909101906020018083116139b85750505091835250506040805161064081019182905290606788019060329082845b8154815260200190600101908083116139f6575050505050604082015285546001600160a01b0390811660e0830152600187015460329116613b6857600187810180546001600160a01b0319166001600160a01b0388161790556002880185905584906035890190613a689084614caf565b60328110613a7857613a78614c17565b01558460038801613a8a600184614caf565b60328110613a9a57613a9a614c17565b0180546001600160a01b0319166001600160a01b0392909216919091179055600654613ac69042614cf6565b60678801613ad5600184614caf565b60328110613ae557613ae5614c17565b0181905550856001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015613b28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b4c9190614c79565b87546001600160a01b0319166001600160a01b03919091161787555b600080613b798460000151886137b5565b915091508115613c3d57613b8e89828761318f565b50604080516106408101918290529060358b019060329082845b815481526020019060010190808311613ba85750505050506020850152604080516106408101918290529060038b019060329082845b81546001600160a01b03168152600190910190602001808311613bde575050509186525050604080516106408101918290529060678b019060329082845b815481526020019060010190808311613c1c57505050505084604001819052505b6020840151600090613c4f9088614055565b9050868a600201541015613c825760018a0180546001600160a01b0319166001600160a01b038a1617905560028a018790555b8451516001600160a01b031660c086015260208501515160a08601526000613cab600183614caf565b1115613d9e5760005b613cbf600183614caf565b811015613d9c576020860151613cd6826001614cf6565b60328110613ce657613ce6614c17565b60200201518b6035018260328110613d0057613d00614c17565b01558551613d0f826001614cf6565b60328110613d1f57613d1f614c17565b60200201518b6003018260328110613d3957613d39614c17565b0180546001600160a01b0319166001600160a01b03929092169190911790556040860151613d68826001614cf6565b60328110613d7857613d78614c17565b60200201518b6067018260328110613d9257613d92614c17565b0155600101613cb4565b505b8660358b01613dae600184614caf565b60328110613dbe57613dbe614c17565b01558760038b01613dd0600184614caf565b60328110613de057613de0614c17565b0180546001600160a01b0319166001600160a01b0392909216919091179055600654613e0c9042614cf6565b60678b01613e1b600184614caf565b60328110613e2b57613e2b614c17565b0181905550886001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015613e6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e929190614c79565b8a546001600160a01b0319166001600160a01b0391909116178a5560a085015115613fca5760a085015160e08601516001600160a01b039081166000908152600e6020908152604080832060c08b015190941683529290529081208054909190613efd908490614cf6565b909155505060a085015160e08601516001600160a01b03166000908152600c602052604081208054909190613f33908490614cf6565b909155505060a085015160e08601516001600160a01b03166000908152600b602052604081208054909190613f69908490614caf565b925050819055508460e001516001600160a01b03168560c001516001600160a01b03167ff40cc8c1a1d17359049ba500cfc894596a692cffc9d03943cd92ec2e159cf6ae8760a00151604051613fc191815260200190565b60405180910390a35b50505050505050505050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16156113df576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60008060325b808210156140cd57600061406f8383614533565b90508486826032811061408457614084614c17565b60200201511180156140ac575060008682603281106140a5576140a5614c17565b6020020151115b156140b9578091506140c7565b6140c4816001614cf6565b92505b5061405b565b6000821180156140fc575083856140e5600185614caf565b603281106140f5576140f5614c17565b6020020151145b156141155761410c600183614caf565b92505050610a4b565b509050610a4b565b61412561376d565b6002805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861415a3390565b6040516001600160a01b03909116815260200160405180910390a1565b61417f614555565b6002805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa3361415a565b6000836001600160a01b031663b2016bd46040518163ffffffff1660e01b8152600401602060405180830381865afa1580156141f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142149190614c79565b9050811561426d576001600160a01b0381811660008181526010602090815260408083208884528252808320429055928252600f815282822087835290522080546001600160a01b0319169186169190911790556142b2565b6001600160a01b03811660008181526010602090815260408083208784528252808320839055928252600f815282822086835290522080546001600160a01b03191690555b82846001600160a01b03167f4c342743a6dd5dff0f08c88d6b7ce96bd95dd0699a77512a71865f7de385cb9b846040516142f0911515815260200190565b60405180910390a350505050565b604051636eb1769f60e11b81523060048201526001600160a01b038381166024830152600091839186169063dd62ed3e90604401602060405180830381865afa15801561434f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143739190614c96565b61437d9190614cf6565b6040516001600160a01b0385166024820152604481018290529091506143b090859063095ea7b360e01b90606401613698565b50505050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166113df576143e7816145a7565b6143f28360206145b9565b604051602001614403929190614d9f565b60408051601f198184030181529082905262461bcd60e51b825261105c91600401614e14565b600061447e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166147559092919063ffffffff16565b805190915015610f7f578080602001905181019061449c9190614c5c565b610f7f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161105c565b6040516001600160a01b03808516602483015283166044820152606481018290526143b09085906323b872dd60e01b90608401613698565b60006145426002848418614d2d565b61454e90848416614cf6565b9392505050565b60025460ff166137b35760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f7420706175736564000000000000000000000000604482015260640161105c565b6060610a4b6001600160a01b03831660145b606060006145c8836002614d0e565b6145d3906002614cf6565b67ffffffffffffffff8111156145eb576145eb614e47565b6040519080825280601f01601f191660200182016040528015614615576020820181803683370190505b509050600360fc1b8160008151811061463057614630614c17565b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061465f5761465f614c17565b60200101906001600160f81b031916908160001a9053506000614683846002614d0e565b61468e906001614cf6565b90505b6001811115614706576f181899199a1a9b1b9c1cb0b131b232b360811b85600f16601081106146c2576146c2614c17565b1a60f81b8282815181106146d8576146d8614c17565b60200101906001600160f81b031916908160001a90535060049490941c936146ff81614e5d565b9050614691565b50831561454e5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161105c565b6060611772848460008585600080866001600160a01b0316858760405161477c9190614e74565b60006040518083038185875af1925050503d80600081146147b9576040519150601f19603f3d011682016040523d82523d6000602084013e6147be565b606091505b50915091506147cf878383876147da565b979650505050505050565b60608315614849578251600003614842576001600160a01b0385163b6148425760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161105c565b5081611772565b611772838381511561485e5781518083602001fd5b8060405162461bcd60e51b815260040161105c9190614e14565b6040518060c0016040528060006001600160a01b0316815260200160006001600160a01b03168152602001600081526020016148b261493a565b81526020016148bf61493a565b81526020016148cc61493a565b905290565b6040518061010001604052806148e561493a565b81526020016148f261493a565b81526020016148ff61493a565b815260200160008152602001600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b031681525090565b6040518061064001604052806032906020820280368337509192915050565b60006020828403121561496b57600080fd5b5035919050565b60006020828403121561498457600080fd5b81356001600160e01b03198116811461454e57600080fd5b6001600160a01b0381168114610f5757600080fd5b600080604083850312156149c457600080fd5b82356149cf8161499c565b946020939093013593505050565b600080604083850312156149f057600080fd5b82356149fb8161499c565b91506020830135614a0b8161499c565b809150509250929050565b8015158114610f5757600080fd5b60008060408385031215614a3757600080fd5b8235614a428161499c565b91506020830135614a0b81614a16565b600060208284031215614a6457600080fd5b813561454e8161499c565b60008060408385031215614a8257600080fd5b823591506020830135614a0b8161499c565b600080600060608486031215614aa957600080fd5b8335614ab48161499c565b95602085013595506040909401359392505050565b8060005b60328110156143b0578151845260209384019390910190600101614acd565b6000611320820190506001600160a01b038084511683526020818186015116818501526040850151604085015260608501516060850160005b6032811015614b44578251851682529183019190830190600101614b25565b50505050506080830151614b5c6106a0840182614ac9565b5060a0830151614b70610ce0840182614ac9565b5092915050565b600060208284031215614b8957600080fd5b813561454e81614a16565b600080600060608486031215614ba957600080fd5b8335614bb48161499c565b9250602084013591506040840135614bcb81614a16565b809150509250925092565b600080600060608486031215614beb57600080fd5b8335614bf68161499c565b92506020840135614c068161499c565b929592945050506040919091013590565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201614c5557614c55614c2d565b5060010190565b600060208284031215614c6e57600080fd5b815161454e81614a16565b600060208284031215614c8b57600080fd5b815161454e8161499c565b600060208284031215614ca857600080fd5b5051919050565b600082821015614cc157614cc1614c2d565b500390565b634e487b7160e01b600052602160045260246000fd5b6020810160358310614cf057614cf0614cc6565b91905290565b60008219821115614d0957614d09614c2d565b500190565b6000816000190483118215151615614d2857614d28614c2d565b500290565b600082614d4a57634e487b7160e01b600052601260045260246000fd5b500490565b8281526040810160028310614d6657614d66614cc6565b8260208301529392505050565b60005b83811015614d8e578181015183820152602001614d76565b838111156143b05750506000910152565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614dd7816017850160208801614d73565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351614e08816028840160208801614d73565b01602801949350505050565b6020815260008251806020840152614e33816040850160208701614d73565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b600081614e6c57614e6c614c2d565b506000190190565b60008251614e86818460208701614d73565b919091019291505056fea26469706673582212207d1a501ca62b59baeafc15a9c171864b14c1f2b49fcd2fe3babde994313d14c264736f6c634300080f003300000000000000000000000007f8cefd165b9e4a84b60ce47f4c3784c2eb408a0000000000000000000000003318923722cd52c7c1752a62056532bef32877200000000000000000000000009a1edb903b058298dd0b06f52876d9d45358b7cb
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000007f8cefd165b9e4a84b60ce47f4c3784c2eb408a0000000000000000000000003318923722cd52c7c1752a62056532bef32877200000000000000000000000009a1edb903b058298dd0b06f52876d9d45358b7cb
-----Decoded View---------------
Arg [0] : _treasury (address): 0x07f8cefd165b9e4a84b60ce47f4c3784c2eb408a
Arg [1] : _liquidator (address): 0x3318923722cd52c7c1752a62056532bef3287720
Arg [2] : _controller (address): 0x9a1edb903b058298dd0b06f52876d9d45358b7cb
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 00000000000000000000000007f8cefd165b9e4a84b60ce47f4c3784c2eb408a
Arg [1] : 0000000000000000000000003318923722cd52c7c1752a62056532bef3287720
Arg [2] : 0000000000000000000000009a1edb903b058298dd0b06f52876d9d45358b7cb
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.