-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove ERC721 tokenTransfer hooks #3893
Remove ERC721 tokenTransfer hooks #3893
Conversation
Overall I feel uncomfortable with this change. Devs that call The truth is, only batchsize == 1 does the transfer, and any other value is just a hack to update the balances. I think this is very error prone and is not aligned with our guidelines! |
My first idea would be to remove the batchSize from the |
But how? And we should keep in mind that the goal is to minimize overrides for the end user. |
We might have to consider adding |
That is one option There was another option that used overflows, but it used 2 slots per account ... and feels very "hacky" My concern is that putting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not for this PR, but we will have to worry about these extensions.
delete _tokenURIs[tokenId]; | ||
function _update(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual override { | ||
super._update(from, to, firstTokenId, batchSize); | ||
if (to == address(0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if to == address(0)
and batchSize > 1
, we should probably do something. Revert?
_resetTokenRoyalty(tokenId); | ||
function _update(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual override { | ||
super._update(from, to, firstTokenId, batchSize); | ||
if (to == address(0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if to == address(0)
and batchSize > 1
, we should probably do something. Revert?
// After construction, {_mintConsecutive} is no longer available and {_mint} becomes available. | ||
require(Address.isContract(address(this)), "ERC721Consecutive: can't mint during construction"); | ||
} | ||
super._update(from, to, firstTokenId, batchSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also realized that here we are not following the rule that overrides should do their own stuff before calling super (and not after). We need to add comments documenting why we are doing so.
) internal virtual override { | ||
super._beforeTokenTransfer(from, to, firstTokenId, batchSize); | ||
|
||
function _update(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual override { | ||
if (batchSize > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to consider batchSize == 0
7383061
to
769c6ec
Compare
Here is a summary of the identified issues that would need to be fixed:
|
Closing this PR in favor of the issue, where I shared the above summary: #3535 |
Fixes #3535
Replaces #3636
The current way to customize token transfers(mint, burn, transfer) is by overriding the hooks _beforeTokenTransfer and _afterTokenTransfer. This refactor removes both hooks from the ERC721 contract, and implements the logic inside the new _update internal function, so future customizations only rely on overriding a single entry point.
PR Checklist