// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/// @author: manifold.xyzimport"@openzeppelin/contracts/utils/introspection/ERC165.sol";
/**
* @dev Base creator extension variables
*/abstractcontractCreatorExtensionisERC165{
/**
* @dev Legacy extension interface identifiers
*
* {IERC165-supportsInterface} needs to return 'true' for this interface
* in order backwards compatible with older creator contracts
*/bytes4constantinternal LEGACY_EXTENSION_INTERFACE =0x7005caad;
/**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverride(ERC165) returns (bool) {
return interfaceId == LEGACY_EXTENSION_INTERFACE
||super.supportsInterface(interfaceId);
}
}
Contract Source Code
File 2 of 13: ERC165.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)pragmasolidity ^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 13: IAdminControl.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/// @author: manifold.xyzimport"@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @dev Interface for admin control
*/interfaceIAdminControlisIERC165{
eventAdminApproved(addressindexed account, addressindexed sender);
eventAdminRevoked(addressindexed account, addressindexed sender);
/**
* @dev gets address of all admins
*/functiongetAdmins() externalviewreturns (address[] memory);
/**
* @dev add an admin. Can only be called by contract owner.
*/functionapproveAdmin(address admin) external;
/**
* @dev remove an admin. Can only be called by contract owner.
*/functionrevokeAdmin(address admin) external;
/**
* @dev checks whether or not given address is an admin
* Returns True if they are
*/functionisAdmin(address admin) externalviewreturns (bool);
}
Contract Source Code
File 4 of 13: ICreatorCore.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/// @author: manifold.xyzimport"@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @dev Core creator interface
*/interfaceICreatorCoreisIERC165{
eventExtensionRegistered(addressindexed extension, addressindexed sender);
eventExtensionUnregistered(addressindexed extension, addressindexed sender);
eventExtensionBlacklisted(addressindexed extension, addressindexed sender);
eventMintPermissionsUpdated(addressindexed extension, addressindexed permissions, addressindexed sender);
eventRoyaltiesUpdated(uint256indexed tokenId, addresspayable[] receivers, uint256[] basisPoints);
eventDefaultRoyaltiesUpdated(addresspayable[] receivers, uint256[] basisPoints);
eventApproveTransferUpdated(address extension);
eventExtensionRoyaltiesUpdated(addressindexed extension, addresspayable[] receivers, uint256[] basisPoints);
eventExtensionApproveTransferUpdated(addressindexed extension, bool enabled);
/**
* @dev gets address of all extensions
*/functiongetExtensions() externalviewreturns (address[] memory);
/**
* @dev add an extension. Can only be called by contract owner or admin.
* extension address must point to a contract implementing ICreatorExtension.
* Returns True if newly added, False if already added.
*/functionregisterExtension(address extension, stringcalldata baseURI) external;
/**
* @dev add an extension. Can only be called by contract owner or admin.
* extension address must point to a contract implementing ICreatorExtension.
* Returns True if newly added, False if already added.
*/functionregisterExtension(address extension, stringcalldata baseURI, bool baseURIIdentical) external;
/**
* @dev add an extension. Can only be called by contract owner or admin.
* Returns True if removed, False if already removed.
*/functionunregisterExtension(address extension) external;
/**
* @dev blacklist an extension. Can only be called by contract owner or admin.
* This function will destroy all ability to reference the metadata of any tokens created
* by the specified extension. It will also unregister the extension if needed.
* Returns True if removed, False if already removed.
*/functionblacklistExtension(address extension) external;
/**
* @dev set the baseTokenURI of an extension. Can only be called by extension.
*/functionsetBaseTokenURIExtension(stringcalldata uri) external;
/**
* @dev set the baseTokenURI of an extension. Can only be called by extension.
* For tokens with no uri configured, tokenURI will return "uri+tokenId"
*/functionsetBaseTokenURIExtension(stringcalldata uri, bool identical) external;
/**
* @dev set the common prefix of an extension. Can only be called by extension.
* If configured, and a token has a uri set, tokenURI will return "prefixURI+tokenURI"
* Useful if you want to use ipfs/arweave
*/functionsetTokenURIPrefixExtension(stringcalldata prefix) external;
/**
* @dev set the tokenURI of a token extension. Can only be called by extension that minted token.
*/functionsetTokenURIExtension(uint256 tokenId, stringcalldata uri) external;
/**
* @dev set the tokenURI of a token extension for multiple tokens. Can only be called by extension that minted token.
*/functionsetTokenURIExtension(uint256[] memory tokenId, string[] calldata uri) external;
/**
* @dev set the baseTokenURI for tokens with no extension. Can only be called by owner/admin.
* For tokens with no uri configured, tokenURI will return "uri+tokenId"
*/functionsetBaseTokenURI(stringcalldata uri) external;
/**
* @dev set the common prefix for tokens with no extension. Can only be called by owner/admin.
* If configured, and a token has a uri set, tokenURI will return "prefixURI+tokenURI"
* Useful if you want to use ipfs/arweave
*/functionsetTokenURIPrefix(stringcalldata prefix) external;
/**
* @dev set the tokenURI of a token with no extension. Can only be called by owner/admin.
*/functionsetTokenURI(uint256 tokenId, stringcalldata uri) external;
/**
* @dev set the tokenURI of multiple tokens with no extension. Can only be called by owner/admin.
*/functionsetTokenURI(uint256[] memory tokenIds, string[] calldata uris) external;
/**
* @dev set a permissions contract for an extension. Used to control minting.
*/functionsetMintPermissions(address extension, address permissions) external;
/**
* @dev Configure so transfers of tokens created by the caller (must be extension) gets approval
* from the extension before transferring
*/functionsetApproveTransferExtension(bool enabled) external;
/**
* @dev get the extension of a given token
*/functiontokenExtension(uint256 tokenId) externalviewreturns (address);
/**
* @dev Set default royalties
*/functionsetRoyalties(addresspayable[] calldata receivers, uint256[] calldata basisPoints) external;
/**
* @dev Set royalties of a token
*/functionsetRoyalties(uint256 tokenId, addresspayable[] calldata receivers, uint256[] calldata basisPoints) external;
/**
* @dev Set royalties of an extension
*/functionsetRoyaltiesExtension(address extension, addresspayable[] calldata receivers, uint256[] calldata basisPoints) external;
/**
* @dev Get royalites of a token. Returns list of receivers and basisPoints
*/functiongetRoyalties(uint256 tokenId) externalviewreturns (addresspayable[] memory, uint256[] memory);
// Royalty support for various other standardsfunctiongetFeeRecipients(uint256 tokenId) externalviewreturns (addresspayable[] memory);
functiongetFeeBps(uint256 tokenId) externalviewreturns (uint[] memory);
functiongetFees(uint256 tokenId) externalviewreturns (addresspayable[] memory, uint256[] memory);
functionroyaltyInfo(uint256 tokenId, uint256 value) externalviewreturns (address, uint256);
/**
* @dev Set the default approve transfer contract location.
*/functionsetApproveTransfer(address extension) external;
/**
* @dev Get the default approve transfer contract location.
*/functiongetApproveTransfer() externalviewreturns (address);
}
Contract Source Code
File 5 of 13: ICreatorExtensionTokenURI.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/// @author: manifold.xyzimport"@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @dev Implement this if you want your extension to have overloadable URI's
*/interfaceICreatorExtensionTokenURIisIERC165{
/**
* Get the uri for a given creator/tokenId
*/functiontokenURI(address creator, uint256 tokenId) externalviewreturns (stringmemory);
}
Contract Source Code
File 6 of 13: IERC165.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)pragmasolidity ^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 7 of 13: IERC721CreatorCore.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/// @author: manifold.xyzimport"./ICreatorCore.sol";
/**
* @dev Core ERC721 creator interface
*/interfaceIERC721CreatorCoreisICreatorCore{
/**
* @dev mint a token with no extension. Can only be called by an admin.
* Returns tokenId minted
*/functionmintBase(address to) externalreturns (uint256);
/**
* @dev mint a token with no extension. Can only be called by an admin.
* Returns tokenId minted
*/functionmintBase(address to, stringcalldata uri) externalreturns (uint256);
/**
* @dev batch mint a token with no extension. Can only be called by an admin.
* Returns tokenId minted
*/functionmintBaseBatch(address to, uint16 count) externalreturns (uint256[] memory);
/**
* @dev batch mint a token with no extension. Can only be called by an admin.
* Returns tokenId minted
*/functionmintBaseBatch(address to, string[] calldata uris) externalreturns (uint256[] memory);
/**
* @dev mint a token. Can only be called by a registered extension.
* Returns tokenId minted
*/functionmintExtension(address to) externalreturns (uint256);
/**
* @dev mint a token. Can only be called by a registered extension.
* Returns tokenId minted
*/functionmintExtension(address to, stringcalldata uri) externalreturns (uint256);
/**
* @dev mint a token. Can only be called by a registered extension.
* Returns tokenId minted
*/functionmintExtension(address to, uint80 data) externalreturns (uint256);
/**
* @dev batch mint a token. Can only be called by a registered extension.
* Returns tokenIds minted
*/functionmintExtensionBatch(address to, uint16 count) externalreturns (uint256[] memory);
/**
* @dev batch mint a token. Can only be called by a registered extension.
* Returns tokenId minted
*/functionmintExtensionBatch(address to, string[] calldata uris) externalreturns (uint256[] memory);
/**
* @dev batch mint a token. Can only be called by a registered extension.
* Returns tokenId minted
*/functionmintExtensionBatch(address to, uint80[] calldata data) externalreturns (uint256[] memory);
/**
* @dev burn a token. Can only be called by token owner or approved address.
* On burn, calls back to the registered extension's onBurn method
*/functionburn(uint256 tokenId) external;
/**
* @dev get token data
*/functiontokenData(uint256 tokenId) externalviewreturns (uint80);
}
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/// @author: manifold.xyz/**
* Manifold ERC721 Edition Controller interface
*/interfaceIManifoldERC721Edition{
errorInvalidEdition();
errorInvalidInput();
errorTooManyRequested();
errorInvalidToken();
eventSeriesCreated(address caller, address creatorCore, uint256 series, uint256 maxSupply);
structRecipient {
address recipient;
uint16 count;
}
enumStorageProtocol { INVALID, NONE, ARWEAVE, IPFS }
structEditionInfo {
uint192 firstTokenId;
uint8 contractVersion;
uint24 totalSupply;
uint24 maxSupply;
StorageProtocol storageProtocol;
string location;
}
/**
* @dev Create a new series. Returns the series id.
*/functioncreateSeries(address creatorCore, uint256 instanceId, uint24 maxSupply_, StorageProtocol storageProtocol, stringcalldata location, Recipient[] memory recipients) external;
/**
* @dev Set the token uri prefix
*/functionsetTokenURI(address creatorCore, uint256 instanceId, StorageProtocol storageProtocol, stringcalldata location) external;
/**
* @dev Mint NFTs to a single recipient
*/functionmint(address creatorCore, uint256 instanceId, uint24 currentSupply, Recipient[] memory recipients) external;
/**
* @dev Get the EditionInfo for a Series
*/functiongetEditionInfo(address creatorCore, uint256 instanceId) externalviewreturns(EditionInfo memory);
/**
* @dev Get the instance ids for a set of token
*/functiongetInstanceIdsForTokens(address creatorCore, uint256[] calldata tokenIds) externalviewreturns(uint256[] memory);
/**
* @dev Get all the token ids for an instance
*/functiongetInstanceTokenIds(address creatorCore, uint256 instanceId) externalviewreturns(uint256[] memory);
}
Contract Source Code
File 10 of 13: ManifoldERC721Edition.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/// @author: manifold.xyzimport"@manifoldxyz/libraries-solidity/contracts/access/IAdminControl.sol";
import"@manifoldxyz/creator-core-solidity/contracts/core/IERC721CreatorCore.sol";
import"@manifoldxyz/creator-core-solidity/contracts/extensions/CreatorExtension.sol";
import"@manifoldxyz/creator-core-solidity/contracts/extensions/ICreatorExtensionTokenURI.sol";
import"@openzeppelin/contracts/security/ReentrancyGuard.sol";
import"@openzeppelin/contracts/utils/Strings.sol";
import"../libraries/IERC721CreatorCoreVersion.sol";
import"./IManifoldERC721Edition.sol";
/**
* Manifold ERC721 Edition Controller Implementation
*/contractManifoldERC721EditionisCreatorExtension, ICreatorExtensionTokenURI, IManifoldERC721Edition, ReentrancyGuard{
usingStringsforuint256;
structIndexRange {
uint256 startIndex;
uint256 count;
}
stringprivateconstant ARWEAVE_PREFIX ="https://arweave.net/";
stringprivateconstant IPFS_PREFIX ="ipfs://";
uint256privateconstant MAX_UINT_24 =0xffffff;
uint256privateconstant MAX_UINT_56 =0xffffffffffffff;
uint256privateconstant MAX_UINT_192 =0xffffffffffffffffffffffffffffffffffffffffffffffff;
mapping(address=>mapping(uint256=> EditionInfo)) _editionInfo;
mapping(address=>mapping(uint256=> IndexRange[])) _indexRanges;
mapping(address=>uint256[]) _creatorInstanceIds;
/**
* @dev Only allows approved admins to call the specified function
*/modifiercreatorAdminRequired(address creator) {
if (!IAdminControl(creator).isAdmin(msg.sender)) revert("Must be owner or admin of creator contract");
_;
}
functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverride(CreatorExtension, IERC165) returns (bool) {
return
interfaceId ==type(ICreatorExtensionTokenURI).interfaceId||
interfaceId ==type(IManifoldERC721Edition).interfaceId||
CreatorExtension.supportsInterface(interfaceId);
}
/**
* @dev See {IManifoldERC721Edition-createSeries}.
*/functioncreateSeries(address creatorCore, uint256 instanceId, uint24 maxSupply_, StorageProtocol storageProtocol, stringcalldata location, Recipient[] memory recipients) externaloverridecreatorAdminRequired(creatorCore) {
if (instanceId ==0||
instanceId > MAX_UINT_56 ||
maxSupply_ ==0||
storageProtocol == StorageProtocol.INVALID ||
_editionInfo[creatorCore][instanceId].storageProtocol != StorageProtocol.INVALID
) revert InvalidInput();
uint8 creatorContractVersion;
try IERC721CreatorCoreVersion(creatorCore).VERSION() returns(uint256 version) {
require(version <=255, "Unsupported contract version");
creatorContractVersion =uint8(version);
} catch {}
_editionInfo[creatorCore][instanceId] = EditionInfo({
maxSupply: maxSupply_,
totalSupply: 0,
contractVersion: creatorContractVersion,
storageProtocol: storageProtocol,
location: location,
firstTokenId: 0
});
if (creatorContractVersion <3) {
_creatorInstanceIds[creatorCore].push(instanceId);
}
emit SeriesCreated(msg.sender, creatorCore, instanceId, maxSupply_);
if (recipients.length>0) _mintTokens(creatorCore, instanceId, _editionInfo[creatorCore][instanceId], recipients);
}
/**
* See {IManifoldERC721Edition-setTokenURI}.
*/functionsetTokenURI(address creatorCore, uint256 instanceId, StorageProtocol storageProtocol, stringcalldata location) externaloverridecreatorAdminRequired(creatorCore) {
if (storageProtocol == StorageProtocol.INVALID) revert InvalidInput();
EditionInfo storage info = _getEditionInfo(creatorCore, instanceId);
info.storageProtocol = storageProtocol;
info.location = location;
}
function_getEditionInfo(address creatorCore, uint256 instanceId) privateviewreturns(EditionInfo storage info) {
info = _editionInfo[creatorCore][instanceId];
if (info.storageProtocol == StorageProtocol.INVALID) revert InvalidEdition();
}
/**
* @dev See {IManifoldERC721Edition-getEditionInfo}.
*
* This is the public version of the above internal function. Separate function because it returns EditionInfo
* memory instead of storage.
*/functiongetEditionInfo(address creatorCore, uint256 instanceId) publicviewreturns(EditionInfo memory info) {
info = _editionInfo[creatorCore][instanceId];
if (info.storageProtocol == StorageProtocol.INVALID) revert InvalidEdition();
}
/**
* @dev See {IManifoldERC721Edition-getInstanceIdsForTokens}.
*/functiongetInstanceIdsForTokens(address creatorCore, uint256[] calldata tokenIds) externalviewoverridereturns(uint256[] memory instanceIds) {
instanceIds =newuint256[](tokenIds.length);
for (uint256 i; i < tokenIds.length;) {
uint256 tokenId = tokenIds[i];
try IERC721CreatorCore(creatorCore).tokenExtension(tokenId) returns(address tokenExtension) {
if (tokenExtension ==address(this)) {
uint256 creatorContractVersion;
uint256 instanceId;
try IERC721CreatorCoreVersion(creatorCore).VERSION() returns(uint256 version) {
creatorContractVersion = version;
} catch {}
if (creatorContractVersion >=3) {
// Contract versions 3+ support storage of data with the token mint, so use thatuint80 tokenData = IERC721CreatorCore(creatorCore).tokenData(tokenId);
instanceId =uint56(tokenData >>24);
} else {
(instanceId, ) = _tokenInstanceAndIndex(creatorCore, tokenId);
}
instanceIds[i] = instanceId;
}
} catch {}
unchecked{++i;}
}
}
/**
* @dev See {IManifoldERC721Edition-getInstanceTokenIds}.
*/functiongetInstanceTokenIds(address creatorCore, uint256 instanceId) externalviewreturns(uint256[] memory tokenIds) {
EditionInfo storage info = _getEditionInfo(creatorCore, instanceId);
uint256 creatorContractVersion;
tokenIds =newuint256[](info.totalSupply);
try IERC721CreatorCoreVersion(creatorCore).VERSION() returns(uint256 version) {
creatorContractVersion = version;
} catch {}
if (creatorContractVersion >=3) {
// We do not have index ranges, so seek based on first tokenIduint256 tokenId = info.firstTokenId;
uint256 foundTokens;
while (foundTokens < info.totalSupply) {
try IERC721CreatorCore(creatorCore).tokenExtension(tokenId) returns(address tokenExtension) {
if (tokenExtension ==address(this)) {
uint80 tokenData = IERC721CreatorCore(creatorCore).tokenData(tokenId);
if (instanceId ==uint56(tokenData >>24)) {
tokenIds[foundTokens] = tokenId;
unchecked{++foundTokens;}
}
}
} catch {}
unchecked{++tokenId;}
}
} else {
// We have index ranges, so we can just iterate through them
IndexRange[] memory indexRanges = _indexRanges[creatorCore][instanceId];
uint256 current;
for (uint256 i; i < indexRanges.length;) {
IndexRange memory currentIndex = indexRanges[i];
for (uint256 j; j < currentIndex.count;) {
tokenIds[current] = currentIndex.startIndex + j;
unchecked{++current; ++j;}
}
unchecked{++i;}
}
}
}
/**
* @dev See {ICreatorExtensionTokenURI-tokenURI}.
*/functiontokenURI(address creatorCore, uint256 tokenId) externalviewoverridereturns (stringmemory) {
uint256 creatorContractVersion;
try IERC721CreatorCoreVersion(creatorCore).VERSION() returns(uint256 version) {
creatorContractVersion = version;
} catch {}
uint256 instanceId;
uint256 index;
if (creatorContractVersion >=3) {
// Contract versions 3+ support storage of data with the token mint, so use thatuint80 tokenData = IERC721CreatorCore(creatorCore).tokenData(tokenId);
instanceId =uint56(tokenData >>24);
if (instanceId ==0) revert InvalidToken();
index =uint256(tokenData & MAX_UINT_24);
} else {
(instanceId, index) = _tokenInstanceAndIndex(creatorCore, tokenId);
}
EditionInfo storage info = _getEditionInfo(creatorCore, instanceId);
stringmemory prefix ="";
if (info.storageProtocol == StorageProtocol.ARWEAVE) {
prefix = ARWEAVE_PREFIX;
} elseif (info.storageProtocol == StorageProtocol.IPFS) {
prefix = IPFS_PREFIX;
}
returnstring(abi.encodePacked(prefix, info.location, "/", (index+1).toString()));
}
/**
* @dev See {IManifoldERC721Edition-mint}.
*/functionmint(address creatorCore, uint256 instanceId, uint24 currentSupply, Recipient[] memory recipients) externaloverridenonReentrantcreatorAdminRequired(creatorCore) {
EditionInfo storage info = _getEditionInfo(creatorCore, instanceId);
if (currentSupply != info.totalSupply) revert InvalidInput();
_mintTokens(creatorCore, instanceId, info, recipients);
}
function_mintTokens(address creatorCore, uint256 instanceId, EditionInfo storage info, Recipient[] memory recipients) private{
if (recipients.length==0) revert InvalidInput();
if (info.totalSupply+1> info.maxSupply) revert TooManyRequested();
uint256[] memory tokenIdResults;
if (info.contractVersion >=3) {
uint16 count =0;
uint24 totalSupply_ = info.totalSupply;
uint24 maxSupply_ = info.maxSupply;
uint256 newMintIndex = totalSupply_;
// Contract versions 3+ support storage of data with the token mint, so use that// to avoid additional storage costsfor (uint256 i; i < recipients.length;) {
uint16 mintCount = recipients[i].count;
if (mintCount ==0) revert InvalidInput();
count += mintCount;
if (totalSupply_+count > maxSupply_) revert TooManyRequested();
uint80[] memory tokenDatas =newuint80[](mintCount);
for (uint256 j; j < mintCount;) {
tokenDatas[j] =uint56(instanceId) <<24|uint24(newMintIndex+j);
unchecked {++j;}
}
// Airdrop the tokens
tokenIdResults = IERC721CreatorCore(creatorCore).mintExtensionBatch(recipients[i].recipient, tokenDatas);
if (i ==0&& info.firstTokenId ==0) {
if (tokenIdResults[0] > MAX_UINT_192) revert InvalidInput();
info.firstTokenId =uint192(tokenIdResults[0]);
}
// Increment newMintIndex for the next airdropunchecked{newMintIndex += mintCount;}
unchecked{++i;}
}
info.totalSupply += count;
} else {
uint256 startIndex;
uint16 count =0;
uint24 totalSupply_ = info.totalSupply;
uint24 maxSupply_ = info.maxSupply;
for (uint256 i; i < recipients.length;) {
if (recipients[i].count ==0) revert InvalidInput();
count += recipients[i].count;
if (totalSupply_+count > maxSupply_) revert TooManyRequested();
tokenIdResults = IERC721CreatorCore(creatorCore).mintExtensionBatch(recipients[i].recipient, recipients[i].count);
if (i ==0) {
startIndex = tokenIdResults[0];
if (info.firstTokenId ==0) {
if (startIndex > MAX_UINT_192) revert InvalidInput();
info.firstTokenId =uint192(startIndex);
}
}
unchecked{++i;}
}
_updateIndexRanges(creatorCore, instanceId, info, startIndex, count);
}
}
/**
* @dev Update the index ranges, which is used to figure out the index from a tokenId
*/function_updateIndexRanges(address creatorCore, uint256 instanceId, EditionInfo storage info, uint256 startIndex, uint16 count) internal{
IndexRange[] storage indexRanges = _indexRanges[creatorCore][instanceId];
if (indexRanges.length==0) {
indexRanges.push(IndexRange(startIndex, count));
} else {
IndexRange storage lastIndexRange = indexRanges[indexRanges.length-1];
if ((lastIndexRange.startIndex + lastIndexRange.count) == startIndex) {
lastIndexRange.count += count;
} else {
indexRanges.push(IndexRange(startIndex, count));
}
}
info.totalSupply += count;
}
/**
* @dev Index from tokenId
*/function_tokenInstanceAndIndex(address creatorCore, uint256 tokenId) internalviewreturns(uint256, uint256) {
// Go through all their series until we find the tokenIdfor (uint256 i; i < _creatorInstanceIds[creatorCore].length;) {
uint256 instanceId = _creatorInstanceIds[creatorCore][i];
IndexRange[] memory indexRanges = _indexRanges[creatorCore][instanceId];
uint256 offset;
for (uint j; j < indexRanges.length;) {
IndexRange memory currentIndex = indexRanges[j];
if (tokenId < currentIndex.startIndex) break;
if (tokenId >= currentIndex.startIndex && tokenId < currentIndex.startIndex + currentIndex.count) {
return (instanceId, tokenId - currentIndex.startIndex + offset);
}
offset += currentIndex.count;
unchecked{++j;}
}
unchecked{++i;}
}
revert InvalidToken();
}
}
Contract Source Code
File 11 of 13: Math.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)pragmasolidity ^0.8.0;/**
* @dev Standard math utilities missing in the Solidity language.
*/libraryMath{
enumRounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/functionmax(uint256 a, uint256 b) internalpurereturns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/functionmin(uint256 a, uint256 b) internalpurereturns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/functionaverage(uint256 a, uint256 b) internalpurereturns (uint256) {
// (a + b) / 2 can overflow.return (a & b) + (a ^ b) /2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/functionceilDiv(uint256 a, uint256 b) internalpurereturns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.return a ==0 ? 0 : (a -1) / b +1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/functionmulDiv(uint256 x,
uint256 y,
uint256 denominator
) internalpurereturns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256// variables such that product = prod1 * 2^256 + prod0.uint256 prod0; // Least significant 256 bits of the productuint256 prod1; // Most significant 256 bits of the productassembly {
let mm :=mulmod(x, y, not(0))
prod0 :=mul(x, y)
prod1 :=sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.if (prod1 ==0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.require(denominator > prod1);
///////////////////////////////////////////////// 512 by 256 division.///////////////////////////////////////////////// Make division exact by subtracting the remainder from [prod1 prod0].uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder :=mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 :=sub(prod1, gt(remainder, prod0))
prod0 :=sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.// See https://cs.stackexchange.com/q/138556/92363.// Does not overflow because the denominator cannot be zero at this stage in the function.uint256 twos = denominator & (~denominator +1);
assembly {
// Divide denominator by twos.
denominator :=div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 :=div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos :=add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for// four bits. That is, denominator * inv = 1 mod 2^4.uint256 inverse = (3* denominator) ^2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works// in modular arithmetic, doubling the correct bits in each step.
inverse *=2- denominator * inverse; // inverse mod 2^8
inverse *=2- denominator * inverse; // inverse mod 2^16
inverse *=2- denominator * inverse; // inverse mod 2^32
inverse *=2- denominator * inverse; // inverse mod 2^64
inverse *=2- denominator * inverse; // inverse mod 2^128
inverse *=2- denominator * inverse; // inverse mod 2^256// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/functionmulDiv(uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internalpurereturns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up &&mulmod(x, y, denominator) >0) {
result +=1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/functionsqrt(uint256 a) internalpurereturns (uint256) {
if (a ==0) {
return0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.//// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.//// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`//// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.uint256 result =1<< (log2(a) >>1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision// into the expected uint128 result.unchecked {
result = (result + a / result) >>1;
result = (result + a / result) >>1;
result = (result + a / result) >>1;
result = (result + a / result) >>1;
result = (result + a / result) >>1;
result = (result + a / result) >>1;
result = (result + a / result) >>1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/functionsqrt(uint256 a, Rounding rounding) internalpurereturns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/functionlog2(uint256 value) internalpurereturns (uint256) {
uint256 result =0;
unchecked {
if (value >>128>0) {
value >>=128;
result +=128;
}
if (value >>64>0) {
value >>=64;
result +=64;
}
if (value >>32>0) {
value >>=32;
result +=32;
}
if (value >>16>0) {
value >>=16;
result +=16;
}
if (value >>8>0) {
value >>=8;
result +=8;
}
if (value >>4>0) {
value >>=4;
result +=4;
}
if (value >>2>0) {
value >>=2;
result +=2;
}
if (value >>1>0) {
result +=1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/functionlog2(uint256 value, Rounding rounding) internalpurereturns (uint256) {
unchecked {
uint256 result =log2(value);
return result + (rounding == Rounding.Up &&1<< result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/functionlog10(uint256 value) internalpurereturns (uint256) {
uint256 result =0;
unchecked {
if (value >=10**64) {
value /=10**64;
result +=64;
}
if (value >=10**32) {
value /=10**32;
result +=32;
}
if (value >=10**16) {
value /=10**16;
result +=16;
}
if (value >=10**8) {
value /=10**8;
result +=8;
}
if (value >=10**4) {
value /=10**4;
result +=4;
}
if (value >=10**2) {
value /=10**2;
result +=2;
}
if (value >=10**1) {
result +=1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/functionlog10(uint256 value, Rounding rounding) internalpurereturns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up &&10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/functionlog256(uint256 value) internalpurereturns (uint256) {
uint256 result =0;
unchecked {
if (value >>128>0) {
value >>=128;
result +=16;
}
if (value >>64>0) {
value >>=64;
result +=8;
}
if (value >>32>0) {
value >>=32;
result +=4;
}
if (value >>16>0) {
value >>=16;
result +=2;
}
if (value >>8>0) {
result +=1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/functionlog256(uint256 value, Rounding rounding) internalpurereturns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up &&1<< (result *8) < value ? 1 : 0);
}
}
}
Contract Source Code
File 12 of 13: ReentrancyGuard.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)pragmasolidity ^0.8.0;/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/abstractcontractReentrancyGuard{
// Booleans are more expensive than uint256 or any type that takes up a full// word because each write operation emits an extra SLOAD to first read the// slot's contents, replace the bits taken up by the boolean, and then write// back. This is the compiler's defense against contract upgrades and// pointer aliasing, and it cannot be disabled.// The values being non-zero value makes deployment a bit more expensive,// but in exchange the refund on every call to nonReentrant will be lower in// amount. Since refunds are capped to a percentage of the total// transaction's gas, it is best to keep them low in cases like this one, to// increase the likelihood of the full refund coming into effect.uint256privateconstant _NOT_ENTERED =1;
uint256privateconstant _ENTERED =2;
uint256private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/modifiernonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function_nonReentrantBefore() private{
// On the first call to nonReentrant, _status will be _NOT_ENTEREDrequire(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function_nonReentrantAfter() private{
// By storing the original value once again, a refund is triggered (see// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
Contract Source Code
File 13 of 13: Strings.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)pragmasolidity ^0.8.0;import"./math/Math.sol";
/**
* @dev String operations.
*/libraryStrings{
bytes16privateconstant _SYMBOLS ="0123456789abcdef";
uint8privateconstant _ADDRESS_LENGTH =20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/functiontoString(uint256 value) internalpurereturns (stringmemory) {
unchecked {
uint256 length = Math.log10(value) +1;
stringmemory buffer =newstring(length);
uint256 ptr;
/// @solidity memory-safe-assemblyassembly {
ptr :=add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assemblyassembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /=10;
if (value ==0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/functiontoHexString(uint256 value) internalpurereturns (stringmemory) {
unchecked {
return toHexString(value, Math.log256(value) +1);
}
}
/**
* @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] = _SYMBOLS[value &0xf];
value >>=4;
}
require(value ==0, "Strings: hex length insufficient");
returnstring(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/functiontoHexString(address addr) internalpurereturns (stringmemory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}