Skip to content

Commit 0a670d0

Browse files
Transpile 9e3f4d6
1 parent f6401d9 commit 0a670d0

19 files changed

+450
-485
lines changed

.changeset/bright-tomatoes-sing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'openzeppelin-solidity': major
33
---
44

5-
`ERC20`, `ERC1155`: Deleted `_beforeTokenTransfer` and `_afterTokenTransfer` hooks, added a new internal `_update` function for customizations, and refactored all extensions using those hooks to use `_update` instead. ([#3838](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3838), [#3876](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3876))
5+
`ERC20`, `ERC721`, `ERC1155`: Deleted `_beforeTokenTransfer` and `_afterTokenTransfer` hooks, added a new internal `_update` function for customizations, and refactored all extensions using those hooks to use `_update` instead. ([#3838](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3838), [#3876](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3876), [#4377](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/4377))

.changeset/eighty-lemons-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': major
3+
---
4+
5+
`ERC721`: `_approve` no longer allows approving the owner of the tokenId. `_setApprovalForAll` no longer allows setting address(0) as an operator.

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ These removals were implemented in the following PRs: [#3637](https://github.com
3636

3737
These breaking changes will require modifications to ERC20, ERC721, and ERC1155 contracts, since the `_afterTokenTransfer` and `_beforeTokenTransfer` functions were removed. Any customization made through those hooks should now be done overriding the new `_update` function instead.
3838

39-
Minting and burning are implemented by `_update` and customizations should be done by overriding this function as well. `_mint` and `_burn` are no longer virtual (meaning they are not overridable) to guard against possible inconsistencies.
39+
Minting and burning are implemented by `_update` and customizations should be done by overriding this function as well. `_transfer`, `_mint` and `_burn` are no longer virtual (meaning they are not overridable) to guard against possible inconsistencies.
4040

4141
For example, a contract using `ERC20`'s `_beforeTokenTransfer` hook would have to be changed in the following way.
4242

@@ -53,6 +53,18 @@ For example, a contract using `ERC20`'s `_beforeTokenTransfer` hook would have t
5353
}
5454
```
5555

56+
### More about ERC721
57+
58+
In the case of `ERC721`, the `_update` function does not include a `from` parameter, as the sender is implicitly the previous owner of the `tokenId`. The address of
59+
this previous owner is returned by the `_update` function, so it can be used for a posteriori checks. In addition to `to` and `tokenId`, a third parameter (`auth`) is
60+
present in this function. This parameter enabled an optional check that the caller/spender is approved to do the transfer. This check cannot be performed after the transfer (because the transfer resets the approval), and doing it before `_update` would require a duplicate call to `_ownerOf`.
61+
62+
In this logic of removing hidden SLOADs, the `_isApprovedOrOwner` function was removed in favor of a new `_isAuthorized` function. Overrides that used to target the
63+
`_isApprovedOrOwner` should now be performed on the `_isAuthorized` function. Calls to `_isApprovedOrOwner` that preceded a call to `_transfer`, `_burn` or `_approve`
64+
should be removed in favor of using the `auth` argument in `_update` and `_approve`. This is showcased in `ERC721Burnable.burn` and in `ERC721Wrapper.withdrawTo`.
65+
66+
The `_exists` function was removed. Calls to this function can be replaced by `_ownerOf(tokenId) != address(0)`.
67+
5668
#### ERC165Storage
5769

5870
Users that were registering EIP-165 interfaces with `_registerInterface` from `ERC165Storage` should instead do so so by overriding the `supportsInterface` function as seen below:

contracts/mocks/token/ERC721ConsecutiveEnumerableMockUpgradeable.sol

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,16 @@ contract ERC721ConsecutiveEnumerableMockUpgradeable is Initializable, ERC721Cons
3939
return super._ownerOf(tokenId);
4040
}
4141

42-
function _mint(address to, uint256 tokenId) internal virtual override(ERC721Upgradeable, ERC721ConsecutiveUpgradeable) {
43-
super._mint(to, tokenId);
44-
}
45-
46-
function _beforeTokenTransfer(
47-
address from,
42+
function _update(
4843
address to,
49-
uint256 firstTokenId,
50-
uint256 batchSize
51-
) internal virtual override(ERC721Upgradeable, ERC721EnumerableUpgradeable) {
52-
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
44+
uint256 tokenId,
45+
address auth
46+
) internal virtual override(ERC721ConsecutiveUpgradeable, ERC721EnumerableUpgradeable) returns (address) {
47+
return super._update(to, tokenId, auth);
5348
}
5449

55-
function _afterTokenTransfer(
56-
address from,
57-
address to,
58-
uint256 firstTokenId,
59-
uint256 batchSize
60-
) internal virtual override(ERC721Upgradeable, ERC721ConsecutiveUpgradeable) {
61-
super._afterTokenTransfer(from, to, firstTokenId, batchSize);
50+
function _increaseBalance(address account, uint128 amount) internal virtual override(ERC721Upgradeable, ERC721EnumerableUpgradeable) {
51+
super._increaseBalance(account, amount);
6252
}
6353

6454
/**

contracts/mocks/token/ERC721ConsecutiveMockUpgradeable.sol

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,16 @@ contract ERC721ConsecutiveMockUpgradeable is Initializable, ERC721ConsecutiveUpg
5656
return super._ownerOf(tokenId);
5757
}
5858

59-
function _mint(address to, uint256 tokenId) internal virtual override(ERC721Upgradeable, ERC721ConsecutiveUpgradeable) {
60-
super._mint(to, tokenId);
61-
}
62-
63-
function _beforeTokenTransfer(
64-
address from,
59+
function _update(
6560
address to,
66-
uint256 firstTokenId,
67-
uint256 batchSize
68-
) internal virtual override(ERC721Upgradeable, ERC721PausableUpgradeable) {
69-
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
61+
uint256 tokenId,
62+
address auth
63+
) internal virtual override(ERC721ConsecutiveUpgradeable, ERC721PausableUpgradeable, ERC721VotesUpgradeable) returns (address) {
64+
return super._update(to, tokenId, auth);
7065
}
7166

72-
function _afterTokenTransfer(
73-
address from,
74-
address to,
75-
uint256 firstTokenId,
76-
uint256 batchSize
77-
) internal virtual override(ERC721Upgradeable, ERC721VotesUpgradeable, ERC721ConsecutiveUpgradeable) {
78-
super._afterTokenTransfer(from, to, firstTokenId, batchSize);
67+
function _increaseBalance(address account, uint128 amount) internal virtual override(ERC721Upgradeable, ERC721VotesUpgradeable) {
68+
super._increaseBalance(account, amount);
7969
}
8070

8171
/**

0 commit comments

Comments
 (0)