@niftory/solidity-contracts v0.0.2
Niftory Smart Contracts for EVM Compatible Blockchains
This repository hosts all smart contracts (and related scripts, tests, etc.) for Niftory, an NFT management platform. Niftory NFTs are ERC1155 compatible.
Note: This README is autogenerated. Please modify docs from within the docs folder and run yarn build to regenerate.
Usage
In order to use the contract, just extend one of the contracts from the impl folder. Currently, there is only NiftoryStandardERC1155.
Typed APIs, generated with typechain, can be accessed via src/bindings. NiftoryStandardERC1155Interface from here is the best place to see the full accessible API in one place.
Overview
Each uniquely identifiable ERC1155 token maps to a unique set (via setId) and template (via templateId) pair. The IERC1155 token id (e.g. for the uri function) can be expressed as (setId << 64) + templateId, as setId and templateId are both 64 bits each.
A contract can have multiple sets, and each set can have multiple templates. Indexing for both starts at 1 (so there is no set with setId=0 or template with templateId=0 in any set).
Each template maps to exactly one uri, which can be modified by an Admin or SetAdmin (see next section). templates also keep track of how many NFTs have been minted for that template and how many are allowed to minted (maxMint). A template with a maxMint of 0 allows unlimited minting. A maxMint may be set later, however.
sets can be locked to prevent more templates from being added, and templates can have metadata modification and minting locked separately.
sets allow Admins to delegate control to a collection of templates to a SetAdmin, allowing the SetAdmin to lock and mint from sets it owns.
Roles and Actions
This contract uses a very simple RBAC style management with three different roles, as below.
Admin
An Admin is the superuser of the contract. An Admin can
- Assign (or revoke) more Admins
- Assign (or revoke) SetAdmins
- Create & lock sets
- Add templates to any set
- Mint from any mintable template
- Change the metadata for any template
- Modify the maximum mint amount for any template
- Lock metadata and minting for any template
- Modify the global default URI
Set Admin
A SetAdmin is an adminstrator of sets it has been given power over, either from an Admin or another previous SetAdmin. A SetAdmin can
- Assign (or revoke) SetAdmins from the sets it owns
- Lock sets it owns
- Add templates to sets it owns
- Mint from mintable templates of sets it owns
- Change the metadata of templates of sets it owns
- Modify the maximum mint amount for templates of sets it owns
- Lock metadata and minting for templates of sets it owns
Collector
Collector is another way of saying "no role" and can be anyone with an account on the blockchain. A Collector can
- Hold and transfer tokens
- Approve another account to manage tokens
- Burn tokens
All the above functionality is provided by OpenZeppelin's ERC1155 implementation.
Architecture
There are three extensions that can be used to power this token, which all assume that an ERC1155 token uses the set/template scheme mentioned above.
The main NiftoryStandardERC1155 uses OpenZeppelin's ERC1155Burnable.sol as a base. There are three custom extensions used, which can be found in contracts/extensions
UriManagermanages URI's for templates and allows modification. If the URI is blank, it will use the default_defaultUri.RoleManagermanages the Admin and SetAdmin based ownership.RoleManagermaps an(address, setId)pair to a boolean value indicating whetheraddressis a SetAdmin of setsetId. The 0-th bit is used to indicate an Admin. This extension uses a custom library (lib/AddressIndexedBitmap.sol) in order to tightly pack the boolean role indicatorTemplateManageris broken into two parts - theSetManagerand the derivingTemplateManager. TheSetManagerstoresSets in asetId => Setmap. ASetneeds to keep track of how many templates it contains, and also allows locking to stop more templates from being added.TemplateManagermanages eachTemplate, keeping track of what the max mint is, how many NFTs have been minted from it, whether metadata can still be modified, and whether minting is still unlocked.
There are also two libraries in the lib folder - AddressedIndexedBitmap.sol and TemplateBasedId.sol. AddressedIndexedBitmap was already mentioned above, but TemplateBasedId provides a 1-1 mapping from (uint64 setId, uint64 templateId) <=> uint256 id), in order to adhere to IERC1155.
Development
yarn- install all node dependenciesyarn clean- remove all hardhat generated filesyarn compile- compile Solidity files and generate docsyarn build- clean and compileyarn test- build and run tests (and show gas usage information)yarn coverage- generate coverage reports
Solidity API
AddressIndexedBitmap
A bitmap that can be efficiently indexed by an (address, uint64) pair.
Best if used as a decorator for a mapping of (uint256 => uint256)
getBit
function getBit(mapping(uint256 => uint256) bitmap, address addr, uint64 index) internal view returns (bool)get the bit at position index for addr in bitmap
Parameters
| Name | Type | Description |
|---|---|---|
| bitmap | mapping(uint256 => uint256) | the underlying bitmap - target of decorator |
| addr | address | the address to index into the bitmap |
| index | uint64 | the bit to get |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | bool | the bit at position index for addr in bitmap |
setBit
function setBit(mapping(uint256 => uint256) bitmap, address addr, uint64 index) internalset the bit at position index for addr in bitmap
Parameters
| Name | Type | Description |
|---|---|---|
| bitmap | mapping(uint256 => uint256) | the underlying bitmap - target of decorator |
| addr | address | the address to index into the bitmap |
| index | uint64 | the bit to set |
clearBit
function clearBit(mapping(uint256 => uint256) bitmap, address addr, uint64 index) internalclear the bit at position index for addr in bitmap
Parameters
| Name | Type | Description |
|---|---|---|
| bitmap | mapping(uint256 => uint256) | the underlying bitmap - target of decorator |
| addr | address | the address to index into the bitmap |
| index | uint64 | the bit to clear |
_wordIndex
function _wordIndex(address addr, uint64 index) private pure returns (uint256)get the word index for addr and index
Parameters
| Name | Type | Description |
|---|---|---|
| addr | address | the address part of the bitmap key |
| index | uint64 | the index part of the bitmap key |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | uint256 | essentially addr << 64 + index/256 |
NiftoryStandardERC1155
This is an implementation of ERC1155. It uses ERC1155Burnable from
OpenZeppelin as a base. This contract uses three custom extensions.
TemplateManager provides data structures to organize our contract into
Sets and Templates. A contract can have multiple Sets, and each Set
can have multiple Templates. Each unique token 1-1 maps with a Template.
UriManager manages the URIs for each Template, or provides a default
if a particular token doesn't have a URI set.
RoleManager helps provide gated access to mutating functions to Admins,
who have full control over all functions, and Set Admins, who have access
to mutate Sets that they have been privileged for.
AdminsAssigned
event AdminsAssigned(uint64 setId, address[] admins)AdminsRevoked
event AdminsRevoked(uint64 setId, address[] admins)SetsAdded
event SetsAdded(uint64[] setIds)SetsLocked
event SetsLocked(uint64[] setIds)TemplatesAdded
event TemplatesAdded(uint64 setId, uint64[] templateIds)TemplatesMetadataLocked
event TemplatesMetadataLocked(uint64 setId, uint64[] templateIds)SetMetadataLocked
event SetMetadataLocked(uint64 setId)TemplatesMaxMintModified
event TemplatesMaxMintModified(uint64 setId, uint64[] templateIds, uint64[] newMaxes)TemplatesMintingLocked
event TemplatesMintingLocked(uint64 setId, uint64[] templateIds)SetMintingLocked
event SetMintingLocked(uint64 setId)constructor
constructor(string defaultUri) publicParameters
| Name | Type | Description |
|---|---|---|
| defaultUri | string | default URI of tokens without their own URI |
uri
function uri(uint256 tokenId) public view returns (string)_See {IERC1155MetadataURI-uri}.
This implementation returns the same URI for all token types. It relies on the token type ID substitution mechanism https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
Clients calling this function must replace the \{id\} substring with the
actual token type ID._
modifyDefaultUri
function modifyDefaultUri(string newDefaultUri) externalmodify the default URI if the caller isAdmin
Parameters
| Name | Type | Description |
|---|---|---|
| newDefaultUri | string | new default URI |
assignAdmins
function assignAdmins(address[] addrs) externalassign all addrs as a new Admins, only if caller isAdmin.
Parameters
| Name | Type | Description |
|---|---|---|
| addrs | address[] | the addresses to assign as Admins |
revokeAdmins
function revokeAdmins(address[] addrs) externalrevoke all addrs's Admin roles, only if caller isAdmin.
Parameters
| Name | Type | Description |
|---|---|---|
| addrs | address[] | the addresses to revoke as Admins |
assignSetAdmins
function assignSetAdmins(uint64 setId, address[] addrs) externalassign all addrs as new SetAdmins for the set with id setId,
only if caller isSetAdmin.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | the set ID to assign new SetAdmins to |
| addrs | address[] | the addresses to assign as SetAdmins |
revokeSetAdmins
function revokeSetAdmins(uint64 setId, address[] addrs) externalrevoke all addrs's SetAdmin roles for the set with id setId,
only if caller isSetAdmin.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | the set ID to revoke SetAdmins from |
| addrs | address[] | the addresses to revoke as SetAdmins |
addSets
function addSets(uint64 numNewSets) externaladd new sets if caller isAdmin.
Parameters
| Name | Type | Description |
|---|---|---|
| numNewSets | uint64 | number of sets to add |
_lockSet
function _lockSet(uint64 setId) internallock a set
overriden to check if caller is Set Admin of setId
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
lockSets
function lockSets(uint64[] setIds) externallock multiple sets if caller isAdmin.
Parameters
| Name | Type | Description |
|---|---|---|
| setIds | uint64[] | set IDs |
_modifyUri
function _modifyUri(uint64 setId, uint64 templateId, string newUri) internalmodify the URI for a token
overriden to check ifTemplateMetadataUnlocked
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
| newUri | string | new URI |
addTemplates
function addTemplates(uint64 setId, uint64 numNewTemplates, uint64[] maxMints, string[] uris) externaladd templates to a set and add their URIs if caller is Set
admin
new templates are given an ID based on the number of templates in
set setId
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| numNewTemplates | uint64 | number of new templates to add |
| maxMints | uint64[] | maximum number of NFTs that can be minted from each template |
| uris | string[] | URIs for each template |
modifyMetadataForTemplates
function modifyMetadataForTemplates(uint64 setId, uint64[] templateIds, string[] newUris) externalmodify the URIs for a given list of templates within a set, only
if caller is Set Admin of Set setId.
requires templateIds.length == newUris.length as they map 1-1
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateIds | uint64[] | list of template IDs |
| newUris | string[] | list of new URIs |
lockMetadataForTemplates
function lockMetadataForTemplates(uint64 setId, uint64[] templateIds) externallock metadata for multiple Templates within a set, only if
caller is Set Admin of Set setId.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateIds | uint64[] | template IDs |
lockMetadataForSet
function lockMetadataForSet(uint64 setId) externallock metadata for all Templates within a set, only if caller
is Set Admin of Set setId.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
modifyMaxMints
function modifyMaxMints(uint64 setId, uint64[] templateIds, uint64[] newMaxes) externalmodify the maximum number of NFTs that can be minted from
multiple Templates, if not already set, only if caller is Set Admin
of Set setId.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateIds | uint64[] | template IDs |
| newMaxes | uint64[] | new maximum number of NFTs that can be minted from |
mintFromTemplates
function mintFromTemplates(address to, uint64 setId, uint64[] templateIds, uint64[] amounts) externalbulk mint NFTs for multiple Templates, if the Templates are
not locked and no max mints will be surpassed, only if caller is Set
Admin of Set setId.
Parameters
| Name | Type | Description |
|---|---|---|
| to | address | address to mint to |
| setId | uint64 | set ID |
| templateIds | uint64[] | template IDs |
| amounts | uint64[] | number of NFTs to register |
lockMintingForTemplates
function lockMintingForTemplates(uint64 setId, uint64[] templateIds) externallock minting for multiple Templates within a set, only if
caller is Set Admin of Set setId.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateIds | uint64[] | template IDs |
lockMintingForSet
function lockMintingForSet(uint64 setId) externallock minting for all Templates within a set, only if caller
is Set Admin of Set setId.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
RoleManager
A helper that manages roles for an NFT implementation. Roles include Admin and SetAdmin. An Admin manages an entire contract, while a SetAdmin can manage specific sets.
implemented using AddressIndexedBitmap. bitmap[0] respresents
whether an address is an Admin, while bitmap[setId] (where setId >= 1)
represents whether an address is a SetAdmin for the set with id setId.
_ADMIN_BIT
uint64 _ADMIN_BITthe special ADMIN_BIT refers to the 0'th bit in the bitmap
_roles
mapping(uint256 => uint256) _rolesthe underlying bitmap from (address, setId) => bool
isAdmin
function isAdmin(address addr) public view returns (bool)check whether addr is an Admin
Parameters
| Name | Type | Description |
|---|---|---|
| addr | address | the address to check |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | bool | true if addr is an Admin |
isSetAdmin
function isSetAdmin(uint64 setId, address addr) public view returns (bool)check whether addr is a SetAdmin for the set with id setId
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | the set ID to check |
| addr | address | the address to check |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | bool | true if addr is a SetAdmin for the set with id setId |
_assignAdmin
function _assignAdmin(address addr) internal virtualassign addr as a new Admin
this should not be exposed externally. Override this just to add
restrictions. Use _assignAdmins instead.
Parameters
| Name | Type | Description |
|---|---|---|
| addr | address | the address to assign as an Admin |
_assignAdmins
function _assignAdmins(address[] addrs) internalassign all addrs as a new Admins, only if caller isAdmin.
Parameters
| Name | Type | Description |
|---|---|---|
| addrs | address[] | the addresses to assign as Admins |
_revokeAdmin
function _revokeAdmin(address addr) internal virtualrevoke addr's Admin role
this should not be exposed externally. Override this just to add
restrictions. Use _revokeAdmins instead.
Parameters
| Name | Type | Description |
|---|---|---|
| addr | address | the address to revoke as Admin |
_revokeAdmins
function _revokeAdmins(address[] addrs) internalrevoke all addrs's Admin roles, only if caller isAdmin.
Parameters
| Name | Type | Description |
|---|---|---|
| addrs | address[] | the addresses to revoke as Admins |
_assignSetAdmin
function _assignSetAdmin(uint64 setId, address addr) internal virtualassign addr as a new SetAdmin for the set with id setId
this should not be exposed externally. Override this just to add
restrictions. Use _assignSetAdmins instead.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | the set ID to assign a new SetAdmin |
| addr | address | the address to assign as a SetAdmin |
_assignSetAdmins
function _assignSetAdmins(uint64 setId, address[] addrs) internalassign all addrs as new SetAdmins for the set with id setId,
only if caller isSetAdmin.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | the set ID to assign new SetAdmins to |
| addrs | address[] | the addresses to assign as SetAdmins |
_revokeSetAdmin
function _revokeSetAdmin(uint64 setId, address addr) internal virtualrevoke addr's SetAdmin role for the set with id setId
this should not be exposed externally. Override this just to add
restrictions. Use _revokeSetAdmins instead.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | the set ID to revoke a SetAdmin from |
| addr | address | the address to revoke as a SetAdmin |
_revokeSetAdmins
function _revokeSetAdmins(uint64 setId, address[] addrs) internalrevoke all addrs's SetAdmin roles for the set with id setId,
only if caller isSetAdmin.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | the set ID to revoke SetAdmins from |
| addrs | address[] | the addresses to revoke as SetAdmins |
ifAdmin
modifier ifAdmin()check whether msg.sender is an Admin, revert if not
ifSetAdmin
modifier ifSetAdmin(uint64 setId)check whether msg.sender is a SetAdmin for the set with id
setId, revert if not
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | the set ID to check |
TemplateBasedId
ERC1155 tokens use a single uint256 to represent a token ID.
This library provides a way to encode a uint64 set ID and a uint64 template
ID into a single uint256 id so that it can be combined into a key that fits
in a single EVM slot. Useful for functions like IERC1155#uri
This can be used as a decorator for the uint256 tokenId decoding
encodeAsTokenId
function encodeAsTokenId(uint64 setId, uint64 templateId) internal pure returns (uint256)bijectively encode setId and templateId into a single
uint256 id
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | uint256 | encoded ID |
decodeSetId
function decodeSetId(uint256 tokenId) internal pure returns (uint64)decode tokenId into a uint64 set ID
Parameters
| Name | Type | Description |
|---|---|---|
| tokenId | uint256 | encoded ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | uint64 | set ID |
decodeTemplateId
function decodeTemplateId(uint256 tokenId) internal pure returns (uint64)decode tokenId into a uint64 template ID
Parameters
| Name | Type | Description |
|---|---|---|
| tokenId | uint256 | encoded ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | uint64 | template ID |
SetManager
A generic NFT extension that allows NFTs to be organized within
Sets. Each Set has a unique ID within an NFT contract and can contain
multiple Templates (which has its own contract below this one).
The NFT contract should inherit from TemplateManager and not this
SetManager contract.
_numSets
uint64 _numSetsnumber of sets this contract has - used to determine valid set IDs
_sets
mapping(uint64 => struct SetManager.Set) _setsmapping from set ID to its corresponding Set struct
Set
struct Set {
uint64 numTemplates;
bool locked;
}numSets
function numSets() public view returns (uint64)number of sets this contract has
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | uint64 | number of sets |
setExists
function setExists(uint64 setId) public view returns (bool)check if a set exists. Valid set IDs are between 1, numSets.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | bool | true if set exists |
set
function set(uint64 setId) public view returns (struct SetManager.Set)get Set with id setId
only a copy - cannot modify Set in storage
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | struct SetManager.Set | a copy of the Set struct with id setId |
numTemplatesInSet
function numTemplatesInSet(uint64 setId) public view returns (uint64)number of templates in a set
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | uint64 | number of templates |
isSetLocked
function isSetLocked(uint64 setId) public view returns (bool)check if a set is locked
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | bool | true if set is locked |
_addSets
function _addSets(uint64 numNewSets) internaladd new sets
Parameters
| Name | Type | Description |
|---|---|---|
| numNewSets | uint64 | number of sets to add |
_incrementNumTemplates
function _incrementNumTemplates(uint64 setId, uint64 amount) internalincrement the number of templates in a set
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| amount | uint64 | amount to increment by |
_lockSet
function _lockSet(uint64 setId) internal virtuallock a set
this should not be exposed externally. Override this just to add
restrictions. Use _lockSets instead.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
_lockSets
function _lockSets(uint64[] setIds) internallock multiple sets
Parameters
| Name | Type | Description |
|---|---|---|
| setIds | uint64[] | set IDs |
ifSetExists
modifier ifSetExists(uint64 setId)check if set exists, otherwise revert
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
ifSetUnlocked
modifier ifSetUnlocked(uint64 setId)check if set is unlocked, otherwise revert
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
TemplateManager
A Set can contain multiple Templates. Each Template should
have a 1-1 mapping with a unique NFT token. A Template can be used to
manage NFT minting (allowing max mints and lcoking) and manage NFT metadata,
probably alongside UriManager.
The final NFT contract should inherit from TemplateManager
_templates
mapping(uint256 => struct TemplateManager.Template) _templatesmapping from a template to a Template struct. The key of the
mapping is essentially determined by setId << 64 + templateId, which
allows us to keep the keys compact yet keep uniqueness.
Template
struct Template {
uint64 max;
uint64 minted;
bool metadataLocked;
bool mintingLocked;
}templateExists
function templateExists(uint64 setId, uint64 templateId) public view returns (bool)check if a template exists. Valid template IDs are between 1, numTemplatesInSet.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | bool | true if template exists |
template
function template(uint64 setId, uint64 templateId) public view returns (struct TemplateManager.Template)get Template with id templateId in set setId
only a copy - cannot modify Template in storage
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | struct TemplateManager.Template | a copy of the Template struct with id templateId in set setId |
maxMintOfTemplate
function maxMintOfTemplate(uint64 setId, uint64 templateId) public view returns (uint64)get the maximum mint allowed for a Template
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | uint64 | maximum mint allowed |
numMintedFromTemplate
function numMintedFromTemplate(uint64 setId, uint64 templateId) public view returns (uint64)get the number of NFTs minted for a Template
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | uint64 | number of NFTs minted |
isTemplateMetadataLocked
function isTemplateMetadataLocked(uint64 setId, uint64 templateId) public view returns (bool)check if metadata for a Template is locked
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | bool | true if metadata is locked |
isTemplateMintingLocked
function isTemplateMintingLocked(uint64 setId, uint64 templateId) public view returns (bool)check if minting for a Template is locked
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | bool | true if minting is locked |
_addTemplates
function _addTemplates(uint64 setId, uint64 numNewTemplates, uint64[] maxMints) internaladd templates to a set
new templates are given an ID based on the number of templates in
set setId
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| numNewTemplates | uint64 | number of new templates to add |
| maxMints | uint64[] | maximum number of NFTs that can be minted from each template |
_modifyMaxMint
function _modifyMaxMint(uint64 setId, uint64 templateId, uint64 newMax) internal virtualmodify the maximum number of NFTs that can be minted from a
Template, if not already set.
this should not be exposed externally. Override this just to add
restrictions. Use _modifyMaxMints instead.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
| newMax | uint64 | new maximum number of NFTs that can be minted from a Template |
_modifyMaxMints
function _modifyMaxMints(uint64 setId, uint64[] templateIds, uint64[] newMaxes) internalmodify the maximum number of NFTs that can be minted from
multiple Templates, if not already set.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateIds | uint64[] | template IDs |
| newMaxes | uint64[] | new maximum number of NFTs that can be minted from |
_registerMint
function _registerMint(uint64 setId, uint64 templateId, uint64 amount) internal virtualregister mints for a Template, if the Template is not locked
and the max mint won't be surpassed
this should not be exposed externally. Override this just to add
restrictions. Use _registerMints instead.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
| amount | uint64 | number of NFTs to register |
_registerMints
function _registerMints(uint64 setId, uint64[] templateIds, uint64[] amounts) internalregister mints for multiple Templates, if the Templates are
not locked and no max mints will be surpassed
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateIds | uint64[] | template IDs |
| amounts | uint64[] | number of NFTs to register |
_lockMinting
function _lockMinting(uint64 setId, uint64 templateId) internal virtuallock minting for a Template
this should not be exposed externally. Override this just to add
restrictions. Use _lockMintingForTemplates or _lockMintingForSet
instead.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
_lockMintingForTemplates
function _lockMintingForTemplates(uint64 setId, uint64[] templateIds) internallock minting for multiple Templates within a set
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateIds | uint64[] | template IDs |
_lockMintingForSet
function _lockMintingForSet(uint64 setId) internallock minting for all Templates within a set
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
_lockMetadata
function _lockMetadata(uint64 setId, uint64 templateId) internal virtuallock metadata for a Template
this should not be exposed externally. Override this just to add
restrictions. Use _lockMetadataForTemplates or _lockMetadataForSet
instead.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
_lockMetadataForTemplates
function _lockMetadataForTemplates(uint64 setId, uint64[] templateIds) internallock metadata for multiple Templates within a set
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateIds | uint64[] | template IDs |
_lockMetadataForSet
function _lockMetadataForSet(uint64 setId) internallock metadata for all Templates within a set
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
ifTemplateExists
modifier ifTemplateExists(uint64 setId, uint64 templateId)check if a Template exists, and revert if it doesn't
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
ifTemplateMetadataUnlocked
modifier ifTemplateMetadataUnlocked(uint64 setId, uint64 templateId)check if the metadata for a Template is still modifiable, and
revert if it isn't
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
ifTemplateCanMint
modifier ifTemplateCanMint(uint64 setId, uint64 templateId, uint64 amount)check if a Template is still able to register mints
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
| amount | uint64 |
UriManager
There is one metadata URI associated with each (set, template) pair.
UriManager manages a mapping from the (set, template) pair to a string URI.
The URI should default to _defaultUri if no URI is set for the
(set, template) pair. This contract also allows modification of URIs.
Privileging for mutating functions should be handled by an implementing contract via modifiers.
_defaultUri
string _defaultUridefault URI that's used if a token's URI is not set
_uris
mapping(uint256 => string) _urismapping from (set << 64 + template) pair to its URI
uri
function uri(uint64 setId, uint64 templateId) public view returns (string)get the URI for a token, or use the default if none.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
Return Values
| Name | Type | Description |
|---|---|---|
| 0 | string | URI |
_modifyDefaultUri
function _modifyDefaultUri(string newDefaultUri) internalmodify the default URI
Parameters
| Name | Type | Description |
|---|---|---|
| newDefaultUri | string | new default URI |
_modifyUri
function _modifyUri(uint64 setId, uint64 templateId, string newUri) internal virtualmodify the URI for a token
this should not be exposed externally. Override this just to add
restrictions. Use _modifyUris instead.
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateId | uint64 | template ID |
| newUri | string | new URI |
_modifyUris
function _modifyUris(uint64 setId, uint64[] templateIds, string[] newUris) internalmodify the URIs for a given list of templates within a set
requires templateIds.length == newUris.length as they map 1-1
Parameters
| Name | Type | Description |
|---|---|---|
| setId | uint64 | set ID |
| templateIds | uint64[] | list of template IDs |
| newUris | string[] | list of new URIs |
3 years ago