From c3fc86c9d80a44badd3f8c4d900b68e76bc9216c Mon Sep 17 00:00:00 2001 From: antazoey Date: Fri, 2 Feb 2024 16:20:24 -0600 Subject: [PATCH] feat: Allow adding dependencies from Etherscan (#114) --- README.md | 21 ++++++ ape_etherscan/__init__.py | 6 ++ ape_etherscan/client.py | 10 +-- ape_etherscan/dependency.py | 64 +++++++++++++++++ ape_etherscan/exceptions.py | 9 +++ ape_etherscan/explorer.py | 68 ++++++++++++++++--- ape_etherscan/types.py | 47 +++++++++++-- tests/conftest.py | 48 ++++++++++--- ...n => get_contract_response_flattened.json} | 2 +- .../get_contract_response_json.json | 1 + ...et_contract_response_json_source_code.json | 41 +++++++++++ .../get_contract_response_not_verified.json | 1 + tests/test_dependency.py | 45 ++++++++++++ tests/test_etherscan.py | 6 +- 14 files changed, 336 insertions(+), 33 deletions(-) create mode 100644 ape_etherscan/dependency.py rename tests/mock_responses/{get_contract_response.json => get_contract_response_flattened.json} (99%) create mode 100644 tests/mock_responses/get_contract_response_json.json create mode 100644 tests/mock_responses/get_contract_response_json_source_code.json create mode 100644 tests/mock_responses/get_contract_response_not_verified.json create mode 100644 tests/test_dependency.py diff --git a/README.md b/README.md index 8cb5dad..aad6f63 100644 --- a/README.md +++ b/README.md @@ -138,3 +138,24 @@ etherscan: uri: https://custom.scan api_uri: https://api.custom.scan/api ``` + +## Dependencies + +You can use dependencies from Etherscan in your projects. +Configure them like this: + +```yaml +dependencies: + - name: Spork + etherscan: "0xb624FdE1a972B1C89eC1dAD691442d5E8E891469" + ecosystem: ethereum + network: mainnet +``` + +Then, access contract types from the dependency in your code: + +```python +from ape import project + +spork_contract_type = project.dependencies["Spork"]["etherscan"].Spork +``` diff --git a/ape_etherscan/__init__.py b/ape_etherscan/__init__.py index fa4f53a..6d9a34c 100644 --- a/ape_etherscan/__init__.py +++ b/ape_etherscan/__init__.py @@ -1,6 +1,7 @@ from ape import plugins from .config import EtherscanConfig +from .dependency import EtherscanDependency from .explorer import Etherscan from .query import EtherscanQueryEngine from .utils import NETWORKS @@ -22,3 +23,8 @@ def query_engines(): @plugins.register(plugins.Config) def config_class(): return EtherscanConfig + + +@plugins.register(plugins.DependencyPlugin) +def dependencies(): + yield "etherscan", EtherscanDependency diff --git a/ape_etherscan/client.py b/ape_etherscan/client.py index 6d2729a..4865787 100644 --- a/ape_etherscan/client.py +++ b/ape_etherscan/client.py @@ -13,6 +13,7 @@ from ape_etherscan.config import EtherscanConfig from ape_etherscan.exceptions import ( + ContractNotVerifiedError, UnhandledResultError, UnsupportedEcosystemError, UnsupportedNetworkError, @@ -302,7 +303,7 @@ def get_source_code(self) -> SourceCodeResponse: } result = self._get(params=params) - if not (result_list := result.value or []): + if not (result_list := result.value): return SourceCodeResponse() elif len(result_list) > 1: @@ -312,9 +313,10 @@ def get_source_code(self) -> SourceCodeResponse: if not isinstance(data, dict): raise UnhandledResultError(result, data) - abi = data.get("ABI") or "" - name = data.get("ContractName") or "unknown" - return SourceCodeResponse(abi, name) + if data.get("ABI") == "Contract source code not verified": + raise ContractNotVerifiedError(result, self._address) + + return SourceCodeResponse.model_validate(data) def verify_source_code( self, diff --git a/ape_etherscan/dependency.py b/ape_etherscan/dependency.py new file mode 100644 index 0000000..ed62f6e --- /dev/null +++ b/ape_etherscan/dependency.py @@ -0,0 +1,64 @@ +from ape.api.projects import DependencyAPI +from ape.exceptions import ProjectError +from ape.types import AddressType +from ethpm_types import PackageManifest +from hexbytes import HexBytes +from pydantic import AnyUrl, HttpUrl, field_validator + +from .explorer import Etherscan + + +class EtherscanDependency(DependencyAPI): + etherscan: str + ecosystem: str = "ethereum" + network: str = "mainnet" + + @field_validator("etherscan", mode="before") + @classmethod + def handle_int(cls, value): + return value if isinstance(value, str) else HexBytes(value).hex() + + @property + def version_id(self) -> str: + return f"{self.ecosystem}_{self.network}" + + @property + def address(self) -> AddressType: + return self.network_manager.ethereum.decode_address(self.etherscan) + + @property + def uri(self) -> AnyUrl: + return HttpUrl(f"{self.explorer.get_address_url(self.address)}#code") + + @property + def explorer(self) -> Etherscan: + if self.network_manager.active_provider: + explorer = self.provider.network.explorer + if isinstance(explorer, Etherscan): + # Could be using a different network. + return explorer + else: + return self.network_manager.ethereum.mainnet.explorer + + # Assume Ethereum + return self.network_manager.ethereum.mainnet.explorer + + def extract_manifest(self, use_cache: bool = True) -> PackageManifest: + ecosystem = self.network_manager.get_ecosystem(self.ecosystem) + network = ecosystem.get_network(self.network) + + ctx = None + if self.network_manager.active_provider is None: + ctx = network.use_default_provider() + ctx.__enter__() + + try: + manifest = self.explorer.get_manifest(self.address) + finally: + if ctx: + ctx.__exit__(None) + + if not manifest: + raise ProjectError(f"Etherscan dependency '{self.name}' not verified.") + + return manifest diff --git a/ape_etherscan/exceptions.py b/ape_etherscan/exceptions.py index 2e66762..2bef402 100644 --- a/ape_etherscan/exceptions.py +++ b/ape_etherscan/exceptions.py @@ -47,6 +47,15 @@ def __init__(self, response: Union[Response, "EtherscanResponse"], message: str) super().__init__(f"Response indicated failure: {message}") +class ContractNotVerifiedError(EtherscanResponseError): + """ + Raised when a contract is not verified on Etherscan. + """ + + def __init__(self, response: Union[Response, "EtherscanResponse"], address: str): + super().__init__(response, f"Contract '{address}' not verified.") + + class UnhandledResultError(EtherscanResponseError): """ Raised in specific client module where the result from Etherscan diff --git a/ape_etherscan/explorer.py b/ape_etherscan/explorer.py index ab442ea..4ff1eb9 100644 --- a/ape_etherscan/explorer.py +++ b/ape_etherscan/explorer.py @@ -1,14 +1,20 @@ import json -from json.decoder import JSONDecodeError from typing import Optional from ape.api import ExplorerAPI, PluginConfig from ape.contracts import ContractInstance from ape.exceptions import ProviderNotConnectedError -from ape.logging import logger from ape.types import AddressType, ContractType +from ethpm_types import Compiler, PackageManifest +from ethpm_types.source import Source -from ape_etherscan.client import ClientFactory, get_etherscan_api_uri, get_etherscan_uri +from ape_etherscan.client import ( + ClientFactory, + SourceCodeResponse, + get_etherscan_api_uri, + get_etherscan_uri, +) +from ape_etherscan.exceptions import ContractNotVerifiedError from ape_etherscan.types import EtherscanInstance from ape_etherscan.verify import SourceVerifier @@ -47,23 +53,63 @@ def _client_factory(self) -> ClientFactory: ) ) - def get_contract_type(self, address: AddressType) -> Optional[ContractType]: + def get_manifest(self, address: AddressType) -> Optional[PackageManifest]: + try: + response = self._get_source_code(address) + except ContractNotVerifiedError: + return None + + settings = { + "optimizer": { + "enabled": response.optimization_used, + "runs": response.optimization_runs, + }, + } + + code = response.source_code + if code.startswith("{"): + # JSON verified. + data = json.loads(code) + compiler = Compiler( + name=data.get("language", "Solidity"), + version=response.compiler_version, + settings=data.get("settings", settings), + contractTypes=[response.name], + ) + source_data = data.get("sources", {}) + sources = { + src_id: Source(content=cont.get("content", "")) + for src_id, cont in source_data.items() + } + + else: + # A flattened source. + source_id = f"{response.name}.sol" + compiler = Compiler( + name="Solidity", + version=response.compiler_version, + settings=settings, + contractTypes=[response.name], + ) + sources = {source_id: Source(content=response.source_code)} + + return PackageManifest(compilers=[compiler], sources=sources) + + def _get_source_code(self, address: AddressType) -> SourceCodeResponse: if not self.conversion_manager.is_type(address, AddressType): # Handle non-checksummed addresses address = self.conversion_manager.convert(str(address), AddressType) client = self._client_factory.get_contract_client(address) - source_code = client.get_source_code() - if not (abi_string := source_code.abi): - return None + return client.get_source_code() + def get_contract_type(self, address: AddressType) -> Optional[ContractType]: try: - abi = json.loads(abi_string) - except JSONDecodeError as err: - logger.error(f"Error with contract ABI: {err}") + source_code = self._get_source_code(address) + except ContractNotVerifiedError: return None - contract_type = ContractType(abi=abi, contractName=source_code.name) + contract_type = ContractType(abi=source_code.abi, contractName=source_code.name) if source_code.name == "Vyper_contract" and "symbol" in contract_type.view_methods: try: contract = ContractInstance(address, contract_type) diff --git a/ape_etherscan/types.py b/ape_etherscan/types.py index ee8aef1..deb06ad 100644 --- a/ape_etherscan/types.py +++ b/ape_etherscan/types.py @@ -1,8 +1,11 @@ import json +import re from dataclasses import dataclass from typing import Dict, List, Union from ape.utils import cached_property +from ethpm_types import BaseModel +from pydantic import Field, field_validator from ape_etherscan.exceptions import EtherscanResponseError, get_request_error @@ -17,10 +20,44 @@ class EtherscanInstance: api_uri: str -@dataclass -class SourceCodeResponse: - abi: str = "" - name: str = "unknown" +class SourceCodeResponse(BaseModel): + abi: List = Field([], alias="ABI") + name: str = Field("unknown", alias="ContractName") + source_code: str = Field("", alias="SourceCode") + compiler_version: str = Field("", alias="CompilerVersion") + optimization_used: bool = Field(True, alias="OptimizationUsed") + optimization_runs: int = Field(200, alias="Runs") + evm_version: str = Field("Default", alias="EVMVersion") + library: str = Field("", alias="Library") + license_type: str = Field("", alias="LicenseType") + proxy: bool = Field(False, alias="Proxy") + implementation: str = Field("", alias="Implementation") + swarm_source: str = Field("", alias="SwarmSource") + + @field_validator("optimization_used", "proxy", mode="before") + @classmethod + def validate_bools(cls, value): + return bool(int(value)) + + @field_validator("abi", mode="before") + @classmethod + def validate_abi(cls, value): + return json.loads(value) + + @field_validator("source_code", mode="before") + @classmethod + def validate_source_code(cls, value): + if value.startswith("{"): + # NOTE: Have to deal with very poor JSON + # response from Etherscan. + fixed = re.sub(r"\r\n\s*", "", value) + fixed = re.sub(r"\r\n\s*", "", fixed) + if fixed.startswith("{{"): + fixed = fixed[1:-1] + + return fixed + + return value @dataclass @@ -49,7 +86,7 @@ def value(self) -> ResponseValue: message = response_data.get("message", "") is_error = response_data.get("isError", 0) or message == "NOTOK" - if is_error and self.raise_on_exceptions: + if is_error is True and self.raise_on_exceptions: raise get_request_error(self.response, self.ecosystem) result = response_data.get("result", message) diff --git a/tests/conftest.py b/tests/conftest.py index f9c14aa..f98fe8b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -152,7 +152,9 @@ def address(contract_to_verify): @pytest.fixture(scope="session") def contract_address_map(address): return { - "get_contract_response": address, + "get_contract_response_flattened": address, + "get_contract_response_json": "0x000075Dc60EdE898f11b0d5C6cA31D7A6D050eeD", + "get_contract_response_not_verified": "0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168", "get_proxy_contract_response": "0x55A8a39bc9694714E2874c1ce77aa1E599461E18", "get_vyper_contract_response": "0xdA816459F1AB5631232FE5e97a05BBBb94970c95", } @@ -419,8 +421,20 @@ def side_effect(self): def _get_contract_type_response(self, file_name: str) -> Any: test_data_path = MOCK_RESPONSES_PATH / f"{file_name}.json" - with open(test_data_path) as response_data_file: - return self.get_mock_response(response_data_file, file_name=file_name) + assert test_data_path.is_file(), f"Setup failed - missing test data {file_name}" + if "flattened" in file_name: + with open(test_data_path) as response_data_file: + return self.get_mock_response(response_data_file, file_name=file_name) + + else: + # NOTE: Since the JSON is messed up for these, we can' load the mocks + # even without a weird hack. + content = ( + MOCK_RESPONSES_PATH / "get_contract_response_json_source_code.json" + ).read_text() + data = json.loads(test_data_path.read_text()) + data["SourceCode"] = content + return self.get_mock_response(data, file_name=file_name) def _expected_get_ct_params(self, address: str) -> Dict: return {"module": "contract", "action": "getsourcecode", "address": address} @@ -462,23 +476,37 @@ def get_mock_response( self, response_data: Optional[Union[IO, Dict, str, MagicMock]] = None, **kwargs ): if isinstance(response_data, str): - return self.get_mock_response({"result": response_data}) + return self.get_mock_response({"result": response_data, **kwargs}) elif isinstance(response_data, _io.TextIOWrapper): return self.get_mock_response(json.load(response_data), **kwargs) elif isinstance(response_data, MagicMock): # Mock wasn't set. - response_data = {} + response_data = {**kwargs} + + assert isinstance(response_data, dict) + return self._get_mock_response(response_data=response_data, **kwargs) + def _get_mock_response( + self, + response_data: Optional[Dict] = None, + response_text: Optional[str] = None, + *args, + **kwargs, + ): response = self.mocker.MagicMock(spec=Response) - assert isinstance(response_data, dict) # For mypy - overrides: Dict = kwargs.get("response_overrides", {}) - response.json.return_value = {**response_data, **overrides} - response.text = json.dumps(response_data or {}) + if response_data: + assert isinstance(response_data, dict) # For mypy + overrides: Dict = kwargs.get("response_overrides", {}) + response.json.return_value = {**response_data, **overrides} + if not response_text: + response_text = json.dumps(response_data or {}) - response.status_code = 200 + if response_text: + response.text = response_text + response.status_code = 200 for key, val in kwargs.items(): setattr(response, key, val) diff --git a/tests/mock_responses/get_contract_response.json b/tests/mock_responses/get_contract_response_flattened.json similarity index 99% rename from tests/mock_responses/get_contract_response.json rename to tests/mock_responses/get_contract_response_flattened.json index 7786985..7b275a4 100644 --- a/tests/mock_responses/get_contract_response.json +++ b/tests/mock_responses/get_contract_response_flattened.json @@ -1 +1 @@ -{"status":"1","message":"OK-Missing/Invalid API Key, rate limit of 1/5sec applied","result":[{"SourceCode":"// File: @openzeppelin/contracts/utils/Context.sol\r\n\r\n// SPDX-License-Identifier: MIT\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/*\r\n * @dev Provides information about the current execution context, including the\r\n * sender of the transaction and its data. While these are generally available\r\n * via msg.sender and msg.data, they should not be accessed in such a direct\r\n * manner, since when dealing with GSN meta-transactions the account sending and\r\n * paying for execution may not be the actual sender (as far as an application\r\n * is concerned).\r\n *\r\n * This contract is only required for intermediate, library-like contracts.\r\n */\r\nabstract contract Context {\r\n function _msgSender() internal view virtual returns (address payable) {\r\n return msg.sender;\r\n }\r\n\r\n function _msgData() internal view virtual returns (bytes memory) {\r\n this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\r\n return msg.data;\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/introspection/IERC165.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Interface of the ERC165 standard, as defined in the\r\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\r\n *\r\n * Implementers can declare support of contract interfaces, which can then be\r\n * queried by others ({ERC165Checker}).\r\n *\r\n * For an implementation, see {ERC165}.\r\n */\r\ninterface IERC165 {\r\n /**\r\n * @dev Returns true if this contract implements the interface defined by\r\n * `interfaceId`. See the corresponding\r\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\r\n * to learn more about how these ids are created.\r\n *\r\n * This function call must use less than 30 000 gas.\r\n */\r\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\r\n}\r\n\r\n// File: @openzeppelin/contracts/token/ERC721/IERC721.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.2 <0.8.0;\r\n\r\n\r\n/**\r\n * @dev Required interface of an ERC721 compliant contract.\r\n */\r\ninterface IERC721 is IERC165 {\r\n /**\r\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\r\n */\r\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\r\n\r\n /**\r\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\r\n */\r\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\r\n\r\n /**\r\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\r\n */\r\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\r\n\r\n /**\r\n * @dev Returns the number of tokens in ``owner``'s account.\r\n */\r\n function balanceOf(address owner) external view returns (uint256 balance);\r\n\r\n /**\r\n * @dev Returns the owner of the `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function ownerOf(uint256 tokenId) external view returns (address owner);\r\n\r\n /**\r\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\r\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must exist and be owned by `from`.\r\n * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.\r\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function safeTransferFrom(address from, address to, uint256 tokenId) external;\r\n\r\n /**\r\n * @dev Transfers `tokenId` token from `from` to `to`.\r\n *\r\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must be owned by `from`.\r\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transferFrom(address from, address to, uint256 tokenId) external;\r\n\r\n /**\r\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\r\n * The approval is cleared when the token is transferred.\r\n *\r\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\r\n *\r\n * Requirements:\r\n *\r\n * - The caller must own the token or be an approved operator.\r\n * - `tokenId` must exist.\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function approve(address to, uint256 tokenId) external;\r\n\r\n /**\r\n * @dev Returns the account approved for `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function getApproved(uint256 tokenId) external view returns (address operator);\r\n\r\n /**\r\n * @dev Approve or remove `operator` as an operator for the caller.\r\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\r\n *\r\n * Requirements:\r\n *\r\n * - The `operator` cannot be the caller.\r\n *\r\n * Emits an {ApprovalForAll} event.\r\n */\r\n function setApprovalForAll(address operator, bool _approved) external;\r\n\r\n /**\r\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\r\n *\r\n * See {setApprovalForAll}\r\n */\r\n function isApprovedForAll(address owner, address operator) external view returns (bool);\r\n\r\n /**\r\n * @dev Safely transfers `tokenId` token from `from` to `to`.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must exist and be owned by `from`.\r\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\r\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\r\n}\r\n\r\n// File: @openzeppelin/contracts/token/ERC721/IERC721Metadata.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.2 <0.8.0;\r\n\r\n\r\n/**\r\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\r\n * @dev See https://eips.ethereum.org/EIPS/eip-721\r\n */\r\ninterface IERC721Metadata is IERC721 {\r\n\r\n /**\r\n * @dev Returns the token collection name.\r\n */\r\n function name() external view returns (string memory);\r\n\r\n /**\r\n * @dev Returns the token collection symbol.\r\n */\r\n function symbol() external view returns (string memory);\r\n\r\n /**\r\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\r\n */\r\n function tokenURI(uint256 tokenId) external view returns (string memory);\r\n}\r\n\r\n// File: @openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.2 <0.8.0;\r\n\r\n\r\n/**\r\n * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension\r\n * @dev See https://eips.ethereum.org/EIPS/eip-721\r\n */\r\ninterface IERC721Enumerable is IERC721 {\r\n\r\n /**\r\n * @dev Returns the total amount of tokens stored by the contract.\r\n */\r\n function totalSupply() external view returns (uint256);\r\n\r\n /**\r\n * @dev Returns a token ID owned by `owner` at a given `index` of its token list.\r\n * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.\r\n */\r\n function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);\r\n\r\n /**\r\n * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.\r\n * Use along with {totalSupply} to enumerate all tokens.\r\n */\r\n function tokenByIndex(uint256 index) external view returns (uint256);\r\n}\r\n\r\n// File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @title ERC721 token receiver interface\r\n * @dev Interface for any contract that wants to support safeTransfers\r\n * from ERC721 asset contracts.\r\n */\r\ninterface IERC721Receiver {\r\n /**\r\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\r\n * by `operator` from `from`, this function is called.\r\n *\r\n * It must return its Solidity selector to confirm the token transfer.\r\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\r\n *\r\n * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.\r\n */\r\n function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);\r\n}\r\n\r\n// File: @openzeppelin/contracts/introspection/ERC165.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n\r\n/**\r\n * @dev Implementation of the {IERC165} interface.\r\n *\r\n * Contracts may inherit from this and call {_registerInterface} to declare\r\n * their support of an interface.\r\n */\r\nabstract contract ERC165 is IERC165 {\r\n /*\r\n * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7\r\n */\r\n bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;\r\n\r\n /**\r\n * @dev Mapping of interface ids to whether or not it's supported.\r\n */\r\n mapping(bytes4 => bool) private _supportedInterfaces;\r\n\r\n constructor () internal {\r\n // Derived contracts need only register support for their own interfaces,\r\n // we register support for ERC165 itself here\r\n _registerInterface(_INTERFACE_ID_ERC165);\r\n }\r\n\r\n /**\r\n * @dev See {IERC165-supportsInterface}.\r\n *\r\n * Time complexity O(1), guaranteed to always use less than 30 000 gas.\r\n */\r\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\r\n return _supportedInterfaces[interfaceId];\r\n }\r\n\r\n /**\r\n * @dev Registers the contract as an implementer of the interface defined by\r\n * `interfaceId`. Support of the actual ERC165 interface is automatic and\r\n * registering its interface id is not required.\r\n *\r\n * See {IERC165-supportsInterface}.\r\n *\r\n * Requirements:\r\n *\r\n * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).\r\n */\r\n function _registerInterface(bytes4 interfaceId) internal virtual {\r\n require(interfaceId != 0xffffffff, \"ERC165: invalid interface id\");\r\n _supportedInterfaces[interfaceId] = true;\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/math/SafeMath.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\r\n * checks.\r\n *\r\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\r\n * in bugs, because programmers usually assume that an overflow raises an\r\n * error, which is the standard behavior in high level programming languages.\r\n * `SafeMath` restores this intuition by reverting the transaction when an\r\n * operation overflows.\r\n *\r\n * Using this library instead of the unchecked operations eliminates an entire\r\n * class of bugs, so it's recommended to use it always.\r\n */\r\nlibrary SafeMath {\r\n /**\r\n * @dev Returns the addition of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n uint256 c = a + b;\r\n if (c < a) return (false, 0);\r\n return (true, c);\r\n }\r\n\r\n /**\r\n * @dev Returns the substraction of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n if (b > a) return (false, 0);\r\n return (true, a - b);\r\n }\r\n\r\n /**\r\n * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\r\n // benefit is lost if 'b' is also tested.\r\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\r\n if (a == 0) return (true, 0);\r\n uint256 c = a * b;\r\n if (c / a != b) return (false, 0);\r\n return (true, c);\r\n }\r\n\r\n /**\r\n * @dev Returns the division of two unsigned integers, with a division by zero flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n if (b == 0) return (false, 0);\r\n return (true, a / b);\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n if (b == 0) return (false, 0);\r\n return (true, a % b);\r\n }\r\n\r\n /**\r\n * @dev Returns the addition of two unsigned integers, reverting on\r\n * overflow.\r\n *\r\n * Counterpart to Solidity's `+` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Addition cannot overflow.\r\n */\r\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\r\n uint256 c = a + b;\r\n require(c >= a, \"SafeMath: addition overflow\");\r\n return c;\r\n }\r\n\r\n /**\r\n * @dev Returns the subtraction of two unsigned integers, reverting on\r\n * overflow (when the result is negative).\r\n *\r\n * Counterpart to Solidity's `-` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Subtraction cannot overflow.\r\n */\r\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\r\n require(b <= a, \"SafeMath: subtraction overflow\");\r\n return a - b;\r\n }\r\n\r\n /**\r\n * @dev Returns the multiplication of two unsigned integers, reverting on\r\n * overflow.\r\n *\r\n * Counterpart to Solidity's `*` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Multiplication cannot overflow.\r\n */\r\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\r\n if (a == 0) return 0;\r\n uint256 c = a * b;\r\n require(c / a == b, \"SafeMath: multiplication overflow\");\r\n return c;\r\n }\r\n\r\n /**\r\n * @dev Returns the integer division of two unsigned integers, reverting on\r\n * division by zero. The result is rounded towards zero.\r\n *\r\n * Counterpart to Solidity's `/` operator. Note: this function uses a\r\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n * uses an invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\r\n require(b > 0, \"SafeMath: division by zero\");\r\n return a / b;\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n * reverting when dividing by zero.\r\n *\r\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\r\n * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n * invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\r\n require(b > 0, \"SafeMath: modulo by zero\");\r\n return a % b;\r\n }\r\n\r\n /**\r\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\r\n * overflow (when the result is negative).\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {trySub}.\r\n *\r\n * Counterpart to Solidity's `-` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Subtraction cannot overflow.\r\n */\r\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b <= a, errorMessage);\r\n return a - b;\r\n }\r\n\r\n /**\r\n * @dev Returns the integer division of two unsigned integers, reverting with custom message on\r\n * division by zero. The result is rounded towards zero.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {tryDiv}.\r\n *\r\n * Counterpart to Solidity's `/` operator. Note: this function uses a\r\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n * uses an invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b > 0, errorMessage);\r\n return a / b;\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n * reverting with custom message when dividing by zero.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {tryMod}.\r\n *\r\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\r\n * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n * invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b > 0, errorMessage);\r\n return a % b;\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/utils/Address.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.2 <0.8.0;\r\n\r\n/**\r\n * @dev Collection of functions related to the address type\r\n */\r\nlibrary Address {\r\n /**\r\n * @dev Returns true if `account` is a contract.\r\n *\r\n * [IMPORTANT]\r\n * ====\r\n * It is unsafe to assume that an address for which this function returns\r\n * false is an externally-owned account (EOA) and not a contract.\r\n *\r\n * Among others, `isContract` will return false for the following\r\n * types of addresses:\r\n *\r\n * - an externally-owned account\r\n * - a contract in construction\r\n * - an address where a contract will be created\r\n * - an address where a contract lived, but was destroyed\r\n * ====\r\n */\r\n function isContract(address account) internal view returns (bool) {\r\n // This method relies on extcodesize, which returns 0 for contracts in\r\n // construction, since the code is only stored at the end of the\r\n // constructor execution.\r\n\r\n uint256 size;\r\n // solhint-disable-next-line no-inline-assembly\r\n assembly { size := extcodesize(account) }\r\n return size > 0;\r\n }\r\n\r\n /**\r\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\r\n * `recipient`, forwarding all available gas and reverting on errors.\r\n *\r\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\r\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\r\n * imposed by `transfer`, making them unable to receive funds via\r\n * `transfer`. {sendValue} removes this limitation.\r\n *\r\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\r\n *\r\n * IMPORTANT: because control is transferred to `recipient`, care must be\r\n * taken to not create reentrancy vulnerabilities. Consider using\r\n * {ReentrancyGuard} or the\r\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\r\n */\r\n function sendValue(address payable recipient, uint256 amount) internal {\r\n require(address(this).balance >= amount, \"Address: insufficient balance\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\r\n (bool success, ) = recipient.call{ value: amount }(\"\");\r\n require(success, \"Address: unable to send value, recipient may have reverted\");\r\n }\r\n\r\n /**\r\n * @dev Performs a Solidity function call using a low level `call`. A\r\n * plain`call` is an unsafe replacement for a function call: use this\r\n * function instead.\r\n *\r\n * If `target` reverts with a revert reason, it is bubbled up by this\r\n * function (like regular Solidity function calls).\r\n *\r\n * Returns the raw returned data. To convert to the expected return value,\r\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\r\n *\r\n * Requirements:\r\n *\r\n * - `target` must be a contract.\r\n * - calling `target` with `data` must not revert.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\r\n return functionCall(target, data, \"Address: low-level call failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\r\n * `errorMessage` as a fallback revert reason when `target` reverts.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\r\n return functionCallWithValue(target, data, 0, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but also transferring `value` wei to `target`.\r\n *\r\n * Requirements:\r\n *\r\n * - the calling contract must have an ETH balance of at least `value`.\r\n * - the called Solidity function must be `payable`.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\r\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\r\n * with `errorMessage` as a fallback revert reason when `target` reverts.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\r\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\r\n require(isContract(target), \"Address: call to non-contract\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls\r\n (bool success, bytes memory returndata) = target.call{ value: value }(data);\r\n return _verifyCallResult(success, returndata, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but performing a static call.\r\n *\r\n * _Available since v3.3._\r\n */\r\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\r\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r\n * but performing a static call.\r\n *\r\n * _Available since v3.3._\r\n */\r\n function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {\r\n require(isContract(target), \"Address: static call to non-contract\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls\r\n (bool success, bytes memory returndata) = target.staticcall(data);\r\n return _verifyCallResult(success, returndata, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but performing a delegate call.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\r\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r\n * but performing a delegate call.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\r\n require(isContract(target), \"Address: delegate call to non-contract\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls\r\n (bool success, bytes memory returndata) = target.delegatecall(data);\r\n return _verifyCallResult(success, returndata, errorMessage);\r\n }\r\n\r\n function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {\r\n if (success) {\r\n return returndata;\r\n } else {\r\n // Look for revert reason and bubble it up if present\r\n if (returndata.length > 0) {\r\n // The easiest way to bubble the revert reason is using memory via assembly\r\n\r\n // solhint-disable-next-line no-inline-assembly\r\n assembly {\r\n let returndata_size := mload(returndata)\r\n revert(add(32, returndata), returndata_size)\r\n }\r\n } else {\r\n revert(errorMessage);\r\n }\r\n }\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/utils/EnumerableSet.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Library for managing\r\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\r\n * types.\r\n *\r\n * Sets have the following properties:\r\n *\r\n * - Elements are added, removed, and checked for existence in constant time\r\n * (O(1)).\r\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\r\n *\r\n * ```\r\n * contract Example {\r\n * // Add the library methods\r\n * using EnumerableSet for EnumerableSet.AddressSet;\r\n *\r\n * // Declare a set state variable\r\n * EnumerableSet.AddressSet private mySet;\r\n * }\r\n * ```\r\n *\r\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\r\n * and `uint256` (`UintSet`) are supported.\r\n */\r\nlibrary EnumerableSet {\r\n // To implement this library for multiple types with as little code\r\n // repetition as possible, we write it in terms of a generic Set type with\r\n // bytes32 values.\r\n // The Set implementation uses private functions, and user-facing\r\n // implementations (such as AddressSet) are just wrappers around the\r\n // underlying Set.\r\n // This means that we can only create new EnumerableSets for types that fit\r\n // in bytes32.\r\n\r\n struct Set {\r\n // Storage of set values\r\n bytes32[] _values;\r\n\r\n // Position of the value in the `values` array, plus 1 because index 0\r\n // means a value is not in the set.\r\n mapping (bytes32 => uint256) _indexes;\r\n }\r\n\r\n /**\r\n * @dev Add a value to a set. O(1).\r\n *\r\n * Returns true if the value was added to the set, that is if it was not\r\n * already present.\r\n */\r\n function _add(Set storage set, bytes32 value) private returns (bool) {\r\n if (!_contains(set, value)) {\r\n set._values.push(value);\r\n // The value is stored at length-1, but we add 1 to all indexes\r\n // and use 0 as a sentinel value\r\n set._indexes[value] = set._values.length;\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * @dev Removes a value from a set. O(1).\r\n *\r\n * Returns true if the value was removed from the set, that is if it was\r\n * present.\r\n */\r\n function _remove(Set storage set, bytes32 value) private returns (bool) {\r\n // We read and store the value's index to prevent multiple reads from the same storage slot\r\n uint256 valueIndex = set._indexes[value];\r\n\r\n if (valueIndex != 0) { // Equivalent to contains(set, value)\r\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\r\n // the array, and then remove the last element (sometimes called as 'swap and pop').\r\n // This modifies the order of the array, as noted in {at}.\r\n\r\n uint256 toDeleteIndex = valueIndex - 1;\r\n uint256 lastIndex = set._values.length - 1;\r\n\r\n // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs\r\n // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.\r\n\r\n bytes32 lastvalue = set._values[lastIndex];\r\n\r\n // Move the last value to the index where the value to delete is\r\n set._values[toDeleteIndex] = lastvalue;\r\n // Update the index for the moved value\r\n set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based\r\n\r\n // Delete the slot where the moved value was stored\r\n set._values.pop();\r\n\r\n // Delete the index for the deleted slot\r\n delete set._indexes[value];\r\n\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns true if the value is in the set. O(1).\r\n */\r\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\r\n return set._indexes[value] != 0;\r\n }\r\n\r\n /**\r\n * @dev Returns the number of values on the set. O(1).\r\n */\r\n function _length(Set storage set) private view returns (uint256) {\r\n return set._values.length;\r\n }\r\n\r\n /**\r\n * @dev Returns the value stored at position `index` in the set. O(1).\r\n *\r\n * Note that there are no guarantees on the ordering of values inside the\r\n * array, and it may change when more values are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\r\n require(set._values.length > index, \"EnumerableSet: index out of bounds\");\r\n return set._values[index];\r\n }\r\n\r\n // Bytes32Set\r\n\r\n struct Bytes32Set {\r\n Set _inner;\r\n }\r\n\r\n /**\r\n * @dev Add a value to a set. O(1).\r\n *\r\n * Returns true if the value was added to the set, that is if it was not\r\n * already present.\r\n */\r\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\r\n return _add(set._inner, value);\r\n }\r\n\r\n /**\r\n * @dev Removes a value from a set. O(1).\r\n *\r\n * Returns true if the value was removed from the set, that is if it was\r\n * present.\r\n */\r\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\r\n return _remove(set._inner, value);\r\n }\r\n\r\n /**\r\n * @dev Returns true if the value is in the set. O(1).\r\n */\r\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\r\n return _contains(set._inner, value);\r\n }\r\n\r\n /**\r\n * @dev Returns the number of values in the set. O(1).\r\n */\r\n function length(Bytes32Set storage set) internal view returns (uint256) {\r\n return _length(set._inner);\r\n }\r\n\r\n /**\r\n * @dev Returns the value stored at position `index` in the set. O(1).\r\n *\r\n * Note that there are no guarantees on the ordering of values inside the\r\n * array, and it may change when more values are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\r\n return _at(set._inner, index);\r\n }\r\n\r\n // AddressSet\r\n\r\n struct AddressSet {\r\n Set _inner;\r\n }\r\n\r\n /**\r\n * @dev Add a value to a set. O(1).\r\n *\r\n * Returns true if the value was added to the set, that is if it was not\r\n * already present.\r\n */\r\n function add(AddressSet storage set, address value) internal returns (bool) {\r\n return _add(set._inner, bytes32(uint256(uint160(value))));\r\n }\r\n\r\n /**\r\n * @dev Removes a value from a set. O(1).\r\n *\r\n * Returns true if the value was removed from the set, that is if it was\r\n * present.\r\n */\r\n function remove(AddressSet storage set, address value) internal returns (bool) {\r\n return _remove(set._inner, bytes32(uint256(uint160(value))));\r\n }\r\n\r\n /**\r\n * @dev Returns true if the value is in the set. O(1).\r\n */\r\n function contains(AddressSet storage set, address value) internal view returns (bool) {\r\n return _contains(set._inner, bytes32(uint256(uint160(value))));\r\n }\r\n\r\n /**\r\n * @dev Returns the number of values in the set. O(1).\r\n */\r\n function length(AddressSet storage set) internal view returns (uint256) {\r\n return _length(set._inner);\r\n }\r\n\r\n /**\r\n * @dev Returns the value stored at position `index` in the set. O(1).\r\n *\r\n * Note that there are no guarantees on the ordering of values inside the\r\n * array, and it may change when more values are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\r\n return address(uint160(uint256(_at(set._inner, index))));\r\n }\r\n\r\n\r\n // UintSet\r\n\r\n struct UintSet {\r\n Set _inner;\r\n }\r\n\r\n /**\r\n * @dev Add a value to a set. O(1).\r\n *\r\n * Returns true if the value was added to the set, that is if it was not\r\n * already present.\r\n */\r\n function add(UintSet storage set, uint256 value) internal returns (bool) {\r\n return _add(set._inner, bytes32(value));\r\n }\r\n\r\n /**\r\n * @dev Removes a value from a set. O(1).\r\n *\r\n * Returns true if the value was removed from the set, that is if it was\r\n * present.\r\n */\r\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\r\n return _remove(set._inner, bytes32(value));\r\n }\r\n\r\n /**\r\n * @dev Returns true if the value is in the set. O(1).\r\n */\r\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\r\n return _contains(set._inner, bytes32(value));\r\n }\r\n\r\n /**\r\n * @dev Returns the number of values on the set. O(1).\r\n */\r\n function length(UintSet storage set) internal view returns (uint256) {\r\n return _length(set._inner);\r\n }\r\n\r\n /**\r\n * @dev Returns the value stored at position `index` in the set. O(1).\r\n *\r\n * Note that there are no guarantees on the ordering of values inside the\r\n * array, and it may change when more values are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\r\n return uint256(_at(set._inner, index));\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/utils/EnumerableMap.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Library for managing an enumerable variant of Solidity's\r\n * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]\r\n * type.\r\n *\r\n * Maps have the following properties:\r\n *\r\n * - Entries are added, removed, and checked for existence in constant time\r\n * (O(1)).\r\n * - Entries are enumerated in O(n). No guarantees are made on the ordering.\r\n *\r\n * ```\r\n * contract Example {\r\n * // Add the library methods\r\n * using EnumerableMap for EnumerableMap.UintToAddressMap;\r\n *\r\n * // Declare a set state variable\r\n * EnumerableMap.UintToAddressMap private myMap;\r\n * }\r\n * ```\r\n *\r\n * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are\r\n * supported.\r\n */\r\nlibrary EnumerableMap {\r\n // To implement this library for multiple types with as little code\r\n // repetition as possible, we write it in terms of a generic Map type with\r\n // bytes32 keys and values.\r\n // The Map implementation uses private functions, and user-facing\r\n // implementations (such as Uint256ToAddressMap) are just wrappers around\r\n // the underlying Map.\r\n // This means that we can only create new EnumerableMaps for types that fit\r\n // in bytes32.\r\n\r\n struct MapEntry {\r\n bytes32 _key;\r\n bytes32 _value;\r\n }\r\n\r\n struct Map {\r\n // Storage of map keys and values\r\n MapEntry[] _entries;\r\n\r\n // Position of the entry defined by a key in the `entries` array, plus 1\r\n // because index 0 means a key is not in the map.\r\n mapping (bytes32 => uint256) _indexes;\r\n }\r\n\r\n /**\r\n * @dev Adds a key-value pair to a map, or updates the value for an existing\r\n * key. O(1).\r\n *\r\n * Returns true if the key was added to the map, that is if it was not\r\n * already present.\r\n */\r\n function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) {\r\n // We read and store the key's index to prevent multiple reads from the same storage slot\r\n uint256 keyIndex = map._indexes[key];\r\n\r\n if (keyIndex == 0) { // Equivalent to !contains(map, key)\r\n map._entries.push(MapEntry({ _key: key, _value: value }));\r\n // The entry is stored at length-1, but we add 1 to all indexes\r\n // and use 0 as a sentinel value\r\n map._indexes[key] = map._entries.length;\r\n return true;\r\n } else {\r\n map._entries[keyIndex - 1]._value = value;\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * @dev Removes a key-value pair from a map. O(1).\r\n *\r\n * Returns true if the key was removed from the map, that is if it was present.\r\n */\r\n function _remove(Map storage map, bytes32 key) private returns (bool) {\r\n // We read and store the key's index to prevent multiple reads from the same storage slot\r\n uint256 keyIndex = map._indexes[key];\r\n\r\n if (keyIndex != 0) { // Equivalent to contains(map, key)\r\n // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one\r\n // in the array, and then remove the last entry (sometimes called as 'swap and pop').\r\n // This modifies the order of the array, as noted in {at}.\r\n\r\n uint256 toDeleteIndex = keyIndex - 1;\r\n uint256 lastIndex = map._entries.length - 1;\r\n\r\n // When the entry to delete is the last one, the swap operation is unnecessary. However, since this occurs\r\n // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.\r\n\r\n MapEntry storage lastEntry = map._entries[lastIndex];\r\n\r\n // Move the last entry to the index where the entry to delete is\r\n map._entries[toDeleteIndex] = lastEntry;\r\n // Update the index for the moved entry\r\n map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based\r\n\r\n // Delete the slot where the moved entry was stored\r\n map._entries.pop();\r\n\r\n // Delete the index for the deleted slot\r\n delete map._indexes[key];\r\n\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns true if the key is in the map. O(1).\r\n */\r\n function _contains(Map storage map, bytes32 key) private view returns (bool) {\r\n return map._indexes[key] != 0;\r\n }\r\n\r\n /**\r\n * @dev Returns the number of key-value pairs in the map. O(1).\r\n */\r\n function _length(Map storage map) private view returns (uint256) {\r\n return map._entries.length;\r\n }\r\n\r\n /**\r\n * @dev Returns the key-value pair stored at position `index` in the map. O(1).\r\n *\r\n * Note that there are no guarantees on the ordering of entries inside the\r\n * array, and it may change when more entries are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) {\r\n require(map._entries.length > index, \"EnumerableMap: index out of bounds\");\r\n\r\n MapEntry storage entry = map._entries[index];\r\n return (entry._key, entry._value);\r\n }\r\n\r\n /**\r\n * @dev Tries to returns the value associated with `key`. O(1).\r\n * Does not revert if `key` is not in the map.\r\n */\r\n function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {\r\n uint256 keyIndex = map._indexes[key];\r\n if (keyIndex == 0) return (false, 0); // Equivalent to contains(map, key)\r\n return (true, map._entries[keyIndex - 1]._value); // All indexes are 1-based\r\n }\r\n\r\n /**\r\n * @dev Returns the value associated with `key`. O(1).\r\n *\r\n * Requirements:\r\n *\r\n * - `key` must be in the map.\r\n */\r\n function _get(Map storage map, bytes32 key) private view returns (bytes32) {\r\n uint256 keyIndex = map._indexes[key];\r\n require(keyIndex != 0, \"EnumerableMap: nonexistent key\"); // Equivalent to contains(map, key)\r\n return map._entries[keyIndex - 1]._value; // All indexes are 1-based\r\n }\r\n\r\n /**\r\n * @dev Same as {_get}, with a custom error message when `key` is not in the map.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {_tryGet}.\r\n */\r\n function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) {\r\n uint256 keyIndex = map._indexes[key];\r\n require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key)\r\n return map._entries[keyIndex - 1]._value; // All indexes are 1-based\r\n }\r\n\r\n // UintToAddressMap\r\n\r\n struct UintToAddressMap {\r\n Map _inner;\r\n }\r\n\r\n /**\r\n * @dev Adds a key-value pair to a map, or updates the value for an existing\r\n * key. O(1).\r\n *\r\n * Returns true if the key was added to the map, that is if it was not\r\n * already present.\r\n */\r\n function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {\r\n return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));\r\n }\r\n\r\n /**\r\n * @dev Removes a value from a set. O(1).\r\n *\r\n * Returns true if the key was removed from the map, that is if it was present.\r\n */\r\n function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {\r\n return _remove(map._inner, bytes32(key));\r\n }\r\n\r\n /**\r\n * @dev Returns true if the key is in the map. O(1).\r\n */\r\n function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {\r\n return _contains(map._inner, bytes32(key));\r\n }\r\n\r\n /**\r\n * @dev Returns the number of elements in the map. O(1).\r\n */\r\n function length(UintToAddressMap storage map) internal view returns (uint256) {\r\n return _length(map._inner);\r\n }\r\n\r\n /**\r\n * @dev Returns the element stored at position `index` in the set. O(1).\r\n * Note that there are no guarantees on the ordering of values inside the\r\n * array, and it may change when more values are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {\r\n (bytes32 key, bytes32 value) = _at(map._inner, index);\r\n return (uint256(key), address(uint160(uint256(value))));\r\n }\r\n\r\n /**\r\n * @dev Tries to returns the value associated with `key`. O(1).\r\n * Does not revert if `key` is not in the map.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {\r\n (bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));\r\n return (success, address(uint160(uint256(value))));\r\n }\r\n\r\n /**\r\n * @dev Returns the value associated with `key`. O(1).\r\n *\r\n * Requirements:\r\n *\r\n * - `key` must be in the map.\r\n */\r\n function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {\r\n return address(uint160(uint256(_get(map._inner, bytes32(key)))));\r\n }\r\n\r\n /**\r\n * @dev Same as {get}, with a custom error message when `key` is not in the map.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {tryGet}.\r\n */\r\n function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) {\r\n return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage))));\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/utils/Strings.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev String operations.\r\n */\r\nlibrary Strings {\r\n /**\r\n * @dev Converts a `uint256` to its ASCII `string` representation.\r\n */\r\n function toString(uint256 value) internal pure returns (string memory) {\r\n // Inspired by OraclizeAPI's implementation - MIT licence\r\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\r\n\r\n if (value == 0) {\r\n return \"0\";\r\n }\r\n uint256 temp = value;\r\n uint256 digits;\r\n while (temp != 0) {\r\n digits++;\r\n temp /= 10;\r\n }\r\n bytes memory buffer = new bytes(digits);\r\n uint256 index = digits - 1;\r\n temp = value;\r\n while (temp != 0) {\r\n buffer[index--] = bytes1(uint8(48 + temp % 10));\r\n temp /= 10;\r\n }\r\n return string(buffer);\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/token/ERC721/ERC721.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * @title ERC721 Non-Fungible Token Standard basic implementation\r\n * @dev see https://eips.ethereum.org/EIPS/eip-721\r\n */\r\ncontract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable {\r\n using SafeMath for uint256;\r\n using Address for address;\r\n using EnumerableSet for EnumerableSet.UintSet;\r\n using EnumerableMap for EnumerableMap.UintToAddressMap;\r\n using Strings for uint256;\r\n\r\n // Equals to `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`\r\n // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector`\r\n bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;\r\n\r\n // Mapping from holder address to their (enumerable) set of owned tokens\r\n mapping (address => EnumerableSet.UintSet) private _holderTokens;\r\n\r\n // Enumerable mapping from token ids to their owners\r\n EnumerableMap.UintToAddressMap private _tokenOwners;\r\n\r\n // Mapping from token ID to approved address\r\n mapping (uint256 => address) private _tokenApprovals;\r\n\r\n // Mapping from owner to operator approvals\r\n mapping (address => mapping (address => bool)) private _operatorApprovals;\r\n\r\n // Token name\r\n string private _name;\r\n\r\n // Token symbol\r\n string private _symbol;\r\n\r\n // Optional mapping for token URIs\r\n mapping (uint256 => string) private _tokenURIs;\r\n\r\n // Base URI\r\n string private _baseURI;\r\n\r\n /*\r\n * bytes4(keccak256('balanceOf(address)')) == 0x70a08231\r\n * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e\r\n * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3\r\n * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc\r\n * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465\r\n * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5\r\n * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd\r\n * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e\r\n * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde\r\n *\r\n * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^\r\n * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd\r\n */\r\n bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;\r\n\r\n /*\r\n * bytes4(keccak256('name()')) == 0x06fdde03\r\n * bytes4(keccak256('symbol()')) == 0x95d89b41\r\n * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd\r\n *\r\n * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f\r\n */\r\n bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;\r\n\r\n /*\r\n * bytes4(keccak256('totalSupply()')) == 0x18160ddd\r\n * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59\r\n * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7\r\n *\r\n * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63\r\n */\r\n bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;\r\n\r\n /**\r\n * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.\r\n */\r\n constructor (string memory name_, string memory symbol_) public {\r\n _name = name_;\r\n _symbol = symbol_;\r\n\r\n // register the supported interfaces to conform to ERC721 via ERC165\r\n _registerInterface(_INTERFACE_ID_ERC721);\r\n _registerInterface(_INTERFACE_ID_ERC721_METADATA);\r\n _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-balanceOf}.\r\n */\r\n function balanceOf(address owner) public view virtual override returns (uint256) {\r\n require(owner != address(0), \"ERC721: balance query for the zero address\");\r\n return _holderTokens[owner].length();\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-ownerOf}.\r\n */\r\n function ownerOf(uint256 tokenId) public view virtual override returns (address) {\r\n return _tokenOwners.get(tokenId, \"ERC721: owner query for nonexistent token\");\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Metadata-name}.\r\n */\r\n function name() public view virtual override returns (string memory) {\r\n return _name;\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Metadata-symbol}.\r\n */\r\n function symbol() public view virtual override returns (string memory) {\r\n return _symbol;\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Metadata-tokenURI}.\r\n */\r\n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\r\n require(_exists(tokenId), \"ERC721Metadata: URI query for nonexistent token\");\r\n\r\n string memory _tokenURI = _tokenURIs[tokenId];\r\n string memory base = baseURI();\r\n\r\n // If there is no base URI, return the token URI.\r\n if (bytes(base).length == 0) {\r\n return _tokenURI;\r\n }\r\n // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).\r\n if (bytes(_tokenURI).length > 0) {\r\n return string(abi.encodePacked(base, _tokenURI));\r\n }\r\n // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.\r\n return string(abi.encodePacked(base, tokenId.toString()));\r\n }\r\n\r\n /**\r\n * @dev Returns the base URI set via {_setBaseURI}. This will be\r\n * automatically added as a prefix in {tokenURI} to each token's URI, or\r\n * to the token ID if no specific URI is set for that token ID.\r\n */\r\n function baseURI() public view virtual returns (string memory) {\r\n return _baseURI;\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.\r\n */\r\n function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {\r\n return _holderTokens[owner].at(index);\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Enumerable-totalSupply}.\r\n */\r\n function totalSupply() public view virtual override returns (uint256) {\r\n // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds\r\n return _tokenOwners.length();\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Enumerable-tokenByIndex}.\r\n */\r\n function tokenByIndex(uint256 index) public view virtual override returns (uint256) {\r\n (uint256 tokenId, ) = _tokenOwners.at(index);\r\n return tokenId;\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-approve}.\r\n */\r\n function approve(address to, uint256 tokenId) public virtual override {\r\n address owner = ERC721.ownerOf(tokenId);\r\n require(to != owner, \"ERC721: approval to current owner\");\r\n\r\n require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()),\r\n \"ERC721: approve caller is not owner nor approved for all\"\r\n );\r\n\r\n _approve(to, tokenId);\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-getApproved}.\r\n */\r\n function getApproved(uint256 tokenId) public view virtual override returns (address) {\r\n require(_exists(tokenId), \"ERC721: approved query for nonexistent token\");\r\n\r\n return _tokenApprovals[tokenId];\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-setApprovalForAll}.\r\n */\r\n function setApprovalForAll(address operator, bool approved) public virtual override {\r\n require(operator != _msgSender(), \"ERC721: approve to caller\");\r\n\r\n _operatorApprovals[_msgSender()][operator] = approved;\r\n emit ApprovalForAll(_msgSender(), operator, approved);\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-isApprovedForAll}.\r\n */\r\n function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {\r\n return _operatorApprovals[owner][operator];\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-transferFrom}.\r\n */\r\n function transferFrom(address from, address to, uint256 tokenId) public virtual override {\r\n //solhint-disable-next-line max-line-length\r\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: transfer caller is not owner nor approved\");\r\n\r\n _transfer(from, to, tokenId);\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-safeTransferFrom}.\r\n */\r\n function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {\r\n safeTransferFrom(from, to, tokenId, \"\");\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-safeTransferFrom}.\r\n */\r\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {\r\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: transfer caller is not owner nor approved\");\r\n _safeTransfer(from, to, tokenId, _data);\r\n }\r\n\r\n /**\r\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\r\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\r\n *\r\n * `_data` is additional data, it has no specified format and it is sent in call to `to`.\r\n *\r\n * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.\r\n * implement alternative mechanisms to perform token transfer, such as signature-based.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must exist and be owned by `from`.\r\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {\r\n _transfer(from, to, tokenId);\r\n require(_checkOnERC721Received(from, to, tokenId, _data), \"ERC721: transfer to non ERC721Receiver implementer\");\r\n }\r\n\r\n /**\r\n * @dev Returns whether `tokenId` exists.\r\n *\r\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\r\n *\r\n * Tokens start existing when they are minted (`_mint`),\r\n * and stop existing when they are burned (`_burn`).\r\n */\r\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\r\n return _tokenOwners.contains(tokenId);\r\n }\r\n\r\n /**\r\n * @dev Returns whether `spender` is allowed to manage `tokenId`.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {\r\n require(_exists(tokenId), \"ERC721: operator query for nonexistent token\");\r\n address owner = ERC721.ownerOf(tokenId);\r\n return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender));\r\n }\r\n\r\n /**\r\n * @dev Safely mints `tokenId` and transfers it to `to`.\r\n *\r\n * Requirements:\r\n d*\r\n * - `tokenId` must not exist.\r\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _safeMint(address to, uint256 tokenId) internal virtual {\r\n _safeMint(to, tokenId, \"\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is\r\n * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.\r\n */\r\n function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {\r\n _mint(to, tokenId);\r\n require(_checkOnERC721Received(address(0), to, tokenId, _data), \"ERC721: transfer to non ERC721Receiver implementer\");\r\n }\r\n\r\n /**\r\n * @dev Mints `tokenId` and transfers it to `to`.\r\n *\r\n * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must not exist.\r\n * - `to` cannot be the zero address.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _mint(address to, uint256 tokenId) internal virtual {\r\n require(to != address(0), \"ERC721: mint to the zero address\");\r\n require(!_exists(tokenId), \"ERC721: token already minted\");\r\n\r\n _beforeTokenTransfer(address(0), to, tokenId);\r\n\r\n _holderTokens[to].add(tokenId);\r\n\r\n _tokenOwners.set(tokenId, to);\r\n\r\n emit Transfer(address(0), to, tokenId);\r\n }\r\n\r\n /**\r\n * @dev Destroys `tokenId`.\r\n * The approval is cleared when the token is burned.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _burn(uint256 tokenId) internal virtual {\r\n address owner = ERC721.ownerOf(tokenId); // internal owner\r\n\r\n _beforeTokenTransfer(owner, address(0), tokenId);\r\n\r\n // Clear approvals\r\n _approve(address(0), tokenId);\r\n\r\n // Clear metadata (if any)\r\n if (bytes(_tokenURIs[tokenId]).length != 0) {\r\n delete _tokenURIs[tokenId];\r\n }\r\n\r\n _holderTokens[owner].remove(tokenId);\r\n\r\n _tokenOwners.remove(tokenId);\r\n\r\n emit Transfer(owner, address(0), tokenId);\r\n }\r\n\r\n /**\r\n * @dev Transfers `tokenId` from `from` to `to`.\r\n * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\r\n *\r\n * Requirements:\r\n *\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must be owned by `from`.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _transfer(address from, address to, uint256 tokenId) internal virtual {\r\n require(ERC721.ownerOf(tokenId) == from, \"ERC721: transfer of token that is not own\"); // internal owner\r\n require(to != address(0), \"ERC721: transfer to the zero address\");\r\n\r\n _beforeTokenTransfer(from, to, tokenId);\r\n\r\n // Clear approvals from the previous owner\r\n _approve(address(0), tokenId);\r\n\r\n _holderTokens[from].remove(tokenId);\r\n _holderTokens[to].add(tokenId);\r\n\r\n _tokenOwners.set(tokenId, to);\r\n\r\n emit Transfer(from, to, tokenId);\r\n }\r\n\r\n /**\r\n * @dev Sets `_tokenURI` as the tokenURI of `tokenId`.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {\r\n require(_exists(tokenId), \"ERC721Metadata: URI set of nonexistent token\");\r\n _tokenURIs[tokenId] = _tokenURI;\r\n }\r\n\r\n /**\r\n * @dev Internal function to set the base URI for all token IDs. It is\r\n * automatically added as a prefix to the value returned in {tokenURI},\r\n * or to the token ID if {tokenURI} is empty.\r\n */\r\n function _setBaseURI(string memory baseURI_) internal virtual {\r\n _baseURI = baseURI_;\r\n }\r\n\r\n /**\r\n * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.\r\n * The call is not executed if the target address is not a contract.\r\n *\r\n * @param from address representing the previous owner of the given token ID\r\n * @param to target address that will receive the tokens\r\n * @param tokenId uint256 ID of the token to be transferred\r\n * @param _data bytes optional data to send along with the call\r\n * @return bool whether the call correctly returned the expected magic value\r\n */\r\n function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)\r\n private returns (bool)\r\n {\r\n if (!to.isContract()) {\r\n return true;\r\n }\r\n bytes memory returndata = to.functionCall(abi.encodeWithSelector(\r\n IERC721Receiver(to).onERC721Received.selector,\r\n _msgSender(),\r\n from,\r\n tokenId,\r\n _data\r\n ), \"ERC721: transfer to non ERC721Receiver implementer\");\r\n bytes4 retval = abi.decode(returndata, (bytes4));\r\n return (retval == _ERC721_RECEIVED);\r\n }\r\n\r\n /**\r\n * @dev Approve `to` to operate on `tokenId`\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function _approve(address to, uint256 tokenId) internal virtual {\r\n _tokenApprovals[tokenId] = to;\r\n emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner\r\n }\r\n\r\n /**\r\n * @dev Hook that is called before any token transfer. This includes minting\r\n * and burning.\r\n *\r\n * Calling conditions:\r\n *\r\n * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be\r\n * transferred to `to`.\r\n * - When `from` is zero, `tokenId` will be minted for `to`.\r\n * - When `to` is zero, ``from``'s `tokenId` will be burned.\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n *\r\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\r\n */\r\n function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }\r\n}\r\n\r\n// File: @openzeppelin/contracts/access/Ownable.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Contract module which provides a basic access control mechanism, where\r\n * there is an account (an owner) that can be granted exclusive access to\r\n * specific functions.\r\n *\r\n * By default, the owner account will be the one that deploys the contract. This\r\n * can later be changed with {transferOwnership}.\r\n *\r\n * This module is used through inheritance. It will make available the modifier\r\n * `onlyOwner`, which can be applied to your functions to restrict their use to\r\n * the owner.\r\n */\r\nabstract contract Ownable is Context {\r\n address private _owner;\r\n\r\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r\n\r\n /**\r\n * @dev Initializes the contract setting the deployer as the initial owner.\r\n */\r\n constructor () internal {\r\n address msgSender = _msgSender();\r\n _owner = msgSender;\r\n emit OwnershipTransferred(address(0), msgSender);\r\n }\r\n\r\n /**\r\n * @dev Returns the address of the current owner.\r\n */\r\n function owner() public view virtual returns (address) {\r\n return _owner;\r\n }\r\n\r\n /**\r\n * @dev Throws if called by any account other than the owner.\r\n */\r\n modifier onlyOwner() {\r\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\r\n _;\r\n }\r\n\r\n /**\r\n * @dev Leaves the contract without owner. It will not be possible to call\r\n * `onlyOwner` functions anymore. Can only be called by the current owner.\r\n *\r\n * NOTE: Renouncing ownership will leave the contract without an owner,\r\n * thereby removing any functionality that is only available to the owner.\r\n */\r\n function renounceOwnership() public virtual onlyOwner {\r\n emit OwnershipTransferred(_owner, address(0));\r\n _owner = address(0);\r\n }\r\n\r\n /**\r\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\r\n * Can only be called by the current owner.\r\n */\r\n function transferOwnership(address newOwner) public virtual onlyOwner {\r\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\r\n emit OwnershipTransferred(_owner, newOwner);\r\n _owner = newOwner;\r\n }\r\n}\r\n\r\n// File: contracts/BoredApeYachtClub.sol\r\n\r\n\r\npragma solidity ^0.7.0;\r\n\r\n\r\n\r\n/**\r\n * @title BoredApeYachtClub contract\r\n * @dev Extends ERC721 Non-Fungible Token Standard basic implementation\r\n */\r\ncontract BoredApeYachtClub is ERC721, Ownable {\r\n using SafeMath for uint256;\r\n\r\n string public BAYC_PROVENANCE = \"\";\r\n\r\n uint256 public startingIndexBlock;\r\n\r\n uint256 public startingIndex;\r\n\r\n uint256 public constant apePrice = 80000000000000000; //0.08 ETH\r\n\r\n uint public constant maxApePurchase = 20;\r\n\r\n uint256 public MAX_APES;\r\n\r\n bool public saleIsActive = false;\r\n\r\n uint256 public REVEAL_TIMESTAMP;\r\n\r\n constructor(string memory name, string memory symbol, uint256 maxNftSupply, uint256 saleStart) ERC721(name, symbol) {\r\n MAX_APES = maxNftSupply;\r\n REVEAL_TIMESTAMP = saleStart + (86400 * 9);\r\n }\r\n\r\n function withdraw() public onlyOwner {\r\n uint balance = address(this).balance;\r\n msg.sender.transfer(balance);\r\n }\r\n\r\n /**\r\n * Set some Bored Apes aside\r\n */\r\n function reserveApes() public onlyOwner { \r\n uint supply = totalSupply();\r\n uint i;\r\n for (i = 0; i < 30; i++) {\r\n _safeMint(msg.sender, supply + i);\r\n }\r\n }\r\n\r\n /**\r\n * DM Gargamel in Discord that you're standing right behind him.\r\n */\r\n function setRevealTimestamp(uint256 revealTimeStamp) public onlyOwner {\r\n REVEAL_TIMESTAMP = revealTimeStamp;\r\n } \r\n\r\n /* \r\n * Set provenance once it's calculated\r\n */\r\n function setProvenanceHash(string memory provenanceHash) public onlyOwner {\r\n BAYC_PROVENANCE = provenanceHash;\r\n }\r\n\r\n function setBaseURI(string memory baseURI) public onlyOwner {\r\n _setBaseURI(baseURI);\r\n }\r\n\r\n /*\r\n * Pause sale if active, make active if paused\r\n */\r\n function flipSaleState() public onlyOwner {\r\n saleIsActive = !saleIsActive;\r\n }\r\n\r\n /**\r\n * Mints Bored Apes\r\n */\r\n function mintApe(uint numberOfTokens) public payable {\r\n require(saleIsActive, \"Sale must be active to mint Ape\");\r\n require(numberOfTokens <= maxApePurchase, \"Can only mint 20 tokens at a time\");\r\n require(totalSupply().add(numberOfTokens) <= MAX_APES, \"Purchase would exceed max supply of Apes\");\r\n require(apePrice.mul(numberOfTokens) <= msg.value, \"Ether value sent is not correct\");\r\n \r\n for(uint i = 0; i < numberOfTokens; i++) {\r\n uint mintIndex = totalSupply();\r\n if (totalSupply() < MAX_APES) {\r\n _safeMint(msg.sender, mintIndex);\r\n }\r\n }\r\n\r\n // If we haven't set the starting index and this is either 1) the last saleable token or 2) the first token to be sold after\r\n // the end of pre-sale, set the starting index block\r\n if (startingIndexBlock == 0 && (totalSupply() == MAX_APES || block.timestamp >= REVEAL_TIMESTAMP)) {\r\n startingIndexBlock = block.number;\r\n } \r\n }\r\n\r\n /**\r\n * Set the starting index for the collection\r\n */\r\n function setStartingIndex() public {\r\n require(startingIndex == 0, \"Starting index is already set\");\r\n require(startingIndexBlock != 0, \"Starting index block must be set\");\r\n \r\n startingIndex = uint(blockhash(startingIndexBlock)) % MAX_APES;\r\n // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes)\r\n if (block.number.sub(startingIndexBlock) > 255) {\r\n startingIndex = uint(blockhash(block.number - 1)) % MAX_APES;\r\n }\r\n // Prevent default sequence\r\n if (startingIndex == 0) {\r\n startingIndex = startingIndex.add(1);\r\n }\r\n }\r\n\r\n /**\r\n * Set the starting index block for the collection, essentially unblocking\r\n * setting starting index\r\n */\r\n function emergencySetStartingIndexBlock() public onlyOwner {\r\n require(startingIndex == 0, \"Starting index is already set\");\r\n \r\n startingIndexBlock = block.number;\r\n }\r\n}","ABI":"[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"maxNftSupply\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"saleStart\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"approved\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"BAYC_PROVENANCE\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"MAX_APES\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"REVEAL_TIMESTAMP\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"apePrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"baseURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"emergencySetStartingIndexBlock\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"flipSaleState\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getApproved\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"maxApePurchase\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"numberOfTokens\",\"type\":\"uint256\"}],\"name\":\"mintApe\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"reserveApes\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"saleIsActive\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"baseURI\",\"type\":\"string\"}],\"name\":\"setBaseURI\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"provenanceHash\",\"type\":\"string\"}],\"name\":\"setProvenanceHash\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"revealTimeStamp\",\"type\":\"uint256\"}],\"name\":\"setRevealTimestamp\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"setStartingIndex\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"startingIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"startingIndexBlock\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenByIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenOfOwnerByIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"tokenURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]","ContractName":"BoredApeYachtClub","CompilerVersion":"v0.7.0+commit.9e61f92b","OptimizationUsed":"0","Runs":"200","ConstructorArguments":"000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000006080e6d70000000000000000000000000000000000000000000000000000000000000011426f7265644170655961636874436c756200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044241594300000000000000000000000000000000000000000000000000000000","EVMVersion":"Default","Library":"","LicenseType":"MIT","Proxy":"0","Implementation":"","SwarmSource":"ipfs://b0e64d1fa6c4dbeb9c6f54607d7e1996943fe27624a80652f57b53fda084621b"}]} \ No newline at end of file +{"status":"1","message":"OK-Missing/Invalid API Key, rate limit of 1/5sec applied","result":[{"SourceCode":"// File: @openzeppelin/contracts/utils/Context.sol\r\n\r\n// SPDX-License-Identifier: MIT\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/*\r\n * @dev Provides information about the current execution context, including the\r\n * sender of the transaction and its data. While these are generally available\r\n * via msg.sender and msg.data, they should not be accessed in such a direct\r\n * manner, since when dealing with GSN meta-transactions the account sending and\r\n * paying for execution may not be the actual sender (as far as an application\r\n * is concerned).\r\n *\r\n * This contract is only required for intermediate, library-like contracts.\r\n */\r\nabstract contract Context {\r\n function _msgSender() internal view virtual returns (address payable) {\r\n return msg.sender;\r\n }\r\n\r\n function _msgData() internal view virtual returns (bytes memory) {\r\n this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\r\n return msg.data;\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/introspection/IERC165.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Interface of the ERC165 standard, as defined in the\r\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\r\n *\r\n * Implementers can declare support of contract interfaces, which can then be\r\n * queried by others ({ERC165Checker}).\r\n *\r\n * For an implementation, see {ERC165}.\r\n */\r\ninterface IERC165 {\r\n /**\r\n * @dev Returns true if this contract implements the interface defined by\r\n * `interfaceId`. See the corresponding\r\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\r\n * to learn more about how these ids are created.\r\n *\r\n * This function call must use less than 30 000 gas.\r\n */\r\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\r\n}\r\n\r\n// File: @openzeppelin/contracts/token/ERC721/IERC721.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.2 <0.8.0;\r\n\r\n\r\n/**\r\n * @dev Required interface of an ERC721 compliant contract.\r\n */\r\ninterface IERC721 is IERC165 {\r\n /**\r\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\r\n */\r\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\r\n\r\n /**\r\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\r\n */\r\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\r\n\r\n /**\r\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\r\n */\r\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\r\n\r\n /**\r\n * @dev Returns the number of tokens in ``owner``'s account.\r\n */\r\n function balanceOf(address owner) external view returns (uint256 balance);\r\n\r\n /**\r\n * @dev Returns the owner of the `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function ownerOf(uint256 tokenId) external view returns (address owner);\r\n\r\n /**\r\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\r\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must exist and be owned by `from`.\r\n * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.\r\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function safeTransferFrom(address from, address to, uint256 tokenId) external;\r\n\r\n /**\r\n * @dev Transfers `tokenId` token from `from` to `to`.\r\n *\r\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must be owned by `from`.\r\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transferFrom(address from, address to, uint256 tokenId) external;\r\n\r\n /**\r\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\r\n * The approval is cleared when the token is transferred.\r\n *\r\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\r\n *\r\n * Requirements:\r\n *\r\n * - The caller must own the token or be an approved operator.\r\n * - `tokenId` must exist.\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function approve(address to, uint256 tokenId) external;\r\n\r\n /**\r\n * @dev Returns the account approved for `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function getApproved(uint256 tokenId) external view returns (address operator);\r\n\r\n /**\r\n * @dev Approve or remove `operator` as an operator for the caller.\r\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\r\n *\r\n * Requirements:\r\n *\r\n * - The `operator` cannot be the caller.\r\n *\r\n * Emits an {ApprovalForAll} event.\r\n */\r\n function setApprovalForAll(address operator, bool _approved) external;\r\n\r\n /**\r\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\r\n *\r\n * See {setApprovalForAll}\r\n */\r\n function isApprovedForAll(address owner, address operator) external view returns (bool);\r\n\r\n /**\r\n * @dev Safely transfers `tokenId` token from `from` to `to`.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must exist and be owned by `from`.\r\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\r\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\r\n}\r\n\r\n// File: @openzeppelin/contracts/token/ERC721/IERC721Metadata.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.2 <0.8.0;\r\n\r\n\r\n/**\r\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\r\n * @dev See https://eips.ethereum.org/EIPS/eip-721\r\n */\r\ninterface IERC721Metadata is IERC721 {\r\n\r\n /**\r\n * @dev Returns the token collection name.\r\n */\r\n function name() external view returns (string memory);\r\n\r\n /**\r\n * @dev Returns the token collection symbol.\r\n */\r\n function symbol() external view returns (string memory);\r\n\r\n /**\r\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\r\n */\r\n function tokenURI(uint256 tokenId) external view returns (string memory);\r\n}\r\n\r\n// File: @openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.2 <0.8.0;\r\n\r\n\r\n/**\r\n * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension\r\n * @dev See https://eips.ethereum.org/EIPS/eip-721\r\n */\r\ninterface IERC721Enumerable is IERC721 {\r\n\r\n /**\r\n * @dev Returns the total amount of tokens stored by the contract.\r\n */\r\n function totalSupply() external view returns (uint256);\r\n\r\n /**\r\n * @dev Returns a token ID owned by `owner` at a given `index` of its token list.\r\n * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.\r\n */\r\n function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);\r\n\r\n /**\r\n * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.\r\n * Use along with {totalSupply} to enumerate all tokens.\r\n */\r\n function tokenByIndex(uint256 index) external view returns (uint256);\r\n}\r\n\r\n// File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @title ERC721 token receiver interface\r\n * @dev Interface for any contract that wants to support safeTransfers\r\n * from ERC721 asset contracts.\r\n */\r\ninterface IERC721Receiver {\r\n /**\r\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\r\n * by `operator` from `from`, this function is called.\r\n *\r\n * It must return its Solidity selector to confirm the token transfer.\r\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\r\n *\r\n * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.\r\n */\r\n function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);\r\n}\r\n\r\n// File: @openzeppelin/contracts/introspection/ERC165.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n\r\n/**\r\n * @dev Implementation of the {IERC165} interface.\r\n *\r\n * Contracts may inherit from this and call {_registerInterface} to declare\r\n * their support of an interface.\r\n */\r\nabstract contract ERC165 is IERC165 {\r\n /*\r\n * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7\r\n */\r\n bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;\r\n\r\n /**\r\n * @dev Mapping of interface ids to whether or not it's supported.\r\n */\r\n mapping(bytes4 => bool) private _supportedInterfaces;\r\n\r\n constructor () internal {\r\n // Derived contracts need only register support for their own interfaces,\r\n // we register support for ERC165 itself here\r\n _registerInterface(_INTERFACE_ID_ERC165);\r\n }\r\n\r\n /**\r\n * @dev See {IERC165-supportsInterface}.\r\n *\r\n * Time complexity O(1), guaranteed to always use less than 30 000 gas.\r\n */\r\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\r\n return _supportedInterfaces[interfaceId];\r\n }\r\n\r\n /**\r\n * @dev Registers the contract as an implementer of the interface defined by\r\n * `interfaceId`. Support of the actual ERC165 interface is automatic and\r\n * registering its interface id is not required.\r\n *\r\n * See {IERC165-supportsInterface}.\r\n *\r\n * Requirements:\r\n *\r\n * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).\r\n */\r\n function _registerInterface(bytes4 interfaceId) internal virtual {\r\n require(interfaceId != 0xffffffff, \"ERC165: invalid interface id\");\r\n _supportedInterfaces[interfaceId] = true;\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/math/SafeMath.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\r\n * checks.\r\n *\r\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\r\n * in bugs, because programmers usually assume that an overflow raises an\r\n * error, which is the standard behavior in high level programming languages.\r\n * `SafeMath` restores this intuition by reverting the transaction when an\r\n * operation overflows.\r\n *\r\n * Using this library instead of the unchecked operations eliminates an entire\r\n * class of bugs, so it's recommended to use it always.\r\n */\r\nlibrary SafeMath {\r\n /**\r\n * @dev Returns the addition of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n uint256 c = a + b;\r\n if (c < a) return (false, 0);\r\n return (true, c);\r\n }\r\n\r\n /**\r\n * @dev Returns the substraction of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n if (b > a) return (false, 0);\r\n return (true, a - b);\r\n }\r\n\r\n /**\r\n * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\r\n // benefit is lost if 'b' is also tested.\r\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\r\n if (a == 0) return (true, 0);\r\n uint256 c = a * b;\r\n if (c / a != b) return (false, 0);\r\n return (true, c);\r\n }\r\n\r\n /**\r\n * @dev Returns the division of two unsigned integers, with a division by zero flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n if (b == 0) return (false, 0);\r\n return (true, a / b);\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\r\n if (b == 0) return (false, 0);\r\n return (true, a % b);\r\n }\r\n\r\n /**\r\n * @dev Returns the addition of two unsigned integers, reverting on\r\n * overflow.\r\n *\r\n * Counterpart to Solidity's `+` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Addition cannot overflow.\r\n */\r\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\r\n uint256 c = a + b;\r\n require(c >= a, \"SafeMath: addition overflow\");\r\n return c;\r\n }\r\n\r\n /**\r\n * @dev Returns the subtraction of two unsigned integers, reverting on\r\n * overflow (when the result is negative).\r\n *\r\n * Counterpart to Solidity's `-` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Subtraction cannot overflow.\r\n */\r\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\r\n require(b <= a, \"SafeMath: subtraction overflow\");\r\n return a - b;\r\n }\r\n\r\n /**\r\n * @dev Returns the multiplication of two unsigned integers, reverting on\r\n * overflow.\r\n *\r\n * Counterpart to Solidity's `*` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Multiplication cannot overflow.\r\n */\r\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\r\n if (a == 0) return 0;\r\n uint256 c = a * b;\r\n require(c / a == b, \"SafeMath: multiplication overflow\");\r\n return c;\r\n }\r\n\r\n /**\r\n * @dev Returns the integer division of two unsigned integers, reverting on\r\n * division by zero. The result is rounded towards zero.\r\n *\r\n * Counterpart to Solidity's `/` operator. Note: this function uses a\r\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n * uses an invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\r\n require(b > 0, \"SafeMath: division by zero\");\r\n return a / b;\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n * reverting when dividing by zero.\r\n *\r\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\r\n * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n * invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\r\n require(b > 0, \"SafeMath: modulo by zero\");\r\n return a % b;\r\n }\r\n\r\n /**\r\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\r\n * overflow (when the result is negative).\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {trySub}.\r\n *\r\n * Counterpart to Solidity's `-` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Subtraction cannot overflow.\r\n */\r\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b <= a, errorMessage);\r\n return a - b;\r\n }\r\n\r\n /**\r\n * @dev Returns the integer division of two unsigned integers, reverting with custom message on\r\n * division by zero. The result is rounded towards zero.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {tryDiv}.\r\n *\r\n * Counterpart to Solidity's `/` operator. Note: this function uses a\r\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n * uses an invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b > 0, errorMessage);\r\n return a / b;\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n * reverting with custom message when dividing by zero.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {tryMod}.\r\n *\r\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\r\n * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n * invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n require(b > 0, errorMessage);\r\n return a % b;\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/utils/Address.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.2 <0.8.0;\r\n\r\n/**\r\n * @dev Collection of functions related to the address type\r\n */\r\nlibrary Address {\r\n /**\r\n * @dev Returns true if `account` is a contract.\r\n *\r\n * [IMPORTANT]\r\n * ====\r\n * It is unsafe to assume that an address for which this function returns\r\n * false is an externally-owned account (EOA) and not a contract.\r\n *\r\n * Among others, `isContract` will return false for the following\r\n * types of addresses:\r\n *\r\n * - an externally-owned account\r\n * - a contract in construction\r\n * - an address where a contract will be created\r\n * - an address where a contract lived, but was destroyed\r\n * ====\r\n */\r\n function isContract(address account) internal view returns (bool) {\r\n // This method relies on extcodesize, which returns 0 for contracts in\r\n // construction, since the code is only stored at the end of the\r\n // constructor execution.\r\n\r\n uint256 size;\r\n // solhint-disable-next-line no-inline-assembly\r\n assembly { size := extcodesize(account) }\r\n return size > 0;\r\n }\r\n\r\n /**\r\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\r\n * `recipient`, forwarding all available gas and reverting on errors.\r\n *\r\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\r\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\r\n * imposed by `transfer`, making them unable to receive funds via\r\n * `transfer`. {sendValue} removes this limitation.\r\n *\r\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\r\n *\r\n * IMPORTANT: because control is transferred to `recipient`, care must be\r\n * taken to not create reentrancy vulnerabilities. Consider using\r\n * {ReentrancyGuard} or the\r\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\r\n */\r\n function sendValue(address payable recipient, uint256 amount) internal {\r\n require(address(this).balance >= amount, \"Address: insufficient balance\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\r\n (bool success, ) = recipient.call{ value: amount }(\"\");\r\n require(success, \"Address: unable to send value, recipient may have reverted\");\r\n }\r\n\r\n /**\r\n * @dev Performs a Solidity function call using a low level `call`. A\r\n * plain`call` is an unsafe replacement for a function call: use this\r\n * function instead.\r\n *\r\n * If `target` reverts with a revert reason, it is bubbled up by this\r\n * function (like regular Solidity function calls).\r\n *\r\n * Returns the raw returned data. To convert to the expected return value,\r\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\r\n *\r\n * Requirements:\r\n *\r\n * - `target` must be a contract.\r\n * - calling `target` with `data` must not revert.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\r\n return functionCall(target, data, \"Address: low-level call failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\r\n * `errorMessage` as a fallback revert reason when `target` reverts.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\r\n return functionCallWithValue(target, data, 0, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but also transferring `value` wei to `target`.\r\n *\r\n * Requirements:\r\n *\r\n * - the calling contract must have an ETH balance of at least `value`.\r\n * - the called Solidity function must be `payable`.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\r\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\r\n * with `errorMessage` as a fallback revert reason when `target` reverts.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\r\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\r\n require(isContract(target), \"Address: call to non-contract\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls\r\n (bool success, bytes memory returndata) = target.call{ value: value }(data);\r\n return _verifyCallResult(success, returndata, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but performing a static call.\r\n *\r\n * _Available since v3.3._\r\n */\r\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\r\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r\n * but performing a static call.\r\n *\r\n * _Available since v3.3._\r\n */\r\n function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {\r\n require(isContract(target), \"Address: static call to non-contract\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls\r\n (bool success, bytes memory returndata) = target.staticcall(data);\r\n return _verifyCallResult(success, returndata, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but performing a delegate call.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\r\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r\n * but performing a delegate call.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\r\n require(isContract(target), \"Address: delegate call to non-contract\");\r\n\r\n // solhint-disable-next-line avoid-low-level-calls\r\n (bool success, bytes memory returndata) = target.delegatecall(data);\r\n return _verifyCallResult(success, returndata, errorMessage);\r\n }\r\n\r\n function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {\r\n if (success) {\r\n return returndata;\r\n } else {\r\n // Look for revert reason and bubble it up if present\r\n if (returndata.length > 0) {\r\n // The easiest way to bubble the revert reason is using memory via assembly\r\n\r\n // solhint-disable-next-line no-inline-assembly\r\n assembly {\r\n let returndata_size := mload(returndata)\r\n revert(add(32, returndata), returndata_size)\r\n }\r\n } else {\r\n revert(errorMessage);\r\n }\r\n }\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/utils/EnumerableSet.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Library for managing\r\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\r\n * types.\r\n *\r\n * Sets have the following properties:\r\n *\r\n * - Elements are added, removed, and checked for existence in constant time\r\n * (O(1)).\r\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\r\n *\r\n * ```\r\n * contract Example {\r\n * // Add the library methods\r\n * using EnumerableSet for EnumerableSet.AddressSet;\r\n *\r\n * // Declare a set state variable\r\n * EnumerableSet.AddressSet private mySet;\r\n * }\r\n * ```\r\n *\r\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\r\n * and `uint256` (`UintSet`) are supported.\r\n */\r\nlibrary EnumerableSet {\r\n // To implement this library for multiple types with as little code\r\n // repetition as possible, we write it in terms of a generic Set type with\r\n // bytes32 values.\r\n // The Set implementation uses private functions, and user-facing\r\n // implementations (such as AddressSet) are just wrappers around the\r\n // underlying Set.\r\n // This means that we can only create new EnumerableSets for types that fit\r\n // in bytes32.\r\n\r\n struct Set {\r\n // Storage of set values\r\n bytes32[] _values;\r\n\r\n // Position of the value in the `values` array, plus 1 because index 0\r\n // means a value is not in the set.\r\n mapping (bytes32 => uint256) _indexes;\r\n }\r\n\r\n /**\r\n * @dev Add a value to a set. O(1).\r\n *\r\n * Returns true if the value was added to the set, that is if it was not\r\n * already present.\r\n */\r\n function _add(Set storage set, bytes32 value) private returns (bool) {\r\n if (!_contains(set, value)) {\r\n set._values.push(value);\r\n // The value is stored at length-1, but we add 1 to all indexes\r\n // and use 0 as a sentinel value\r\n set._indexes[value] = set._values.length;\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * @dev Removes a value from a set. O(1).\r\n *\r\n * Returns true if the value was removed from the set, that is if it was\r\n * present.\r\n */\r\n function _remove(Set storage set, bytes32 value) private returns (bool) {\r\n // We read and store the value's index to prevent multiple reads from the same storage slot\r\n uint256 valueIndex = set._indexes[value];\r\n\r\n if (valueIndex != 0) { // Equivalent to contains(set, value)\r\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\r\n // the array, and then remove the last element (sometimes called as 'swap and pop').\r\n // This modifies the order of the array, as noted in {at}.\r\n\r\n uint256 toDeleteIndex = valueIndex - 1;\r\n uint256 lastIndex = set._values.length - 1;\r\n\r\n // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs\r\n // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.\r\n\r\n bytes32 lastvalue = set._values[lastIndex];\r\n\r\n // Move the last value to the index where the value to delete is\r\n set._values[toDeleteIndex] = lastvalue;\r\n // Update the index for the moved value\r\n set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based\r\n\r\n // Delete the slot where the moved value was stored\r\n set._values.pop();\r\n\r\n // Delete the index for the deleted slot\r\n delete set._indexes[value];\r\n\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns true if the value is in the set. O(1).\r\n */\r\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\r\n return set._indexes[value] != 0;\r\n }\r\n\r\n /**\r\n * @dev Returns the number of values on the set. O(1).\r\n */\r\n function _length(Set storage set) private view returns (uint256) {\r\n return set._values.length;\r\n }\r\n\r\n /**\r\n * @dev Returns the value stored at position `index` in the set. O(1).\r\n *\r\n * Note that there are no guarantees on the ordering of values inside the\r\n * array, and it may change when more values are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\r\n require(set._values.length > index, \"EnumerableSet: index out of bounds\");\r\n return set._values[index];\r\n }\r\n\r\n // Bytes32Set\r\n\r\n struct Bytes32Set {\r\n Set _inner;\r\n }\r\n\r\n /**\r\n * @dev Add a value to a set. O(1).\r\n *\r\n * Returns true if the value was added to the set, that is if it was not\r\n * already present.\r\n */\r\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\r\n return _add(set._inner, value);\r\n }\r\n\r\n /**\r\n * @dev Removes a value from a set. O(1).\r\n *\r\n * Returns true if the value was removed from the set, that is if it was\r\n * present.\r\n */\r\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\r\n return _remove(set._inner, value);\r\n }\r\n\r\n /**\r\n * @dev Returns true if the value is in the set. O(1).\r\n */\r\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\r\n return _contains(set._inner, value);\r\n }\r\n\r\n /**\r\n * @dev Returns the number of values in the set. O(1).\r\n */\r\n function length(Bytes32Set storage set) internal view returns (uint256) {\r\n return _length(set._inner);\r\n }\r\n\r\n /**\r\n * @dev Returns the value stored at position `index` in the set. O(1).\r\n *\r\n * Note that there are no guarantees on the ordering of values inside the\r\n * array, and it may change when more values are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\r\n return _at(set._inner, index);\r\n }\r\n\r\n // AddressSet\r\n\r\n struct AddressSet {\r\n Set _inner;\r\n }\r\n\r\n /**\r\n * @dev Add a value to a set. O(1).\r\n *\r\n * Returns true if the value was added to the set, that is if it was not\r\n * already present.\r\n */\r\n function add(AddressSet storage set, address value) internal returns (bool) {\r\n return _add(set._inner, bytes32(uint256(uint160(value))));\r\n }\r\n\r\n /**\r\n * @dev Removes a value from a set. O(1).\r\n *\r\n * Returns true if the value was removed from the set, that is if it was\r\n * present.\r\n */\r\n function remove(AddressSet storage set, address value) internal returns (bool) {\r\n return _remove(set._inner, bytes32(uint256(uint160(value))));\r\n }\r\n\r\n /**\r\n * @dev Returns true if the value is in the set. O(1).\r\n */\r\n function contains(AddressSet storage set, address value) internal view returns (bool) {\r\n return _contains(set._inner, bytes32(uint256(uint160(value))));\r\n }\r\n\r\n /**\r\n * @dev Returns the number of values in the set. O(1).\r\n */\r\n function length(AddressSet storage set) internal view returns (uint256) {\r\n return _length(set._inner);\r\n }\r\n\r\n /**\r\n * @dev Returns the value stored at position `index` in the set. O(1).\r\n *\r\n * Note that there are no guarantees on the ordering of values inside the\r\n * array, and it may change when more values are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\r\n return address(uint160(uint256(_at(set._inner, index))));\r\n }\r\n\r\n\r\n // UintSet\r\n\r\n struct UintSet {\r\n Set _inner;\r\n }\r\n\r\n /**\r\n * @dev Add a value to a set. O(1).\r\n *\r\n * Returns true if the value was added to the set, that is if it was not\r\n * already present.\r\n */\r\n function add(UintSet storage set, uint256 value) internal returns (bool) {\r\n return _add(set._inner, bytes32(value));\r\n }\r\n\r\n /**\r\n * @dev Removes a value from a set. O(1).\r\n *\r\n * Returns true if the value was removed from the set, that is if it was\r\n * present.\r\n */\r\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\r\n return _remove(set._inner, bytes32(value));\r\n }\r\n\r\n /**\r\n * @dev Returns true if the value is in the set. O(1).\r\n */\r\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\r\n return _contains(set._inner, bytes32(value));\r\n }\r\n\r\n /**\r\n * @dev Returns the number of values on the set. O(1).\r\n */\r\n function length(UintSet storage set) internal view returns (uint256) {\r\n return _length(set._inner);\r\n }\r\n\r\n /**\r\n * @dev Returns the value stored at position `index` in the set. O(1).\r\n *\r\n * Note that there are no guarantees on the ordering of values inside the\r\n * array, and it may change when more values are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\r\n return uint256(_at(set._inner, index));\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/utils/EnumerableMap.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Library for managing an enumerable variant of Solidity's\r\n * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]\r\n * type.\r\n *\r\n * Maps have the following properties:\r\n *\r\n * - Entries are added, removed, and checked for existence in constant time\r\n * (O(1)).\r\n * - Entries are enumerated in O(n). No guarantees are made on the ordering.\r\n *\r\n * ```\r\n * contract Example {\r\n * // Add the library methods\r\n * using EnumerableMap for EnumerableMap.UintToAddressMap;\r\n *\r\n * // Declare a set state variable\r\n * EnumerableMap.UintToAddressMap private myMap;\r\n * }\r\n * ```\r\n *\r\n * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are\r\n * supported.\r\n */\r\nlibrary EnumerableMap {\r\n // To implement this library for multiple types with as little code\r\n // repetition as possible, we write it in terms of a generic Map type with\r\n // bytes32 keys and values.\r\n // The Map implementation uses private functions, and user-facing\r\n // implementations (such as Uint256ToAddressMap) are just wrappers around\r\n // the underlying Map.\r\n // This means that we can only create new EnumerableMaps for types that fit\r\n // in bytes32.\r\n\r\n struct MapEntry {\r\n bytes32 _key;\r\n bytes32 _value;\r\n }\r\n\r\n struct Map {\r\n // Storage of map keys and values\r\n MapEntry[] _entries;\r\n\r\n // Position of the entry defined by a key in the `entries` array, plus 1\r\n // because index 0 means a key is not in the map.\r\n mapping (bytes32 => uint256) _indexes;\r\n }\r\n\r\n /**\r\n * @dev Adds a key-value pair to a map, or updates the value for an existing\r\n * key. O(1).\r\n *\r\n * Returns true if the key was added to the map, that is if it was not\r\n * already present.\r\n */\r\n function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) {\r\n // We read and store the key's index to prevent multiple reads from the same storage slot\r\n uint256 keyIndex = map._indexes[key];\r\n\r\n if (keyIndex == 0) { // Equivalent to !contains(map, key)\r\n map._entries.push(MapEntry({ _key: key, _value: value }));\r\n // The entry is stored at length-1, but we add 1 to all indexes\r\n // and use 0 as a sentinel value\r\n map._indexes[key] = map._entries.length;\r\n return true;\r\n } else {\r\n map._entries[keyIndex - 1]._value = value;\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * @dev Removes a key-value pair from a map. O(1).\r\n *\r\n * Returns true if the key was removed from the map, that is if it was present.\r\n */\r\n function _remove(Map storage map, bytes32 key) private returns (bool) {\r\n // We read and store the key's index to prevent multiple reads from the same storage slot\r\n uint256 keyIndex = map._indexes[key];\r\n\r\n if (keyIndex != 0) { // Equivalent to contains(map, key)\r\n // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one\r\n // in the array, and then remove the last entry (sometimes called as 'swap and pop').\r\n // This modifies the order of the array, as noted in {at}.\r\n\r\n uint256 toDeleteIndex = keyIndex - 1;\r\n uint256 lastIndex = map._entries.length - 1;\r\n\r\n // When the entry to delete is the last one, the swap operation is unnecessary. However, since this occurs\r\n // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.\r\n\r\n MapEntry storage lastEntry = map._entries[lastIndex];\r\n\r\n // Move the last entry to the index where the entry to delete is\r\n map._entries[toDeleteIndex] = lastEntry;\r\n // Update the index for the moved entry\r\n map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based\r\n\r\n // Delete the slot where the moved entry was stored\r\n map._entries.pop();\r\n\r\n // Delete the index for the deleted slot\r\n delete map._indexes[key];\r\n\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns true if the key is in the map. O(1).\r\n */\r\n function _contains(Map storage map, bytes32 key) private view returns (bool) {\r\n return map._indexes[key] != 0;\r\n }\r\n\r\n /**\r\n * @dev Returns the number of key-value pairs in the map. O(1).\r\n */\r\n function _length(Map storage map) private view returns (uint256) {\r\n return map._entries.length;\r\n }\r\n\r\n /**\r\n * @dev Returns the key-value pair stored at position `index` in the map. O(1).\r\n *\r\n * Note that there are no guarantees on the ordering of entries inside the\r\n * array, and it may change when more entries are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) {\r\n require(map._entries.length > index, \"EnumerableMap: index out of bounds\");\r\n\r\n MapEntry storage entry = map._entries[index];\r\n return (entry._key, entry._value);\r\n }\r\n\r\n /**\r\n * @dev Tries to returns the value associated with `key`. O(1).\r\n * Does not revert if `key` is not in the map.\r\n */\r\n function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {\r\n uint256 keyIndex = map._indexes[key];\r\n if (keyIndex == 0) return (false, 0); // Equivalent to contains(map, key)\r\n return (true, map._entries[keyIndex - 1]._value); // All indexes are 1-based\r\n }\r\n\r\n /**\r\n * @dev Returns the value associated with `key`. O(1).\r\n *\r\n * Requirements:\r\n *\r\n * - `key` must be in the map.\r\n */\r\n function _get(Map storage map, bytes32 key) private view returns (bytes32) {\r\n uint256 keyIndex = map._indexes[key];\r\n require(keyIndex != 0, \"EnumerableMap: nonexistent key\"); // Equivalent to contains(map, key)\r\n return map._entries[keyIndex - 1]._value; // All indexes are 1-based\r\n }\r\n\r\n /**\r\n * @dev Same as {_get}, with a custom error message when `key` is not in the map.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {_tryGet}.\r\n */\r\n function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) {\r\n uint256 keyIndex = map._indexes[key];\r\n require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key)\r\n return map._entries[keyIndex - 1]._value; // All indexes are 1-based\r\n }\r\n\r\n // UintToAddressMap\r\n\r\n struct UintToAddressMap {\r\n Map _inner;\r\n }\r\n\r\n /**\r\n * @dev Adds a key-value pair to a map, or updates the value for an existing\r\n * key. O(1).\r\n *\r\n * Returns true if the key was added to the map, that is if it was not\r\n * already present.\r\n */\r\n function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {\r\n return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));\r\n }\r\n\r\n /**\r\n * @dev Removes a value from a set. O(1).\r\n *\r\n * Returns true if the key was removed from the map, that is if it was present.\r\n */\r\n function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {\r\n return _remove(map._inner, bytes32(key));\r\n }\r\n\r\n /**\r\n * @dev Returns true if the key is in the map. O(1).\r\n */\r\n function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {\r\n return _contains(map._inner, bytes32(key));\r\n }\r\n\r\n /**\r\n * @dev Returns the number of elements in the map. O(1).\r\n */\r\n function length(UintToAddressMap storage map) internal view returns (uint256) {\r\n return _length(map._inner);\r\n }\r\n\r\n /**\r\n * @dev Returns the element stored at position `index` in the set. O(1).\r\n * Note that there are no guarantees on the ordering of values inside the\r\n * array, and it may change when more values are added or removed.\r\n *\r\n * Requirements:\r\n *\r\n * - `index` must be strictly less than {length}.\r\n */\r\n function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {\r\n (bytes32 key, bytes32 value) = _at(map._inner, index);\r\n return (uint256(key), address(uint160(uint256(value))));\r\n }\r\n\r\n /**\r\n * @dev Tries to returns the value associated with `key`. O(1).\r\n * Does not revert if `key` is not in the map.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {\r\n (bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));\r\n return (success, address(uint160(uint256(value))));\r\n }\r\n\r\n /**\r\n * @dev Returns the value associated with `key`. O(1).\r\n *\r\n * Requirements:\r\n *\r\n * - `key` must be in the map.\r\n */\r\n function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {\r\n return address(uint160(uint256(_get(map._inner, bytes32(key)))));\r\n }\r\n\r\n /**\r\n * @dev Same as {get}, with a custom error message when `key` is not in the map.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {tryGet}.\r\n */\r\n function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) {\r\n return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage))));\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/utils/Strings.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev String operations.\r\n */\r\nlibrary Strings {\r\n /**\r\n * @dev Converts a `uint256` to its ASCII `string` representation.\r\n */\r\n function toString(uint256 value) internal pure returns (string memory) {\r\n // Inspired by OraclizeAPI's implementation - MIT licence\r\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\r\n\r\n if (value == 0) {\r\n return \"0\";\r\n }\r\n uint256 temp = value;\r\n uint256 digits;\r\n while (temp != 0) {\r\n digits++;\r\n temp /= 10;\r\n }\r\n bytes memory buffer = new bytes(digits);\r\n uint256 index = digits - 1;\r\n temp = value;\r\n while (temp != 0) {\r\n buffer[index--] = bytes1(uint8(48 + temp % 10));\r\n temp /= 10;\r\n }\r\n return string(buffer);\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/token/ERC721/ERC721.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/**\r\n * @title ERC721 Non-Fungible Token Standard basic implementation\r\n * @dev see https://eips.ethereum.org/EIPS/eip-721\r\n */\r\ncontract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable {\r\n using SafeMath for uint256;\r\n using Address for address;\r\n using EnumerableSet for EnumerableSet.UintSet;\r\n using EnumerableMap for EnumerableMap.UintToAddressMap;\r\n using Strings for uint256;\r\n\r\n // Equals to `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`\r\n // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector`\r\n bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;\r\n\r\n // Mapping from holder address to their (enumerable) set of owned tokens\r\n mapping (address => EnumerableSet.UintSet) private _holderTokens;\r\n\r\n // Enumerable mapping from token ids to their owners\r\n EnumerableMap.UintToAddressMap private _tokenOwners;\r\n\r\n // Mapping from token ID to approved address\r\n mapping (uint256 => address) private _tokenApprovals;\r\n\r\n // Mapping from owner to operator approvals\r\n mapping (address => mapping (address => bool)) private _operatorApprovals;\r\n\r\n // Token name\r\n string private _name;\r\n\r\n // Token symbol\r\n string private _symbol;\r\n\r\n // Optional mapping for token URIs\r\n mapping (uint256 => string) private _tokenURIs;\r\n\r\n // Base URI\r\n string private _baseURI;\r\n\r\n /*\r\n * bytes4(keccak256('balanceOf(address)')) == 0x70a08231\r\n * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e\r\n * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3\r\n * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc\r\n * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465\r\n * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5\r\n * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd\r\n * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e\r\n * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde\r\n *\r\n * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^\r\n * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd\r\n */\r\n bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;\r\n\r\n /*\r\n * bytes4(keccak256('name()')) == 0x06fdde03\r\n * bytes4(keccak256('symbol()')) == 0x95d89b41\r\n * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd\r\n *\r\n * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f\r\n */\r\n bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;\r\n\r\n /*\r\n * bytes4(keccak256('totalSupply()')) == 0x18160ddd\r\n * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59\r\n * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7\r\n *\r\n * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63\r\n */\r\n bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;\r\n\r\n /**\r\n * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.\r\n */\r\n constructor (string memory name_, string memory symbol_) public {\r\n _name = name_;\r\n _symbol = symbol_;\r\n\r\n // register the supported interfaces to conform to ERC721 via ERC165\r\n _registerInterface(_INTERFACE_ID_ERC721);\r\n _registerInterface(_INTERFACE_ID_ERC721_METADATA);\r\n _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-balanceOf}.\r\n */\r\n function balanceOf(address owner) public view virtual override returns (uint256) {\r\n require(owner != address(0), \"ERC721: balance query for the zero address\");\r\n return _holderTokens[owner].length();\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-ownerOf}.\r\n */\r\n function ownerOf(uint256 tokenId) public view virtual override returns (address) {\r\n return _tokenOwners.get(tokenId, \"ERC721: owner query for nonexistent token\");\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Metadata-name}.\r\n */\r\n function name() public view virtual override returns (string memory) {\r\n return _name;\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Metadata-symbol}.\r\n */\r\n function symbol() public view virtual override returns (string memory) {\r\n return _symbol;\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Metadata-tokenURI}.\r\n */\r\n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\r\n require(_exists(tokenId), \"ERC721Metadata: URI query for nonexistent token\");\r\n\r\n string memory _tokenURI = _tokenURIs[tokenId];\r\n string memory base = baseURI();\r\n\r\n // If there is no base URI, return the token URI.\r\n if (bytes(base).length == 0) {\r\n return _tokenURI;\r\n }\r\n // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).\r\n if (bytes(_tokenURI).length > 0) {\r\n return string(abi.encodePacked(base, _tokenURI));\r\n }\r\n // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.\r\n return string(abi.encodePacked(base, tokenId.toString()));\r\n }\r\n\r\n /**\r\n * @dev Returns the base URI set via {_setBaseURI}. This will be\r\n * automatically added as a prefix in {tokenURI} to each token's URI, or\r\n * to the token ID if no specific URI is set for that token ID.\r\n */\r\n function baseURI() public view virtual returns (string memory) {\r\n return _baseURI;\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.\r\n */\r\n function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {\r\n return _holderTokens[owner].at(index);\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Enumerable-totalSupply}.\r\n */\r\n function totalSupply() public view virtual override returns (uint256) {\r\n // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds\r\n return _tokenOwners.length();\r\n }\r\n\r\n /**\r\n * @dev See {IERC721Enumerable-tokenByIndex}.\r\n */\r\n function tokenByIndex(uint256 index) public view virtual override returns (uint256) {\r\n (uint256 tokenId, ) = _tokenOwners.at(index);\r\n return tokenId;\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-approve}.\r\n */\r\n function approve(address to, uint256 tokenId) public virtual override {\r\n address owner = ERC721.ownerOf(tokenId);\r\n require(to != owner, \"ERC721: approval to current owner\");\r\n\r\n require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()),\r\n \"ERC721: approve caller is not owner nor approved for all\"\r\n );\r\n\r\n _approve(to, tokenId);\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-getApproved}.\r\n */\r\n function getApproved(uint256 tokenId) public view virtual override returns (address) {\r\n require(_exists(tokenId), \"ERC721: approved query for nonexistent token\");\r\n\r\n return _tokenApprovals[tokenId];\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-setApprovalForAll}.\r\n */\r\n function setApprovalForAll(address operator, bool approved) public virtual override {\r\n require(operator != _msgSender(), \"ERC721: approve to caller\");\r\n\r\n _operatorApprovals[_msgSender()][operator] = approved;\r\n emit ApprovalForAll(_msgSender(), operator, approved);\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-isApprovedForAll}.\r\n */\r\n function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {\r\n return _operatorApprovals[owner][operator];\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-transferFrom}.\r\n */\r\n function transferFrom(address from, address to, uint256 tokenId) public virtual override {\r\n //solhint-disable-next-line max-line-length\r\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: transfer caller is not owner nor approved\");\r\n\r\n _transfer(from, to, tokenId);\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-safeTransferFrom}.\r\n */\r\n function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {\r\n safeTransferFrom(from, to, tokenId, \"\");\r\n }\r\n\r\n /**\r\n * @dev See {IERC721-safeTransferFrom}.\r\n */\r\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {\r\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: transfer caller is not owner nor approved\");\r\n _safeTransfer(from, to, tokenId, _data);\r\n }\r\n\r\n /**\r\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\r\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\r\n *\r\n * `_data` is additional data, it has no specified format and it is sent in call to `to`.\r\n *\r\n * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.\r\n * implement alternative mechanisms to perform token transfer, such as signature-based.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must exist and be owned by `from`.\r\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {\r\n _transfer(from, to, tokenId);\r\n require(_checkOnERC721Received(from, to, tokenId, _data), \"ERC721: transfer to non ERC721Receiver implementer\");\r\n }\r\n\r\n /**\r\n * @dev Returns whether `tokenId` exists.\r\n *\r\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\r\n *\r\n * Tokens start existing when they are minted (`_mint`),\r\n * and stop existing when they are burned (`_burn`).\r\n */\r\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\r\n return _tokenOwners.contains(tokenId);\r\n }\r\n\r\n /**\r\n * @dev Returns whether `spender` is allowed to manage `tokenId`.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {\r\n require(_exists(tokenId), \"ERC721: operator query for nonexistent token\");\r\n address owner = ERC721.ownerOf(tokenId);\r\n return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender));\r\n }\r\n\r\n /**\r\n * @dev Safely mints `tokenId` and transfers it to `to`.\r\n *\r\n * Requirements:\r\n d*\r\n * - `tokenId` must not exist.\r\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _safeMint(address to, uint256 tokenId) internal virtual {\r\n _safeMint(to, tokenId, \"\");\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is\r\n * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.\r\n */\r\n function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {\r\n _mint(to, tokenId);\r\n require(_checkOnERC721Received(address(0), to, tokenId, _data), \"ERC721: transfer to non ERC721Receiver implementer\");\r\n }\r\n\r\n /**\r\n * @dev Mints `tokenId` and transfers it to `to`.\r\n *\r\n * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must not exist.\r\n * - `to` cannot be the zero address.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _mint(address to, uint256 tokenId) internal virtual {\r\n require(to != address(0), \"ERC721: mint to the zero address\");\r\n require(!_exists(tokenId), \"ERC721: token already minted\");\r\n\r\n _beforeTokenTransfer(address(0), to, tokenId);\r\n\r\n _holderTokens[to].add(tokenId);\r\n\r\n _tokenOwners.set(tokenId, to);\r\n\r\n emit Transfer(address(0), to, tokenId);\r\n }\r\n\r\n /**\r\n * @dev Destroys `tokenId`.\r\n * The approval is cleared when the token is burned.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _burn(uint256 tokenId) internal virtual {\r\n address owner = ERC721.ownerOf(tokenId); // internal owner\r\n\r\n _beforeTokenTransfer(owner, address(0), tokenId);\r\n\r\n // Clear approvals\r\n _approve(address(0), tokenId);\r\n\r\n // Clear metadata (if any)\r\n if (bytes(_tokenURIs[tokenId]).length != 0) {\r\n delete _tokenURIs[tokenId];\r\n }\r\n\r\n _holderTokens[owner].remove(tokenId);\r\n\r\n _tokenOwners.remove(tokenId);\r\n\r\n emit Transfer(owner, address(0), tokenId);\r\n }\r\n\r\n /**\r\n * @dev Transfers `tokenId` from `from` to `to`.\r\n * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\r\n *\r\n * Requirements:\r\n *\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must be owned by `from`.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _transfer(address from, address to, uint256 tokenId) internal virtual {\r\n require(ERC721.ownerOf(tokenId) == from, \"ERC721: transfer of token that is not own\"); // internal owner\r\n require(to != address(0), \"ERC721: transfer to the zero address\");\r\n\r\n _beforeTokenTransfer(from, to, tokenId);\r\n\r\n // Clear approvals from the previous owner\r\n _approve(address(0), tokenId);\r\n\r\n _holderTokens[from].remove(tokenId);\r\n _holderTokens[to].add(tokenId);\r\n\r\n _tokenOwners.set(tokenId, to);\r\n\r\n emit Transfer(from, to, tokenId);\r\n }\r\n\r\n /**\r\n * @dev Sets `_tokenURI` as the tokenURI of `tokenId`.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {\r\n require(_exists(tokenId), \"ERC721Metadata: URI set of nonexistent token\");\r\n _tokenURIs[tokenId] = _tokenURI;\r\n }\r\n\r\n /**\r\n * @dev Internal function to set the base URI for all token IDs. It is\r\n * automatically added as a prefix to the value returned in {tokenURI},\r\n * or to the token ID if {tokenURI} is empty.\r\n */\r\n function _setBaseURI(string memory baseURI_) internal virtual {\r\n _baseURI = baseURI_;\r\n }\r\n\r\n /**\r\n * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.\r\n * The call is not executed if the target address is not a contract.\r\n *\r\n * @param from address representing the previous owner of the given token ID\r\n * @param to target address that will receive the tokens\r\n * @param tokenId uint256 ID of the token to be transferred\r\n * @param _data bytes optional data to send along with the call\r\n * @return bool whether the call correctly returned the expected magic value\r\n */\r\n function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)\r\n private returns (bool)\r\n {\r\n if (!to.isContract()) {\r\n return true;\r\n }\r\n bytes memory returndata = to.functionCall(abi.encodeWithSelector(\r\n IERC721Receiver(to).onERC721Received.selector,\r\n _msgSender(),\r\n from,\r\n tokenId,\r\n _data\r\n ), \"ERC721: transfer to non ERC721Receiver implementer\");\r\n bytes4 retval = abi.decode(returndata, (bytes4));\r\n return (retval == _ERC721_RECEIVED);\r\n }\r\n\r\n /**\r\n * @dev Approve `to` to operate on `tokenId`\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function _approve(address to, uint256 tokenId) internal virtual {\r\n _tokenApprovals[tokenId] = to;\r\n emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner\r\n }\r\n\r\n /**\r\n * @dev Hook that is called before any token transfer. This includes minting\r\n * and burning.\r\n *\r\n * Calling conditions:\r\n *\r\n * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be\r\n * transferred to `to`.\r\n * - When `from` is zero, `tokenId` will be minted for `to`.\r\n * - When `to` is zero, ``from``'s `tokenId` will be burned.\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n *\r\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\r\n */\r\n function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }\r\n}\r\n\r\n// File: @openzeppelin/contracts/access/Ownable.sol\r\n\r\n\r\n\r\npragma solidity >=0.6.0 <0.8.0;\r\n\r\n/**\r\n * @dev Contract module which provides a basic access control mechanism, where\r\n * there is an account (an owner) that can be granted exclusive access to\r\n * specific functions.\r\n *\r\n * By default, the owner account will be the one that deploys the contract. This\r\n * can later be changed with {transferOwnership}.\r\n *\r\n * This module is used through inheritance. It will make available the modifier\r\n * `onlyOwner`, which can be applied to your functions to restrict their use to\r\n * the owner.\r\n */\r\nabstract contract Ownable is Context {\r\n address private _owner;\r\n\r\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r\n\r\n /**\r\n * @dev Initializes the contract setting the deployer as the initial owner.\r\n */\r\n constructor () internal {\r\n address msgSender = _msgSender();\r\n _owner = msgSender;\r\n emit OwnershipTransferred(address(0), msgSender);\r\n }\r\n\r\n /**\r\n * @dev Returns the address of the current owner.\r\n */\r\n function owner() public view virtual returns (address) {\r\n return _owner;\r\n }\r\n\r\n /**\r\n * @dev Throws if called by any account other than the owner.\r\n */\r\n modifier onlyOwner() {\r\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\r\n _;\r\n }\r\n\r\n /**\r\n * @dev Leaves the contract without owner. It will not be possible to call\r\n * `onlyOwner` functions anymore. Can only be called by the current owner.\r\n *\r\n * NOTE: Renouncing ownership will leave the contract without an owner,\r\n * thereby removing any functionality that is only available to the owner.\r\n */\r\n function renounceOwnership() public virtual onlyOwner {\r\n emit OwnershipTransferred(_owner, address(0));\r\n _owner = address(0);\r\n }\r\n\r\n /**\r\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\r\n * Can only be called by the current owner.\r\n */\r\n function transferOwnership(address newOwner) public virtual onlyOwner {\r\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\r\n emit OwnershipTransferred(_owner, newOwner);\r\n _owner = newOwner;\r\n }\r\n}\r\n\r\n// File: contracts/BoredApeYachtClub.sol\r\n\r\n\r\npragma solidity ^0.7.0;\r\n\r\n\r\n\r\n/**\r\n * @title BoredApeYachtClub contract\r\n * @dev Extends ERC721 Non-Fungible Token Standard basic implementation\r\n */\r\ncontract BoredApeYachtClub is ERC721, Ownable {\r\n using SafeMath for uint256;\r\n\r\n string public BAYC_PROVENANCE = \"\";\r\n\r\n uint256 public startingIndexBlock;\r\n\r\n uint256 public startingIndex;\r\n\r\n uint256 public constant apePrice = 80000000000000000; //0.08 ETH\r\n\r\n uint public constant maxApePurchase = 20;\r\n\r\n uint256 public MAX_APES;\r\n\r\n bool public saleIsActive = false;\r\n\r\n uint256 public REVEAL_TIMESTAMP;\r\n\r\n constructor(string memory name, string memory symbol, uint256 maxNftSupply, uint256 saleStart) ERC721(name, symbol) {\r\n MAX_APES = maxNftSupply;\r\n REVEAL_TIMESTAMP = saleStart + (86400 * 9);\r\n }\r\n\r\n function withdraw() public onlyOwner {\r\n uint balance = address(this).balance;\r\n msg.sender.transfer(balance);\r\n }\r\n\r\n /**\r\n * Set some Bored Apes aside\r\n */\r\n function reserveApes() public onlyOwner { \r\n uint supply = totalSupply();\r\n uint i;\r\n for (i = 0; i < 30; i++) {\r\n _safeMint(msg.sender, supply + i);\r\n }\r\n }\r\n\r\n /**\r\n * DM Gargamel in Discord that you're standing right behind him.\r\n */\r\n function setRevealTimestamp(uint256 revealTimeStamp) public onlyOwner {\r\n REVEAL_TIMESTAMP = revealTimeStamp;\r\n } \r\n\r\n /* \r\n * Set provenance once it's calculated\r\n */\r\n function setProvenanceHash(string memory provenanceHash) public onlyOwner {\r\n BAYC_PROVENANCE = provenanceHash;\r\n }\r\n\r\n function setBaseURI(string memory baseURI) public onlyOwner {\r\n _setBaseURI(baseURI);\r\n }\r\n\r\n /*\r\n * Pause sale if active, make active if paused\r\n */\r\n function flipSaleState() public onlyOwner {\r\n saleIsActive = !saleIsActive;\r\n }\r\n\r\n /**\r\n * Mints Bored Apes\r\n */\r\n function mintApe(uint numberOfTokens) public payable {\r\n require(saleIsActive, \"Sale must be active to mint Ape\");\r\n require(numberOfTokens <= maxApePurchase, \"Can only mint 20 tokens at a time\");\r\n require(totalSupply().add(numberOfTokens) <= MAX_APES, \"Purchase would exceed max supply of Apes\");\r\n require(apePrice.mul(numberOfTokens) <= msg.value, \"Ether value sent is not correct\");\r\n \r\n for(uint i = 0; i < numberOfTokens; i++) {\r\n uint mintIndex = totalSupply();\r\n if (totalSupply() < MAX_APES) {\r\n _safeMint(msg.sender, mintIndex);\r\n }\r\n }\r\n\r\n // If we haven't set the starting index and this is either 1) the last saleable token or 2) the first token to be sold after\r\n // the end of pre-sale, set the starting index block\r\n if (startingIndexBlock == 0 && (totalSupply() == MAX_APES || block.timestamp >= REVEAL_TIMESTAMP)) {\r\n startingIndexBlock = block.number;\r\n } \r\n }\r\n\r\n /**\r\n * Set the starting index for the collection\r\n */\r\n function setStartingIndex() public {\r\n require(startingIndex == 0, \"Starting index is already set\");\r\n require(startingIndexBlock != 0, \"Starting index block must be set\");\r\n \r\n startingIndex = uint(blockhash(startingIndexBlock)) % MAX_APES;\r\n // Just a sanity case in the worst case if this function is called late (EVM only stores last 256 block hashes)\r\n if (block.number.sub(startingIndexBlock) > 255) {\r\n startingIndex = uint(blockhash(block.number - 1)) % MAX_APES;\r\n }\r\n // Prevent default sequence\r\n if (startingIndex == 0) {\r\n startingIndex = startingIndex.add(1);\r\n }\r\n }\r\n\r\n /**\r\n * Set the starting index block for the collection, essentially unblocking\r\n * setting starting index\r\n */\r\n function emergencySetStartingIndexBlock() public onlyOwner {\r\n require(startingIndex == 0, \"Starting index is already set\");\r\n \r\n startingIndexBlock = block.number;\r\n }\r\n}","ABI":"[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"maxNftSupply\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"saleStart\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"approved\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"BAYC_PROVENANCE\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"MAX_APES\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"REVEAL_TIMESTAMP\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"apePrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"baseURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"emergencySetStartingIndexBlock\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"flipSaleState\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getApproved\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"maxApePurchase\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"numberOfTokens\",\"type\":\"uint256\"}],\"name\":\"mintApe\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"reserveApes\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"saleIsActive\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"baseURI\",\"type\":\"string\"}],\"name\":\"setBaseURI\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"provenanceHash\",\"type\":\"string\"}],\"name\":\"setProvenanceHash\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"revealTimeStamp\",\"type\":\"uint256\"}],\"name\":\"setRevealTimestamp\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"setStartingIndex\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"startingIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"startingIndexBlock\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenByIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenOfOwnerByIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"tokenURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]","ContractName":"BoredApeYachtClub","CompilerVersion":"v0.7.0+commit.9e61f92b","OptimizationUsed":"0","Runs":"200","ConstructorArguments":"000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000006080e6d70000000000000000000000000000000000000000000000000000000000000011426f7265644170655961636874436c756200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044241594300000000000000000000000000000000000000000000000000000000","EVMVersion":"Default","Library":"","LicenseType":"MIT","Proxy":"0","Implementation":"","SwarmSource":"ipfs://b0e64d1fa6c4dbeb9c6f54607d7e1996943fe27624a80652f57b53fda084621b"}]} diff --git a/tests/mock_responses/get_contract_response_json.json b/tests/mock_responses/get_contract_response_json.json new file mode 100644 index 0000000..2865353 --- /dev/null +++ b/tests/mock_responses/get_contract_response_json.json @@ -0,0 +1 @@ +{"status": "1", "message": "OK", "result": [{"ABI": "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"subtractedValue\",\"type\":\"uint256\"}],\"name\":\"decreaseAllowance\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"addedValue\",\"type\":\"uint256\"}],\"name\":\"increaseAllowance\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", "ContractName": "LOVEYOU", "CompilerVersion": "v0.8.9+commit.e5eed63a", "OptimizationUsed": "0", "Runs": "200", "ConstructorArguments": "", "EVMVersion": "Default", "Library": "", "LicenseType": "", "Proxy": "0", "Implementation": "", "SwarmSource": ""}]} diff --git a/tests/mock_responses/get_contract_response_json_source_code.json b/tests/mock_responses/get_contract_response_json_source_code.json new file mode 100644 index 0000000..c54ad03 --- /dev/null +++ b/tests/mock_responses/get_contract_response_json_source_code.json @@ -0,0 +1,41 @@ +{{ + "language": "Solidity", + "sources": { + "contract-0a868d3251.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.9;\n\nimport \"@openzeppelin/contracts@4.9.2/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts@4.9.2/access/Ownable.sol\";\n\n/// @custom:security-contact security@loveyou.pw\ncontract LOVEYOU is ERC20, Ownable {\n constructor() ERC20(\"LOVE YOU\", \"LOVEYOU\") {\n _mint(msg.sender, 1000000 * 10 ** decimals());\n }\n}\n" + }, + "@openzeppelin/contracts@4.9.2/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby disabling any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" + }, + "@openzeppelin/contracts@4.9.2/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the default value returned by this function, unless\n * it's overridden.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(address from, address to, uint256 amount) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\n // decrementing then incrementing.\n _balances[to] += amount;\n }\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n unchecked {\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\n _balances[account] += amount;\n }\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n // Overflow not possible: amount <= accountBalance <= totalSupply.\n _totalSupply -= amount;\n }\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(address owner, address spender, uint256 amount) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}\n}\n" + }, + "@openzeppelin/contracts@4.9.2/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n" + }, + "@openzeppelin/contracts@4.9.2/token/ERC20/extensions/IERC20Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n" + }, + "@openzeppelin/contracts@4.9.2/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n" + } + }, + "settings": { + "optimizer": { + "enabled": false, + "runs": 200 + }, + "outputSelection": { + "*": { + "*": [ + "evm.bytecode", + "evm.deployedBytecode", + "devdoc", + "userdoc", + "metadata", + "abi" + ] + } + } + } +}} diff --git a/tests/mock_responses/get_contract_response_not_verified.json b/tests/mock_responses/get_contract_response_not_verified.json new file mode 100644 index 0000000..10017e0 --- /dev/null +++ b/tests/mock_responses/get_contract_response_not_verified.json @@ -0,0 +1 @@ +{"status":"1","message":"OK","result":[{"SourceCode":"","ABI":"Contract source code not verified","ContractName":"","CompilerVersion":"","OptimizationUsed":"","Runs":"","ConstructorArguments":"","EVMVersion":"Default","Library":"","LicenseType":"Unknown","Proxy":"0","Implementation":"","SwarmSource":""}]} diff --git a/tests/test_dependency.py b/tests/test_dependency.py new file mode 100644 index 0000000..317ee6a --- /dev/null +++ b/tests/test_dependency.py @@ -0,0 +1,45 @@ +import pytest +from ape.exceptions import ProjectError + +from ape_etherscan.dependency import EtherscanDependency + + +@pytest.mark.parametrize( + "verification_type,contract_address,expected_name", + [ + ("flattened", "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", "BoredApeYachtClub"), + ("json", "0x000075Dc60EdE898f11b0d5C6cA31D7A6D050eeD", "LOVEYOU"), + ], +) +def test_dependency(mock_backend, verification_type, expected_name, contract_address): + ecosystem = "ethereum" + network = "mainnet" + mock_backend.set_network(ecosystem, network) + mock_backend.setup_mock_get_contract_type_response(f"get_contract_response_{verification_type}") + + dependency = EtherscanDependency( + name="Apes", + etherscan=contract_address, + ecosystem=ecosystem, + network=network, + ) + actual = dependency.extract_manifest() + assert dependency.version_id == f"{ecosystem}_{network}" + assert f"{expected_name}.sol" in actual.sources + assert actual.compilers[0].name == "Solidity" + assert not actual.compilers[0].settings["optimizer"]["enabled"] + assert actual.compilers[0].contractTypes == [expected_name] + + +def test_dependency_not_verified(mock_backend): + mock_backend.set_network("ethereum", "mainnet") + mock_backend.setup_mock_get_contract_type_response("get_contract_response_not_verified") + dependency = EtherscanDependency( + name="Apes", + etherscan="0x5777d92f208679db4b9778590fa3cab3ac9e2168", + ecosystem="ethereum", + network="mainnet", + ) + expected = "Etherscan dependency 'Apes' not verified." + with pytest.raises(ProjectError, match=expected): + dependency.extract_manifest() diff --git a/tests/test_etherscan.py b/tests/test_etherscan.py index 72552c6..8d5148b 100644 --- a/tests/test_etherscan.py +++ b/tests/test_etherscan.py @@ -9,7 +9,9 @@ # A map of each mock response to its contract name for testing `get_contract_type()`. EXPECTED_CONTRACT_NAME_MAP = { - "get_contract_response": "BoredApeYachtClub", + "get_contract_response_flattened": "BoredApeYachtClub", + "get_contract_response_json": "BoredApeYachtClub", + "get_contract_response_not_verified": "", "get_proxy_contract_response": "MIM-UST-f", "get_vyper_contract_response": "yvDAI", } @@ -155,7 +157,7 @@ def test_get_contract_type_ecosystems_and_networks( ): # This test parametrizes getting contract types across ecosystem / network combos mock_backend.set_network(ecosystem, network) - response = mock_backend.setup_mock_get_contract_type_response("get_contract_response") + response = mock_backend.setup_mock_get_contract_type_response("get_contract_response_flattened") explorer = get_explorer(ecosystem, network) actual = explorer.get_contract_type(response.expected_address) contract_type_from_lowered_address = explorer.get_contract_type(