Refactor consecutive transfer hooks #3753
Merged
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.
Resolves #3739
In #3739 we realized that the introduction of ERC721Consecutive results in a breaking change, not because the behavior of a contract changes, but because it may stop compiling due to new required disambiguating overrides. An example is the combination of ERC721+ERC721Pausable, or ERC721+ERC721Enumerable, even though these combinations don't involve ERC721Consecutive the user still has to write a disambiguating override for
_beforeConsecutiveTokenTransfer
.This understandably results in confusion. This is a proposal for an alternative way to design the hooks, which gives in to the breaking change but with an arguably less disruptive result. The idea is to reuse
_beforeTokenTransfer
but add a new argument, so that the signature becomes_beforeTokenTransfer(address from, address to, uint firstTokenId, uint lastTokenId)
. Thus, the same hook is reused for simple and consecutive token transfers. A user that updates the dependency to 4.8 "simply" has to add the newlastTokenId
argument to get their contract to compile, and as long as they don't use ERC721Consecutive they can ignore that argument.This PR is incomplete and won't compile, but I wanted to get the idea out since this is blocking the release of 4.8. I personally think this is an important thing to consider. The effect of having consecutive-related overrides in a contract that doesn't use ERC721Consecutive is not nice at all, and I think it just shows that the design needs to be improved.
We could also consider adding
uint size
instead ofuint lastTokenId
as the new argument to the hook.(Related to #3744)