Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
New contracts introduced:
EvolvingNFT
,SharedMetadataBatch
,RulesEngine
.EvolvingNFT
is an ERC721 NFT contract. It is an 'open edition' where the metadata of NFT's changes based on its owner's token ownership profile.Unlike
OpenEditionERC721
which usesSharedMetadata
, this contract usesSharedMetadataBatch
instead, and lets an address with minter role store multiple metadata in the contract. UsingRulesEngine
, thetokenURI
method returns the appropriate metadata for the open edition NFT based on the token ownership score of the NFT owner.Expected usage
The big picture
The actual distribution of open edition NFTs works exactly like in
OpenEditionERC721
, through the use of theDrop
extension contract.But unlike
OpenEdtiionERC721
, you can store multiple shared metadata in the contract. Ultimately, we want to get to the followingtokenURI
function:Here, we first get a 'token ownership score' for the NFT owner and then return metadata for the NFT based on this score. Different ranges of scores result in different shared metadata to be returned for a given token ID. For example:
1. Creating rules
An authorized signer (address with minter role) creates rules; each rule has an associated score.
The authorized signer creates rules by calling
createRule
. This returns aruleId
, which can be used to later calldeleteRule
if needed.A
Rule
defines a criterion of token ownership. For all token types (ERC20, ERC721 and ERC1155), the token ownership criterion checks for the total balance of the token owned by a given address.2. Setting shared metadata
The
OpenEditionERC721
contract has only one shared metadata at a time (all NFTs have the exact same metadata, except for their own unique token ID in the NFT name).The
EvolvingNFT
contract lets an authorized signer (an address with admin role) store multiple shared metadata, each with a uniquebytes32
ID. The contract gets this functionality from theSharedMetadataBatch
extension contract.An authorized signer can store shared metadata by calling the
setSharedMetadata
function:Metadata for a given NFT token ID is accessed using the
bytes32 id
assigned to shared metadata during creation:3. Assigning the right IDs to shared metadata
For a given NFT token ID, the
tokenURI
method first gets a token ownership score for the NFT's owner, and then returns shared metadata assigned to a 'target ID' as seen in the full implementation of the method in the The big picture section.And so, the
bytes32 id
assigned to a shared metadata must be the above mentioned the start (inclusive) of the score range. The relevance of this is explained in the The big picture section.