// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @dev Collection of functions related to the address type
*/libraryAddress{
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/functionisContract(address account) internalviewreturns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in// construction, since the code is only stored at the end of the// constructor execution.uint256 size;
assembly {
size :=extcodesize(account)
}
return size >0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/functionsendValue(addresspayable recipient, uint256 amount) internal{
require(address(this).balance>= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/functionfunctionCall(address target, bytesmemory data) internalreturns (bytesmemory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/functionfunctionCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalreturns (bytesmemory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/functionfunctionCallWithValue(address target,
bytesmemory data,
uint256 value
) internalreturns (bytesmemory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/functionfunctionCallWithValue(address target,
bytesmemory data,
uint256 value,
stringmemory errorMessage
) internalreturns (bytesmemory) {
require(address(this).balance>= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytesmemory returndata) = target.call{value: value}(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/functionfunctionStaticCall(address target, bytesmemory data) internalviewreturns (bytesmemory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/functionfunctionStaticCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalviewreturns (bytesmemory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytesmemory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/functionfunctionDelegateCall(address target, bytesmemory data) internalreturns (bytesmemory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/functionfunctionDelegateCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalreturns (bytesmemory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytesmemory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function_verifyCallResult(bool success,
bytesmemory returndata,
stringmemory errorMessage
) privatepurereturns (bytesmemory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if presentif (returndata.length>0) {
// The easiest way to bubble the revert reason is using memory via assemblyassembly {
let returndata_size :=mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Contract Source Code
File 2 of 8: ERC165.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import"./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/abstractcontractERC165isIERC165{
/**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverridereturns (bool) {
return interfaceId ==type(IERC165).interfaceId;
}
}
Contract Source Code
File 3 of 8: GENE.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.4;import"@openzeppelin/contracts/token/ERC721/IERC721.sol";
import"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import"@openzeppelin/contracts/utils/Address.sol";
import"@openzeppelin/contracts/utils/Strings.sol";
import"@openzeppelin/contracts/utils/introspection/ERC165.sol";
contractGENEisERC165, IERC721, IERC721Metadata{
usingAddressforaddress;
usingStringsforuint256;
/* ============ State Variables ============ */structInfo {
bytes32 id;
uint160 owner;
uint256 value;
uint8 types;
uint256 bornTime;
}
// Owneraddresspublic owner;
// Token namestringprivate _name ="Micro3 GENE";
// Token symbolstringprivate _symbol ="GENE";
// Total number of tokens burneduint256private _burnCount;
// Version of GENE contractuint8private _version =1;
// Max Supplyuint256private _maxSupply =type(uint256).max;
// Array of all tokens storing the owner's address and the campaign id
Info[] private _tokens;
// Mapping owner address to credential countmapping(bytes32=>uint256) private _credentials;
// Mapping owner address to credential countmapping(uint256=>string) private _tokenURIs;
// Mapping owner address to token countmapping(address=>uint256) private _balances;
// Mapping from token ID to approved addressmapping(uint256=>address) private _tokenApprovals;
// Mapping from owner to operator approvalsmapping(address=>mapping(address=>bool)) private _operatorApprovals;
// Mint and burn Info.mapping(address=>bool) private _minters;
//Whitelist transfermapping(address=>bool) private _whitelists;
// Edit Info.mapping(address=>bool) private _editors;
// Default allow transferboolprivate _transferable;
// Default one URIstringprivate _baseURI ="";
boolprivate _initialized;
/* ============ Events ============ */// Add new mintereventEventMinterAdded(addressindexed newMinter);
// Remove old mintereventEventMinterRemoved(addressindexed oldMinter);
// Add new whitelistereventEventWhitelisterAdded(addressindexed newMinter);
// Remove old whitelistereventEventWhitelisterRemoved(addressindexed oldMinter);
// Add new whitelistereventEventEditorAdded(addressindexed newAddress);
// Remove old whitelistereventEventEditorRemoved(addressindexed newAddress);
/* ============ Custom Error ============ */errorOnlyMinter();
errorOnlyEditor();
errorOnlyTransferable();
errorIsExists();
errorOutBoundIndex();
errorIsZeroAddress();
errorIsApproved();
errorIsOwner();
errorIsAdded();
errorIsNotAdded();
errorIsERC721Received();
errorUnauthorized();
/* ============ Modifiers ============ *//**
* Only minter.
*/modifieronlyMinter() {
if (!_minters[msg.sender]) {
revert OnlyMinter();
}
_;
}
/**
* Only editor.
*/modifieronlyEditor() {
if (!_editors[msg.sender]) {
revert OnlyEditor();
}
_;
}
/**
* Only allow transfer.
*/modifieronlyTransferable(addressfrom, address to) {
if (!_transferable &&!_whitelists[to]) {
revert OnlyTransferable();
}
_;
}
/**
* Only Exists .
*/modifieronlyExists(uint256 tokenId) {
if (!_exists(tokenId)) {
revert IsExists();
}
_;
}
/**
* Only Exists .
*/modifieronlyIsApproved(address sender, uint256 tokenId) {
if (!_isApprovedOrOwner(sender, tokenId)) {
revert IsApproved();
}
_;
}
/**
* Only Owner .
*/modifieronlyIsOwner(address sender, uint256 tokenId) {
if (!isOwnerOf(sender, tokenId)) {
revert IsOwner();
}
_;
}
/**
* Only Zero Address .
*/modifieronlyZeroAddress(address sender) {
if (sender ==address(0)) {
revert IsZeroAddress();
}
_;
}
/**
* Only Owner .
*/modifieronlyOwner() {
require(owner ==msg.sender);
_;
}
/**
* @dev Initializes the contract
*/functioninit(bytesmemory initPayload) externalreturns (bool) {
if (_initialized) {
revert Unauthorized();
}
address _owner =abi.decode(initPayload, (address));
// Initialize zero index value
Info memory _nft = Info(0, 0, 0, 0, 0);
_tokens.push(_nft);
owner = _owner;
_minters[_owner] =true;
_whitelists[_owner] =true;
_editors[_owner] =true;
_transferable =false;
_initialized =true;
returntrue;
}
/**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId)
publicviewoverride(ERC165, IERC165)
returns (bool)
{
return
interfaceId ==type(IERC721).interfaceId||
interfaceId ==type(IERC721Metadata).interfaceId||super.supportsInterface(interfaceId);
}
/**
* @dev Is this address a minters.
*/functionminters(address account) externalviewreturns (bool) {
return _minters[account];
}
/**
* @dev Is this contract allow nft transfer.
*/functiontransferable() externalviewreturns (bool) {
return _transferable;
}
/**
* @dev Returns the base URI for nft.
*/functionbaseURI() externalviewreturns (stringmemory) {
return _baseURI;
}
/**
* @dev Get mintingTime.
*/functiongetInfo(uint256 tokenId)
externalviewonlyExists(tokenId)
returns (Info memory)
{
return _tokens[tokenId];
}
/**
* @dev Get mintingTime.
*/functiongetCredentials(bytes32 _id) externalviewreturns (uint256) {
return _credentials[_id];
}
/**
* @dev Get Info NFT owner
*/functiongetNumMinted() publicviewreturns (uint256) {
return _tokens.length-1;
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/functiontotalSupply() externalviewreturns (uint256) {
return getNumMinted() - _burnCount;
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
* This is implementation is O(n) and should not be
* called by other contracts.
*/functiontokenOfOwnerByIndex(address _owner, uint256 index)
publicviewreturns (uint256)
{
uint256 currentIndex =0;
for (uint256 i =1; i < _tokens.length; ) {
if (isOwnerOf(_owner, i)) {
if (currentIndex == index) {
return i;
}
currentIndex +=1;
}
unchecked {
++i;
}
}
revert OutBoundIndex();
}
functiontokensOfOwner(address _owner)
externalviewreturns (uint256[] memory)
{
uint256 tokenIdsIdx;
uint256 tokenIdsLength = balanceOf(_owner);
uint256[] memory tokenIds =newuint256[](tokenIdsLength);
for (uint256 i =0; tokenIdsIdx != tokenIdsLength; ) {
tokenIds[tokenIdsIdx++] = tokenOfOwnerByIndex(_owner, i);
unchecked {
++i;
}
}
return tokenIds;
}
functiontokensOfOwnerByCursor(address _owner,
uint256 cursor,
uint256 size
) externalviewreturns (uint256[] memory) {
uint256 tokenIdsIdx;
uint256 tokenIdsLength = balanceOf(_owner);
uint256 length = size;
if (length > tokenIdsLength - cursor) {
length = tokenIdsLength - cursor;
}
uint256[] memory tokenIds =newuint256[](length);
for (uint256 i =0; tokenIdsIdx != length; ) {
tokenIds[tokenIdsIdx++] = tokenOfOwnerByIndex(_owner, i);
unchecked {
++i;
}
}
return tokenIds;
}
/**
* @dev See {IERC721-balanceOf}.
*/functionbalanceOf(address _owner)
publicviewoverrideonlyZeroAddress(_owner)
returns (uint256)
{
return _balances[_owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/functionownerOf(uint256 tokenId)
publicviewoverrideonlyExists(tokenId)
returns (address)
{
returnaddress(_tokens[tokenId].owner);
}
/**
* @dev See {isOwnerOf}.
*/functionisOwnerOf(address account, uint256 id) publicviewreturns (bool) {
address _owner = ownerOf(id);
return _owner == account;
}
/**
* @dev See {IERC721Metadata-name}.
*/functionname() externalviewvirtualoverridereturns (stringmemory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/functionsymbol() externalviewvirtualoverridereturns (stringmemory) {
return _symbol;
}
/**
* @dev See {GENE-version}.
*/functionversion() externalviewreturns (uint8) {
return _version;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/functiontokenURI(uint256 tokenId)
externalviewoverrideonlyExists(tokenId)
returns (stringmemory)
{
if (bytes(_baseURI).length>0) {
return _baseURI;
}
return _tokenURIs[tokenId];
}
/**
* @dev See {IERC721-approve}.
*/functionapprove(address to, uint256 tokenId) externaloverride{
address _owner = ownerOf(tokenId);
require(to != _owner, "current owner");
require(
msg.sender== _owner || isApprovedForAll(_owner, msg.sender),
"not owner for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/functiongetApproved(uint256 tokenId)
publicviewoverrideonlyExists(tokenId)
returns (address)
{
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/functionsetApprovalForAll(address operator, bool approved)
publicoverride{
require(operator !=msg.sender, "approve to caller");
_operatorApprovals[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/functionisApprovedForAll(address _owner, address _operator)
publicviewoverridereturns (bool)
{
if (_minters[_operator]) returntrue;
return _operatorApprovals[_owner][_operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/functiontransferFrom(addressfrom,
address to,
uint256 tokenId
)
externaloverrideonlyTransferable(from, to)
onlyIsApproved(msg.sender, tokenId)
{
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 tokenId
) externaloverrideonlyTransferable(from, to) {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 tokenId,
bytesmemory _data
)
publicoverrideonlyTransferable(from, to)
onlyIsApproved(msg.sender, tokenId)
{
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/function_safeTransfer(addressfrom,
address to,
uint256 tokenId,
bytesmemory _data
) internal{
_transfer(from, to, tokenId);
if (!_checkOnERC721Received(from, to, tokenId, _data)) {
revert IsERC721Received();
}
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens Info existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/function_exists(uint256 tokenId) internalviewreturns (bool) {
return tokenId >0&& tokenId <= getNumMinted();
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/function_isApprovedOrOwner(address spender, uint256 tokenId)
internalviewreturns (bool)
{
address _owner = ownerOf(tokenId);
return (spender == _owner ||
getApproved(tokenId) == spender ||
isApprovedForAll(_owner, spender) ||
_whitelists[spender]);
}
functioneditInfo(address _owner,
uint256 _tokenId,
uint256 _value
)
externalonlyEditoronlyExists(_tokenId)
onlyIsOwner(_owner, _tokenId)
returns (uint256)
{
_tokens[_tokenId].value= _value;
return _tokenId;
}
functionmint(address _account,
uint256 _value,
bytes32 _id,
uint8 _types,
stringcalldata _tokenURI
) externalonlyMinteronlyZeroAddress(_account) returns (uint256) {
bytes32 hashKey = generateHashKey(_account, _id, _types);
if (_credentials[hashKey] >0) {
revert IsExists();
}
uint256 tokenId = _tokens.length;
Info memory _nft = Info(
_id,
uint160(_account),
_value,
_types,
block.timestamp
);
_balances[_account] +=1;
_tokens.push(_nft);
_credentials[hashKey] = tokenId;
_tokenURIs[tokenId] = _tokenURI;
if (!_checkOnERC721Received(address(0), _account, tokenId, "")) {
revert IsERC721Received();
}
emit Transfer(address(0), _account, tokenId);
return tokenId;
}
functionburn(address account, uint256 id)
externalonlyMinteronlyIsApproved(msg.sender, id)
onlyIsOwner(account, id)
{
// Clear approvals
_approve(address(0), id);
_burnCount++;
_balances[account] -=1;
bytes32 hashKey = generateHashKey(
account,
_tokens[id].id,
_tokens[id].types
);
_credentials[hashKey] =0;
_tokens[id].id =0;
_tokens[id].owner =0;
_tokens[id].value=0;
_tokens[id].types =0;
_tokens[id].bornTime =0;
_tokenURIs[id] ="";
emit Transfer(account, address(0), id);
}
functiongenerateHashKey(address account,
bytes32 id,
uint8 types
) internalpurereturns (bytes32) {
returnkeccak256(abi.encode(account, id, types));
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/function_transfer(addressfrom,
address to,
uint256 tokenId
) internalvirtualonlyIsOwner(from, tokenId) onlyZeroAddress(to) {
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -=1;
_balances[to] +=1;
_tokens[tokenId].owner =uint160(to);
emit Transfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/function_approve(address to, uint256 tokenId) internalvirtual{
_tokenApprovals[tokenId] = to;
emit Approval(ownerOf(tokenId), to, tokenId);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/function_checkOnERC721Received(addressfrom,
address to,
uint256 tokenId,
bytesmemory _data
) privatereturns (bool) {
if (to.isContract()) {
try
IERC721Receiver(to).onERC721Received(
msg.sender,
from,
tokenId,
_data
)
returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytesmemory reason) {
if (reason.length==0) {
revert("ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
returntrue;
}
/* ============ Util Functions ============ *//**
* @dev Sets a new revealedURI for all token types.
*/functionsetBaseURI(stringmemory _uri) externalonlyOwner{
_baseURI = _uri;
}
/**
* @dev Sets a new transferable for all token types.
*/functionsetTransferable(bool _trans) externalonlyOwner{
_transferable = _trans;
}
/**
* @dev Sets a new name for all token types.
*/functionsetName(stringcalldata newName) externalonlyOwner{
_name = newName;
}
/**
* @dev Sets a new symbol for all token types.
*/functionsetSymbol(stringcalldata newSymbol) externalonlyOwner{
_symbol = newSymbol;
}
/**
* @dev Add a new minter.
*/functionaddMinter(address minter)
externalonlyOwneronlyZeroAddress(minter)
{
if (_minters[minter]) {
revert IsAdded();
}
_minters[minter] =true;
emit EventMinterAdded(minter);
}
/**
* @dev Remove a old minter.
*/functionremoveMinter(address minter) externalonlyOwner{
if (!_minters[minter]) {
revert IsNotAdded();
}
delete _minters[minter];
emit EventMinterRemoved(minter);
}
/**
* @dev Add a new minter.
*/functionaddWhitelist(address whitelist)
externalonlyOwneronlyZeroAddress(whitelist)
{
if (_whitelists[whitelist]) {
revert IsAdded();
}
_whitelists[whitelist] =true;
emit EventWhitelisterAdded(whitelist);
}
/**
* @dev Remove a old minter.
*/functionremoveWhitelist(address whitelist) externalonlyOwner{
if (!_whitelists[whitelist]) {
revert IsNotAdded();
}
delete _whitelists[whitelist];
emit EventWhitelisterRemoved(whitelist);
}
/**
* @dev Add a new minter.
*/functionaddEditor(address editor)
externalonlyOwneronlyZeroAddress(editor)
{
if (_editors[editor]) {
revert IsAdded();
}
_editors[editor] =true;
emit EventEditorAdded(editor);
}
/**
* @dev Remove a old minter.
*/functionremoveEditor(address editor) externalonlyOwner{
if (!_editors[editor]) {
revert IsNotAdded();
}
delete _editors[editor];
emit EventEditorRemoved(editor);
}
}
Contract Source Code
File 4 of 8: IERC165.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/interfaceIERC165{
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/functionsupportsInterface(bytes4 interfaceId) externalviewreturns (bool);
}
Contract Source Code
File 5 of 8: IERC721.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import"../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/interfaceIERC721isIERC165{
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/eventApproval(addressindexed owner, addressindexed approved, uint256indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/eventApprovalForAll(addressindexed owner, addressindexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/functionbalanceOf(address owner) externalviewreturns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/functionownerOf(uint256 tokenId) externalviewreturns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/functionapprove(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/functiongetApproved(uint256 tokenId) externalviewreturns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/functionsetApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/functionisApprovedForAll(address owner, address operator) externalviewreturns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/functionsafeTransferFrom(addressfrom,
address to,
uint256 tokenId,
bytescalldata data
) external;
}
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/interfaceIERC721Receiver{
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/functiononERC721Received(address operator,
addressfrom,
uint256 tokenId,
bytescalldata data
) externalreturns (bytes4);
}
Contract Source Code
File 8 of 8: Strings.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @dev String operations.
*/libraryStrings{
bytes16privateconstant _HEX_SYMBOLS ="0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/functiontoString(uint256 value) internalpurereturns (stringmemory) {
// Inspired by OraclizeAPI's implementation - MIT licence// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.solif (value ==0) {
return"0";
}
uint256 temp = value;
uint256 digits;
while (temp !=0) {
digits++;
temp /=10;
}
bytesmemory buffer =newbytes(digits);
while (value !=0) {
digits -=1;
buffer[digits] =bytes1(uint8(48+uint256(value %10)));
value /=10;
}
returnstring(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/functiontoHexString(uint256 value) internalpurereturns (stringmemory) {
if (value ==0) {
return"0x00";
}
uint256 temp = value;
uint256 length =0;
while (temp !=0) {
length++;
temp >>=8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/functiontoHexString(uint256 value, uint256 length) internalpurereturns (stringmemory) {
bytesmemory buffer =newbytes(2* length +2);
buffer[0] ="0";
buffer[1] ="x";
for (uint256 i =2* length +1; i >1; --i) {
buffer[i] = _HEX_SYMBOLS[value &0xf];
value >>=4;
}
require(value ==0, "Strings: hex length insufficient");
returnstring(buffer);
}
}