{ "language": "Solidity", "sources": { "contracts/Tokens/RAIR721_Contract.sol": { "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"openzeppelin-v4.7.1/token/ERC721/ERC721.sol\";\nimport \"openzeppelin-v4.7.1/access/AccessControl.sol\";\nimport \"openzeppelin-v4.7.1/utils/introspection/ERC165.sol\";\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"openzeppelin-v4.7.1/utils/Strings.sol\";\nimport \"./IERC2981.sol\";\nimport \"./IRAIR721_Contract.sol\";\n\n/// @title Extended ERC721 contract for the RAIR system\n/// @notice Uses ERC2981 and ERC165 for standard royalty info\n/// @notice Uses AccessControl for the minting mechanisms\n/// @author Juan M. Sanchez M.\n/// @dev Ideally generated by a RAIR Token Factory\ncontract RAIR721_Contract is\n IERC2981,\n ERC165,\n IRAIR721_Contract,\n ERC721,\n AccessControl,\n ReentrancyGuard\n{\n // Allows the conversion of numbers to strings (used in the token URI functions)\n using Strings for uint;\n\n // Auxiliary struct used to avoid Stack too deep errors\n struct rangeData {\n uint rangeLength;\n uint price;\n uint tokensAllowed;\n uint lockedTokens;\n string name;\n }\n\n mapping(uint => uint) public tokenToRange;\n mapping(uint => uint) public rangeToCollection;\n\n //URIs\n mapping(uint => string) internal uniqueTokenURI;\n mapping(uint => string) internal collectionURI;\n mapping(uint => string) internal rangeURI;\n mapping(uint => bool) internal appendTokenIndexToCollectionURI;\n mapping(uint => bool) internal appendTokenIndexToRangeURI;\n\n string internal baseURI;\n string internal contractMetadataURI;\n\n bool appendTokenIndexToContractURI;\n bool _requireTrader;\n\n range[] private _ranges;\n collection[] private _collections;\n\n // Roles\n bytes32 public constant MINTER = keccak256(\"MINTER\");\n bytes32 public constant TRADER = keccak256(\"TRADER\");\n\n address public owner;\n address public factory;\n string private _symbol;\n uint16 private _royaltyFee;\n string private _metadataExtension;\n\n /// @notice\tMakes sure the collection exists before doing changes to it\n /// @param\tcollectionID\tCollection to verify\n modifier collectionExists(uint collectionID) {\n require(\n _collections.length > collectionID,\n \"RAIR ERC721: Collection does not exist\"\n );\n _;\n }\n\n /// @notice\tMakes sure the range exists\n /// @param\trangeIndex\tRange to verify\n modifier rangeExists(uint rangeIndex) {\n require(\n _ranges.length > rangeIndex,\n \"RAIR ERC721: Range does not exist\"\n );\n _;\n }\n\n /// @notice\tSets up the role system from AccessControl\n /// @dev\tRAIR is the default symbol for the token, this can be updated with setTokenSymbol\n /// @param\t_contractName\tName of the contract\n /// @param\t_creatorAddress\tAddress of the creator of the contract\n constructor(string memory _contractName, address _creatorAddress)\n ERC721(_contractName, \"RAIR\")\n {\n factory = msg.sender;\n _symbol = \"RAIR\";\n _royaltyFee = 30000;\n _setupRole(DEFAULT_ADMIN_ROLE, _creatorAddress);\n _setupRole(MINTER, _creatorAddress);\n _setupRole(TRADER, _creatorAddress);\n _requireTrader = false;\n owner = _creatorAddress;\n }\n\n /// @notice Updates the metadata extension added at the end of all tokens\n /// @dev Must include the . before the extension\n /// @param extension Extension to be added at the end of all contract wide tokens\n function setMetadataExtension(string calldata extension) external onlyRole(DEFAULT_ADMIN_ROLE) {\n require(bytes(extension)[0] == '.', \"RAIR ERC721: Extension must start with a '.'\");\n _metadataExtension = extension;\n emit UpdatedURIExtension(_metadataExtension);\n }\n\n /// @notice \tTransfers the ownership of a contract to a new address\n /// @param \tnewOwner \tAddress of the new owner of the contract\n function transferOwnership(address newOwner)\n public\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n _grantRole(DEFAULT_ADMIN_ROLE, newOwner);\n owner = newOwner;\n renounceRole(DEFAULT_ADMIN_ROLE, msg.sender);\n }\n\n /// @notice \tUpdates the royalty fee used by the 2981 standard\n /// @param \tnewRoyalty \tPercentage that should be sent to the owner of the contract (3 decimals, 30% = 30000)\n function setRoyaltyFee(uint16 newRoyalty)\n public\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n _royaltyFee = newRoyalty;\n }\n\n /// @notice \tUpdates the token symbol\n /// @param \tnewSymbol \tNew symbol to be returned from the symbol() function\n function setTokenSymbol(string calldata newSymbol)\n external\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n _symbol = newSymbol;\n }\n\n /// @notice \tReturns the symbol for this contract\n /// @dev \tBy default, the symbol is RAIR\n function symbol() public view override returns (string memory) {\n return _symbol;\n }\n\n /// @notice \tEnables or disables the requirement of the TRADER role to do NFT transfers\n function requireTraderRole(bool required) public onlyRole(DEFAULT_ADMIN_ROLE) {\n _requireTrader = required;\n }\n\n /// @notice \tEmits an event that OpenSea recognizes as a signal to never update the metadata for this token\n /// @dev \tThe metadata can still be updated, but OpenSea won't update it on their platform\n /// @param \ttokenId \tIdentifier of the token to be frozen\n function freezeMetadataOpensea(uint tokenId) public onlyRole(DEFAULT_ADMIN_ROLE) {\n emit PermanentURI(tokenURI(tokenId), tokenId);\n }\n\n /// @notice \tUpdates the URL that OpenSea uses to fetch the contract's metadata\n /// @param \tnewURI \tURL of the metadata for the token\n function setContractURI(string calldata newURI)\n external\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n contractMetadataURI = newURI;\n emit UpdatedContractURI(newURI);\n }\n\n /// @notice \tReturns the metadata for the entire contract\n /// @dev \tNot the NFTs, this is information about the contract itself\n function contractURI() public view returns (string memory) {\n return contractMetadataURI;\n }\n\n /// @notice\tSets the Base URI for ALL tokens\n /// @dev\tCan be overriden by the collection-wide URI or the specific token URI\n /// @param\tnewURI\tURI to be used\n function setBaseURI(string calldata newURI, bool appendTokenIndex)\n external\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n baseURI = newURI;\n appendTokenIndexToContractURI = appendTokenIndex;\n emit UpdatedBaseURI(newURI, appendTokenIndex, _metadataExtension);\n }\n\n /// @notice\tOverridden function from the ERC721 contract that returns our\n ///\t\t\tvariable base URI instead of the hardcoded URI\n function _baseURI() internal view override(ERC721) returns (string memory) {\n return baseURI;\n }\n\n /// @notice\tUpdates the unique URI of a token, but in a single transaction\n /// @dev\tUses the single function so it also emits an event\n /// @param\ttokenIds\tToken Indexes that will be given an URI\n /// @param\tnewURIs\t\tNew URIs to be set\n function setUniqueURIBatch(\n uint[] calldata tokenIds,\n string[] calldata newURIs\n ) external onlyRole(DEFAULT_ADMIN_ROLE) {\n require(\n tokenIds.length == newURIs.length,\n \"RAIR ERC721: Token IDs and URIs should have the same length\"\n );\n for (uint i = 0; i < tokenIds.length; i++) {\n setUniqueURI(tokenIds[i], newURIs[i]);\n }\n }\n\n /// @notice\tGives an individual token an unique URI\n /// @dev\tEmits an event so there's provenance\n /// @param\ttokenId\tToken Index that will be given an URI\n /// @param\tnewURI\tNew URI to be given\n function setUniqueURI(uint tokenId, string calldata newURI)\n public\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n uniqueTokenURI[tokenId] = newURI;\n emit UpdatedTokenURI(tokenId, newURI);\n }\n\n /// @notice\tGives all tokens within a range a specific URI\n /// @dev\tEmits an event so there's provenance\n /// @param\trangeId\tToken Index that will be given an URI\n /// @param\tnewURI\t\t New URI to be given\n function setRangeURI(\n uint rangeId,\n string calldata newURI,\n bool appendTokenIndex\n ) public onlyRole(DEFAULT_ADMIN_ROLE) {\n rangeURI[rangeId] = newURI;\n appendTokenIndexToRangeURI[rangeId] = appendTokenIndex;\n emit UpdatedRangeURI(rangeId, newURI, appendTokenIndex, _metadataExtension);\n }\n\n /// @notice\tGives all tokens within a collection a specific URI\n /// @dev\tEmits an event so there's provenance\n /// @param\tcollectionId\tToken Index that will be given an URI\n /// @param\tnewURI\t\tNew URI to be given\n function setCollectionURI(\n uint collectionId,\n string calldata newURI,\n bool appendTokenIndex\n ) public onlyRole(DEFAULT_ADMIN_ROLE) {\n collectionURI[collectionId] = newURI;\n appendTokenIndexToCollectionURI[collectionId] = appendTokenIndex;\n emit UpdatedProductURI(collectionId, newURI, appendTokenIndex, _metadataExtension);\n }\n\n\tfunction tokenToCollection(uint tokenId) internal view returns (uint) {\n\t\treturn rangeToCollection[tokenToRange[tokenId]];\n\t}\n\n /// @notice\tReturns a token's URI\n /// @dev\tWill return unique token URI or product URI or contract URI\n /// @param\ttokenId\t\tToken Index to look for\n function tokenURI(uint tokenId)\n public\n view\n override(ERC721)\n returns (string memory)\n {\n // Unique token URI\n string memory URI = uniqueTokenURI[tokenId];\n if (bytes(URI).length > 0) {\n return URI;\n }\n\n // Range wide URI\n URI = rangeURI[tokenToRange[tokenId]];\n if (bytes(URI).length > 0) {\n if (appendTokenIndexToRangeURI[tokenToRange[tokenId]]) {\n return\n string(\n abi.encodePacked(\n URI,\n tokenToCollectionIndex(tokenId).toString(),\n _metadataExtension\n )\n );\n }\n return URI;\n }\n\n // Collection wide URI\n URI = collectionURI[tokenToCollection(tokenId)];\n if (bytes(URI).length > 0) {\n if (appendTokenIndexToCollectionURI[tokenToCollection(tokenId)]) {\n return\n string(\n abi.encodePacked(\n URI,\n tokenToCollectionIndex(tokenId).toString(),\n _metadataExtension\n )\n );\n }\n return URI;\n }\n\n URI = baseURI;\n if (appendTokenIndexToContractURI) {\n return\n string(\n abi.encodePacked(\n URI,\n tokenId.toString(),\n _metadataExtension\n )\n );\n }\n return URI;\n }\n\n /// @notice\tCreates a subdivision of tokens inside the contract (collection is the same as product)\n /// @dev\tThe collections are generated sequentially, there can be no gaps between collections\n /// @param\t_collectionName \tName of the collection\n /// @param\t_copies\t\t\t\tAmount of tokens inside the collection\n function createProduct(string memory _collectionName, uint _copies)\n public\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n uint lastTokenFromPreviousCollection;\n if (_collections.length != 0) {\n lastTokenFromPreviousCollection =\n _collections[_collections.length - 1].endingToken +\n 1;\n }\n\n collection storage newCollection = _collections.push();\n\n newCollection.startingToken = lastTokenFromPreviousCollection;\n // -1 because we include the initial token\n newCollection.endingToken = newCollection.startingToken + _copies - 1;\n newCollection.name = string(_collectionName);\n\n emit CreatedCollection(\n _collections.length - 1,\n _collectionName,\n lastTokenFromPreviousCollection,\n _copies\n );\n }\n\n /// @notice This function will create ranges in batches\n /// @dev \tThere isn't any gas savings here\n /// @param\tcollectionId\tContains the identification for the product\n /// @param\tdata \t\t\tAn array with the data for all the ranges that we want to implement\n function createRangeBatch(uint collectionId, rangeData[] calldata data)\n external\n onlyRole(DEFAULT_ADMIN_ROLE)\n collectionExists(collectionId)\n {\n require(data.length > 0, \"RAIR ERC721: Empty array\");\n collection storage selectedCollection = _collections[collectionId];\n for (uint i = 0; i < data.length; i++) {\n _createRange(\n collectionId,\n data[i].rangeLength,\n data[i].tokensAllowed,\n data[i].lockedTokens,\n data[i].price,\n data[i].name,\n selectedCollection\n );\n }\n }\n\n /// @notice Creates a range inside a collection\n /// @dev \tThis function is only available to an account with the `DEFAULT_ADMIN_ROLE` role\n /// @dev \tThis function require thar the collection ID match a valid collection\n /// @param\tcollectionId\tContains the identification for the product\n /// @param\trangeLength\t\tNumber of tokens to be contained in this new range\n /// @param \tprice \t\t\tContains the selling price for the range of NFT\n /// @param \ttokensAllowed \tContains all the allowed NFT tokens in the range that are available for sell\n /// @param \tlockedTokens \tContains all the NFT tokens in the range that are unavailable for sell\n /// @param \tname \t\t\tContains the name for the created NFT collection range\n function createRange(\n uint collectionId,\n uint rangeLength,\n uint price,\n uint tokensAllowed,\n uint lockedTokens,\n string calldata name\n ) external onlyRole(DEFAULT_ADMIN_ROLE) collectionExists(collectionId) {\n collection storage selectedCollection = _collections[collectionId];\n _createRange(\n collectionId,\n rangeLength,\n price,\n tokensAllowed,\n lockedTokens,\n name,\n selectedCollection\n );\n }\n\n /// @notice This is a internal function that will create the NFT range if the requirements are met\n /// @param\tcollectionIndex\t\tCollection identifier\n /// @param\t_rangeLength\t\tNumber of NFTs in the range\n /// @param \t_allowedTokens \t\tContains all the allowed NFT tokens in the range that are available for sell\n /// @param \t_lockedTokens \t\tContains all the NFT tokens in the range that are unavailable for sell\n /// @param \t_price \t\t\t\tContains the selling price for the range of NFT\n /// @param \t_name \t\t\t\tContains the name for the created NFT collection range\n function _createRange(\n uint collectionIndex,\n uint _rangeLength,\n uint _allowedTokens,\n uint _lockedTokens,\n uint _price,\n string calldata _name,\n collection storage selectedCollection\n ) internal {\n uint nextSequentialToken = selectedCollection.startingToken;\n if (selectedCollection.rangeList.length > 0) {\n nextSequentialToken = (\n _ranges[\n selectedCollection.rangeList[\n selectedCollection.rangeList.length - 1\n ]\n ]\n ).rangeEnd;\n nextSequentialToken++;\n }\n\n // -1 because it includes the first token inside the range\n require(\n nextSequentialToken + _rangeLength - 1 <=\n selectedCollection.endingToken,\n \"RAIR ERC721: Invalid range length\"\n );\n require(\n _allowedTokens <= _rangeLength,\n \"RAIR ERC721: Number of allowed tokens must be less or equal than the range's length\"\n );\n require(\n _lockedTokens <= _rangeLength,\n \"RAIR ERC721: Number of locked tokens must be less or equal than the range's length\"\n );\n require(_price == 0 || _price >= 100, \"RAIR ERC721: Minimum price for a range is 100\");\n\n range storage newRange = _ranges.push();\n\n newRange.rangeStart = nextSequentialToken;\n newRange.rangeEnd = nextSequentialToken + _rangeLength - 1;\n newRange.mintableTokens = _rangeLength;\n newRange.tokensAllowed = _allowedTokens;\n newRange.lockedTokens = _lockedTokens;\n newRange.rangePrice = _price;\n newRange.rangeName = _name;\n\n rangeToCollection[_ranges.length - 1] = collectionIndex;\n\n // No need to initialize minted tokens, the default value is 0\n\n selectedCollection.rangeList.push(_ranges.length - 1);\n\n emit CreatedRange(\n collectionIndex,\n newRange.rangeStart,\n newRange.rangeEnd,\n newRange.rangePrice,\n newRange.tokensAllowed,\n newRange.lockedTokens,\n newRange.rangeName,\n _ranges.length - 1\n );\n }\n\n /// @notice\tUpdates a range\n /// @dev \tBecause they are sequential, the length of the range can't be modified\n /// @param\trangeId \t\t\tIndex of the collection on the contract\n /// @param\tname \t\t\t\tName of the range\n /// @param\tprice_ \t\t\t\tPrice for the tokens in the range\n /// @param\ttokensAllowed_ \t\tNumber of tokens allowed to be sold\n /// @param\tlockedTokens_ \t\tNumber of tokens that have to be minted in order to unlock transfers\n function updateRange(\n uint rangeId,\n string memory name,\n uint price_,\n uint tokensAllowed_,\n uint lockedTokens_\n ) external onlyRole(DEFAULT_ADMIN_ROLE) rangeExists(rangeId) nonReentrant {\n range storage selectedRange = _ranges[rangeId];\n require(price_ == 0 || price_ >= 100, \"RAIR ERC721: Range price must be greater or equal than 100\");\n require(\n tokensAllowed_ <= selectedRange.mintableTokens,\n \"RAIR ERC721: Tokens allowed should be less than the number of mintable tokens\"\n );\n require(\n lockedTokens_ <= selectedRange.mintableTokens,\n \"RAIR ERC721: Locked tokens should be less than the number of mintable tokens\"\n );\n\n selectedRange.tokensAllowed = tokensAllowed_;\n if (lockedTokens_ > 0 && selectedRange.lockedTokens == 0) {\n emit TradingLocked(\n rangeId,\n selectedRange.rangeStart,\n selectedRange.rangeEnd,\n lockedTokens_\n );\n } else if (lockedTokens_ == 0 && selectedRange.lockedTokens > 0) {\n emit TradingUnlocked(\n rangeId,\n selectedRange.rangeStart,\n selectedRange.rangeEnd\n );\n }\n selectedRange.lockedTokens = lockedTokens_;\n selectedRange.rangePrice = price_;\n selectedRange.rangeName = name;\n\n emit UpdatedRange(rangeId, name, price_, tokensAllowed_, lockedTokens_);\n }\n\n /// @notice\tReturns the number of collections on the contract\n /// @dev\tUse with get collection to list all of the collections\n function getCollectionCount()\n external\n view\n override(IRAIR721_Contract)\n returns (uint)\n {\n return _collections.length;\n }\n\n /// @notice\tReturns information about a collection\n /// @param\tcollectionIndex\tIndex of the collection\n function getCollection(uint collectionIndex)\n external\n view\n override(IRAIR721_Contract)\n returns (collection memory)\n {\n return _collections[collectionIndex];\n }\n\n /// @notice\tTranslates the unique index of an NFT to it's collection index\n /// @param\ttoken\tToken ID to find\n function tokenToCollectionIndex(uint token)\n public\n view\n returns (uint tokenIndex)\n {\n return token - _collections[tokenToCollection(token)].startingToken;\n }\n\n /// @notice\tFinds the first token inside a collection that doesn't have an owner\n /// @param\tcollectionID\tIndex of the collection to search\n /// @param\tstartingIndex\tStarting token for the search\n /// @param\tendingIndex\t\tEnding token for the search\n function getNextSequentialIndex(\n uint collectionID,\n uint startingIndex,\n uint endingIndex\n ) public view collectionExists(collectionID) returns (uint nextIndex) {\n collection memory currentCollection = _collections[collectionID];\n return\n _getNextSequentialIndexInRange(\n currentCollection.startingToken + startingIndex,\n currentCollection.startingToken + endingIndex\n );\n }\n\n /// @notice\t\tLoops through a range of tokens and returns the first token without an owner\n /// @dev \t\tLoops are expensive in solidity, do not use this in a gas-consuming function\n /// @param \t\tstartingToken \tStarting token for the search\n /// @param \t\tendingToken \tEnding token for the search\n function _getNextSequentialIndexInRange(\n uint startingToken,\n uint endingToken\n ) internal view returns (uint nextIndex) {\n for (nextIndex = startingToken; nextIndex <= endingToken; nextIndex++) {\n if (!_exists(nextIndex)) {\n break;\n }\n }\n require(\n startingToken <= nextIndex && nextIndex <= endingToken,\n \"RAIR ERC721: There are no available tokens in this range.\"\n );\n }\n\n /// @notice This functions allow us to check the information of the range\n /// @dev \tThis function requires that the rangeIndex_ points to an existing range\n /// @param\trangeIndex\t\tIdentification of the range to verify\n /// @return data \t\t\tInformation about the range\n /// @return productIndex \tContains the index of the product in the range\n function rangeInfo(uint rangeIndex)\n external\n view\n override(IRAIR721_Contract)\n rangeExists(rangeIndex)\n returns (range memory data, uint productIndex)\n {\n data = _ranges[rangeIndex];\n productIndex = rangeToCollection[rangeIndex];\n }\n\n /// @notice\tVerifies if the range where a token is located is locked or not\n /// @param\t_tokenId\tIndex of the token to search\n function isTokenLocked(uint256 _tokenId) public view returns (bool) {\n return _ranges[tokenToRange[_tokenId]].lockedTokens > 0;\n }\n\n\tfunction mintFromRange(\n\t\taddress buyerAddress,\n uint rangeIndex,\n uint indexInCollection\n\t) \n external\n\t\toverride(IRAIR721_Contract)\n onlyRole(MINTER)\n rangeExists(rangeIndex)\n\t{\n\t\t_mintFromRange(\n\t\t\tbuyerAddress,\n\t\t\trangeIndex,\n\t\t\tindexInCollection,\n\t\t\t1\n\t\t);\n\t}\n\n /// @notice\tLoops over the user's tokens looking for one that belongs to a product and a specific range\n\t/// @dev\tLoops are expensive in solidity, so don't use this in a function that requires gas\n\t/// @param\tuserAddress\t\t\tUser to search\n\t/// @param\tcollectionIndex\t\tProduct to search\n\t/// @param\tstartingToken\t\tProduct to search\n\t/// @param\tendingToken\t\t\tProduct to search\n\tfunction hasTokenInProduct(\n address userAddress,\n uint collectionIndex,\n uint startingToken,\n uint endingToken\n )\n collectionExists(collectionIndex)\n public\n view\n returns (bool)\n {\n\t\tcollection memory aux = _collections[collectionIndex];\n require(\n aux.endingToken - aux.startingToken + 1 > startingToken &&\n aux.endingToken - aux.startingToken + 1 > endingToken, \n \"RAIR ERC721: Invalid parameters\"\n );\n\t\tif (aux.endingToken != 0) {\n uint end = aux.startingToken + endingToken;\n\t\t\tfor (uint i = aux.startingToken + startingToken; i < end; i++) {\n\t\t\t\tif (_exists(i) && ownerOf(i) == userAddress) {\n return true;\n }\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n /// @notice\tMints a specific token within a range\n /// @dev\tHas to be used alongside getNextSequentialIndex to simulate a sequential minting\n /// @dev\tAnyone that wants a specific token just has to call this function with the index they want\n /// @param\tbuyerAddress\t\tAddress of the new token's owner\n /// @param\trangeIndex\t\t\tIndex of the range\n /// @param\tindexInCollection\tIndex of the token inside the collection\n function _mintFromRange(\n address buyerAddress,\n uint rangeIndex,\n uint indexInCollection,\n\t\tuint tokenQuantity\n )\n internal\n {\n range storage selectedRange = _ranges[rangeIndex];\n collection storage selectedCollection = _collections[\n rangeToCollection[rangeIndex]\n ];\n\n require(\n selectedRange.tokensAllowed >= tokenQuantity,\n \"RAIR ERC721: Not allowed to mint that many tokens\"\n );\n require(\n selectedRange.rangeStart <=\n selectedCollection.startingToken + indexInCollection &&\n selectedCollection.startingToken + indexInCollection + tokenQuantity - 1 <=\n selectedRange.rangeEnd,\n \"RAIR ERC721: Tried to mint token outside of range\"\n );\n\n selectedRange.tokensAllowed -= tokenQuantity;\n\n if (selectedRange.lockedTokens > 0) {\n\t\t\tif (selectedRange.lockedTokens <= tokenQuantity) {\n\t selectedRange.lockedTokens = 0;\n\t\t\t} else {\n\t selectedRange.lockedTokens -= tokenQuantity;\n\t\t\t}\n if (selectedRange.lockedTokens == 0) {\n emit TradingUnlocked(\n rangeIndex,\n selectedRange.rangeStart,\n selectedRange.rangeEnd\n );\n }\n }\n\n\t\tfor (; tokenQuantity > 0; tokenQuantity--) {\n\t\t\t_safeMint(\n\t\t\t\tbuyerAddress,\n\t\t\t\tselectedCollection.startingToken + indexInCollection + tokenQuantity - 1\n\t\t\t);\n\t\t\ttokenToRange[\n\t\t\t\tselectedCollection.startingToken + indexInCollection + tokenQuantity - 1\n\t\t\t] = rangeIndex;\n\t\t}\n }\n\n /// @notice Returns the fee for the NFT sale\n /// @param _tokenId - the NFT asset queried for royalty information\n /// @param _salePrice - the sale price of the NFT asset specified by _tokenId\n /// @return receiver - address of who should be sent the royalty payment\n /// @return royaltyAmount - the royalty payment amount for _salePrice sale price\n function royaltyInfo(uint256 _tokenId, uint256 _salePrice)\n external\n view\n override(IRAIR721_Contract, IERC2981)\n returns (address receiver, uint256 royaltyAmount)\n {\n require(\n _exists(_tokenId),\n \"RAIR ERC721: Royalty query for a non-existing token\"\n );\n return (owner, (_salePrice * _royaltyFee) / 100000);\n }\n\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override(IERC165, ERC165, AccessControl, ERC721, IERC2981)\n returns (bool)\n {\n return\n interfaceId == type(IERC2981).interfaceId ||\n super.supportsInterface(interfaceId);\n }\n\n /// @notice Hook being called before every transfer\n /// @dev\tLocks and the requirement of the TRADER role happe here\n /// @param\t_from\t\tToken's original owner\n /// @param\t_to\t\t\tToken's new owner\n /// @param\t_tokenId\tToken's ID\n function _beforeTokenTransfer(\n address _from,\n address _to,\n uint256 _tokenId\n ) internal virtual override(ERC721) nonReentrant{\n // If the transfer isn't to mint (from = address(0)) and it's not a burn (to = address(0))\n if (_from != address(0) && _to != address(0)) {\n //\n if (\n _ranges.length > 0 &&\n rangeToCollection[tokenToRange[_tokenId]] ==\n tokenToCollection(_tokenId)\n ) {\n require(\n _ranges[tokenToRange[_tokenId]].lockedTokens == 0,\n \"RAIR ERC721: Transfers for this range are currently locked\"\n );\n }\n if (_requireTrader) {\n _checkRole(TRADER, msg.sender);\n }\n }\n super._beforeTokenTransfer(_from, _to, _tokenId);\n }\n}\n" }, "contracts/Tokens/IERC2981.sol": { "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8.10; \n\ninterface IERC2981 {\n /// ERC165 bytes to add to interface array - set in parent contract\n /// implementing this standard\n ///\n /// bytes4(keccak256(\"royaltyInfo(uint256,uint256,bytes)\")) == 0xc155531d\n /// bytes4 private constant _INTERFACE_ID_ERC2981 = 0xc155531d;\n /// _registerInterface(_INTERFACE_ID_ERC2981);\n\n /// @notice Called with the sale price to determine how much royalty\n // is owed and to whom.\n /// @param _tokenId - the NFT asset queried for royalty information\n /// @param _salePrice - the sale price of the NFT asset specified by _tokenId\n /// @return receiver - address of who should be sent the royalty payment\n /// @return royaltyAmount - the royalty payment amount for _value sale price\n function royaltyInfo(\n \tuint256 _tokenId,\n \tuint256 _salePrice)\n external returns (\n \taddress receiver,\n \tuint256 royaltyAmount);\n\n /// @notice Informs callers that this contract supports ERC2981\n /// @dev If `_registerInterface(_INTERFACE_ID_ERC2981)` is called\n /// in the initializer, this should be automatic\n /// @param interfaceID The interface identifier, as specified in ERC-165\n /// @return `true` if the contract implements\n /// `_INTERFACE_ID_ERC2981` and `false` otherwise\n function supportsInterface(bytes4 interfaceID) external view returns (bool);\n}" }, "contracts/Tokens/IRAIR721_Contract.sol": { "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8.17;\n\nimport \"openzeppelin-v4.7.1/token/ERC721/IERC721.sol\";\n\ninterface IRAIR721_Contract is IERC721 {\n struct range {\n uint rangeStart;\n uint rangeEnd;\n uint tokensAllowed;\n uint mintableTokens;\n uint lockedTokens;\n uint rangePrice;\n string rangeName;\n }\n\n struct collection {\n uint startingToken;\n uint endingToken;\n string name;\n uint[] rangeList;\n }\n\n event CreatedCollection(\n uint indexed collectionIndex,\n string collectionName,\n uint startingToken,\n uint collectionLength\n );\n\n event CreatedRange(\n uint collectionIndex,\n uint start,\n uint end,\n uint price,\n uint tokensAllowed,\n uint lockedTokens,\n string name,\n uint rangeIndex\n );\n event UpdatedRange(\n uint rangeIndex,\n string name,\n uint price,\n uint tokensAllowed,\n uint lockedTokens\n );\n event TradingLocked(\n uint indexed rangeIndex,\n uint from,\n uint to,\n uint lockedTokens\n );\n event TradingUnlocked(uint indexed rangeIndex, uint from, uint to);\n\n event UpdatedBaseURI(string newURI, bool appendTokenIndex, string _metadataExtension);\n event UpdatedTokenURI(uint tokenId, string newURI);\n event UpdatedProductURI(\n uint productId,\n string newURI,\n bool appendTokenIndex,\n string _metadataExtension\n );\n event UpdatedRangeURI(\n uint rangeId,\n string newURI,\n bool appendTokenIndex,\n string _metadataExtension\n );\n event UpdatedURIExtension(string newExtension);\n event UpdatedContractURI(string newURI);\n\n // For OpenSea's Freezing\n event PermanentURI(string _value, uint256 indexed _id);\n\n // Get the total number of collections in the contract\n function getCollectionCount() external view returns (uint);\n\n // Get a specific collection in the contract\n function getCollection(uint collectionIndex)\n external\n view\n returns (collection memory);\n\n function rangeInfo(uint rangeIndex)\n external\n view\n returns (range memory data, uint collectionIndex);\n\n // Mint a token inside a collection\n function mintFromRange(\n address to,\n uint collectionID,\n uint index\n ) external;\n\n // Ask for the royalty info of the creator\n function royaltyInfo(uint256 _tokenId, uint256 _salePrice)\n external\n view\n returns (address receiver, uint256 royaltyAmount);\n}\n" }, "openzeppelin-v4.7.1/access/AccessControl.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n Strings.toHexString(uint160(account), 20),\n \" is missing role \",\n Strings.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleGranted} event.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleRevoked} event.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n *\n * May emit a {RoleRevoked} event.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * May emit a {RoleGranted} event.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleGranted} event.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleRevoked} event.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n}\n" }, "openzeppelin-v4.7.1/token/ERC721/ERC721.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/ERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC721.sol\";\nimport \"./IERC721Receiver.sol\";\nimport \"./extensions/IERC721Metadata.sol\";\nimport \"../../utils/Address.sol\";\nimport \"../../utils/Context.sol\";\nimport \"../../utils/Strings.sol\";\nimport \"../../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including\n * the Metadata extension, but not including the Enumerable extension, which is available separately as\n * {ERC721Enumerable}.\n */\ncontract ERC721 is Context, ERC165, IERC721, IERC721Metadata {\n using Address for address;\n using Strings for uint256;\n\n // Token name\n string private _name;\n\n // Token symbol\n string private _symbol;\n\n // Mapping from token ID to owner address\n mapping(uint256 => address) private _owners;\n\n // Mapping owner address to token count\n mapping(address => uint256) private _balances;\n\n // Mapping from token ID to approved address\n mapping(uint256 => address) private _tokenApprovals;\n\n // Mapping from owner to operator approvals\n mapping(address => mapping(address => bool)) private _operatorApprovals;\n\n /**\n * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n return\n interfaceId == type(IERC721).interfaceId ||\n interfaceId == type(IERC721Metadata).interfaceId ||\n super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev See {IERC721-balanceOf}.\n */\n function balanceOf(address owner) public view virtual override returns (uint256) {\n require(owner != address(0), \"ERC721: address zero is not a valid owner\");\n return _balances[owner];\n }\n\n /**\n * @dev See {IERC721-ownerOf}.\n */\n function ownerOf(uint256 tokenId) public view virtual override returns (address) {\n address owner = _owners[tokenId];\n require(owner != address(0), \"ERC721: invalid token ID\");\n return owner;\n }\n\n /**\n * @dev See {IERC721Metadata-name}.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev See {IERC721Metadata-symbol}.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev See {IERC721Metadata-tokenURI}.\n */\n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\n _requireMinted(tokenId);\n\n string memory baseURI = _baseURI();\n return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : \"\";\n }\n\n /**\n * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each\n * token will be the concatenation of the `baseURI` and the `tokenId`. Empty\n * by default, can be overridden in child contracts.\n */\n function _baseURI() internal view virtual returns (string memory) {\n return \"\";\n }\n\n /**\n * @dev See {IERC721-approve}.\n */\n function approve(address to, uint256 tokenId) public virtual override {\n address owner = ERC721.ownerOf(tokenId);\n require(to != owner, \"ERC721: approval to current owner\");\n\n require(\n _msgSender() == owner || isApprovedForAll(owner, _msgSender()),\n \"ERC721: approve caller is not token owner nor approved for all\"\n );\n\n _approve(to, tokenId);\n }\n\n /**\n * @dev See {IERC721-getApproved}.\n */\n function getApproved(uint256 tokenId) public view virtual override returns (address) {\n _requireMinted(tokenId);\n\n return _tokenApprovals[tokenId];\n }\n\n /**\n * @dev See {IERC721-setApprovalForAll}.\n */\n function setApprovalForAll(address operator, bool approved) public virtual override {\n _setApprovalForAll(_msgSender(), operator, approved);\n }\n\n /**\n * @dev See {IERC721-isApprovedForAll}.\n */\n function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {\n return _operatorApprovals[owner][operator];\n }\n\n /**\n * @dev See {IERC721-transferFrom}.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public virtual override {\n //solhint-disable-next-line max-line-length\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: caller is not token owner nor approved\");\n\n _transfer(from, to, tokenId);\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public virtual override {\n safeTransferFrom(from, to, tokenId, \"\");\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes memory data\n ) public virtual override {\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: caller is not token owner nor approved\");\n _safeTransfer(from, to, tokenId, data);\n }\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n *\n * `data` is additional data, it has no specified format and it is sent in call to `to`.\n *\n * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.\n * implement alternative mechanisms to perform token transfer, such as signature-based.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function _safeTransfer(\n address from,\n address to,\n uint256 tokenId,\n bytes memory data\n ) internal virtual {\n _transfer(from, to, tokenId);\n require(_checkOnERC721Received(from, to, tokenId, data), \"ERC721: transfer to non ERC721Receiver implementer\");\n }\n\n /**\n * @dev Returns whether `tokenId` exists.\n *\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\n *\n * Tokens start existing when they are minted (`_mint`),\n * and stop existing when they are burned (`_burn`).\n */\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\n return _owners[tokenId] != address(0);\n }\n\n /**\n * @dev Returns whether `spender` is allowed to manage `tokenId`.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {\n address owner = ERC721.ownerOf(tokenId);\n return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);\n }\n\n /**\n * @dev Safely mints `tokenId` and transfers it to `to`.\n *\n * Requirements:\n *\n * - `tokenId` must not exist.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function _safeMint(address to, uint256 tokenId) internal virtual {\n _safeMint(to, tokenId, \"\");\n }\n\n /**\n * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is\n * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.\n */\n function _safeMint(\n address to,\n uint256 tokenId,\n bytes memory data\n ) internal virtual {\n _mint(to, tokenId);\n require(\n _checkOnERC721Received(address(0), to, tokenId, data),\n \"ERC721: transfer to non ERC721Receiver implementer\"\n );\n }\n\n /**\n * @dev Mints `tokenId` and transfers it to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible\n *\n * Requirements:\n *\n * - `tokenId` must not exist.\n * - `to` cannot be the zero address.\n *\n * Emits a {Transfer} event.\n */\n function _mint(address to, uint256 tokenId) internal virtual {\n require(to != address(0), \"ERC721: mint to the zero address\");\n require(!_exists(tokenId), \"ERC721: token already minted\");\n\n _beforeTokenTransfer(address(0), to, tokenId);\n\n _balances[to] += 1;\n _owners[tokenId] = to;\n\n emit Transfer(address(0), to, tokenId);\n\n _afterTokenTransfer(address(0), to, tokenId);\n }\n\n /**\n * @dev Destroys `tokenId`.\n * The approval is cleared when the token is burned.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n *\n * Emits a {Transfer} event.\n */\n function _burn(uint256 tokenId) internal virtual {\n address owner = ERC721.ownerOf(tokenId);\n\n _beforeTokenTransfer(owner, address(0), tokenId);\n\n // Clear approvals\n _approve(address(0), tokenId);\n\n _balances[owner] -= 1;\n delete _owners[tokenId];\n\n emit Transfer(owner, address(0), tokenId);\n\n _afterTokenTransfer(owner, address(0), tokenId);\n }\n\n /**\n * @dev Transfers `tokenId` from `from` to `to`.\n * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n *\n * Emits a {Transfer} event.\n */\n function _transfer(\n address from,\n address to,\n uint256 tokenId\n ) internal virtual {\n require(ERC721.ownerOf(tokenId) == from, \"ERC721: transfer from incorrect owner\");\n require(to != address(0), \"ERC721: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, tokenId);\n\n // Clear approvals from the previous owner\n _approve(address(0), tokenId);\n\n _balances[from] -= 1;\n _balances[to] += 1;\n _owners[tokenId] = to;\n\n emit Transfer(from, to, tokenId);\n\n _afterTokenTransfer(from, to, tokenId);\n }\n\n /**\n * @dev Approve `to` to operate on `tokenId`\n *\n * Emits an {Approval} event.\n */\n function _approve(address to, uint256 tokenId) internal virtual {\n _tokenApprovals[tokenId] = to;\n emit Approval(ERC721.ownerOf(tokenId), to, tokenId);\n }\n\n /**\n * @dev Approve `operator` to operate on all of `owner` tokens\n *\n * Emits an {ApprovalForAll} event.\n */\n function _setApprovalForAll(\n address owner,\n address operator,\n bool approved\n ) internal virtual {\n require(owner != operator, \"ERC721: approve to caller\");\n _operatorApprovals[owner][operator] = approved;\n emit ApprovalForAll(owner, operator, approved);\n }\n\n /**\n * @dev Reverts if the `tokenId` has not been minted yet.\n */\n function _requireMinted(uint256 tokenId) internal view virtual {\n require(_exists(tokenId), \"ERC721: invalid token ID\");\n }\n\n /**\n * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.\n * The call is not executed if the target address is not a contract.\n *\n * @param from address representing the previous owner of the given token ID\n * @param to target address that will receive the tokens\n * @param tokenId uint256 ID of the token to be transferred\n * @param data bytes optional data to send along with the call\n * @return bool whether the call correctly returned the expected magic value\n */\n function _checkOnERC721Received(\n address from,\n address to,\n uint256 tokenId,\n bytes memory data\n ) private returns (bool) {\n if (to.isContract()) {\n try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {\n return retval == IERC721Receiver.onERC721Received.selector;\n } catch (bytes memory reason) {\n if (reason.length == 0) {\n revert(\"ERC721: transfer to non ERC721Receiver implementer\");\n } else {\n /// @solidity memory-safe-assembly\n assembly {\n revert(add(32, reason), mload(reason))\n }\n }\n }\n } else {\n return true;\n }\n }\n\n /**\n * @dev Hook that is called before any token transfer. This includes minting\n * and burning.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be\n * transferred to `to`.\n * - When `from` is zero, `tokenId` will be minted for `to`.\n * - When `to` is zero, ``from``'s `tokenId` 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(\n address from,\n address to,\n uint256 tokenId\n ) 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.\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(\n address from,\n address to,\n uint256 tokenId\n ) internal virtual {}\n}\n" }, "@openzeppelin/contracts/security/ReentrancyGuard.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n constructor() {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n}\n" }, "openzeppelin-v4.7.1/utils/introspection/ERC165.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" }, "openzeppelin-v4.7.1/utils/Strings.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n // Inspired by OraclizeAPI's implementation - MIT licence\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n if (value == 0) {\n return \"0\";\n }\n uint256 temp = value;\n uint256 digits;\n while (temp != 0) {\n digits++;\n temp /= 10;\n }\n bytes memory buffer = new bytes(digits);\n while (value != 0) {\n digits -= 1;\n buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n value /= 10;\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n if (value == 0) {\n return \"0x00\";\n }\n uint256 temp = value;\n uint256 length = 0;\n while (temp != 0) {\n length++;\n temp >>= 8;\n }\n return toHexString(value, length);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _HEX_SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n}\n" }, "openzeppelin-v4.7.1/token/ERC721/IERC721.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n /**\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n */\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n */\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n */\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n /**\n * @dev Returns the number of tokens in ``owner``'s account.\n */\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /**\n * @dev Returns the owner of the `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function ownerOf(uint256 tokenId) external view returns (address owner);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) external;\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Transfers `tokenId` token from `from` to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n *\n * Emits an {Approval} event.\n */\n function approve(address to, uint256 tokenId) external;\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the caller.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool _approved) external;\n\n /**\n * @dev Returns the account approved for `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function getApproved(uint256 tokenId) external view returns (address operator);\n\n /**\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n *\n * See {setApprovalForAll}\n */\n function isApprovedForAll(address owner, address operator) external view returns (bool);\n}\n" }, "openzeppelin-v4.7.1/utils/introspection/IERC165.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" }, "openzeppelin-v4.7.1/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-v4.7.1/access/IAccessControl.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n" }, "openzeppelin-v4.7.1/token/ERC721/extensions/IERC721Metadata.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC721.sol\";\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\n * @dev See https://eips.ethereum.org/EIPS/eip-721\n */\ninterface IERC721Metadata is IERC721 {\n /**\n * @dev Returns the token collection name.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the token collection symbol.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n */\n function tokenURI(uint256 tokenId) external view returns (string memory);\n}\n" }, "openzeppelin-v4.7.1/token/ERC721/IERC721Receiver.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n /**\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n * by `operator` from `from`, this function is called.\n *\n * It must return its Solidity selector to confirm the token transfer.\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n *\n * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.\n */\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}\n" }, "openzeppelin-v4.7.1/utils/Address.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n" } }, "settings": { "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} } }