Skip to content

Commit 85696d8

Browse files
authored
Remove further hardcoded function resolution (#4309)
1 parent 6c14de4 commit 85696d8

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

.changeset/red-dots-fold.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-
Overrides are now used internally for a number of functions that were previously hardcoded to their default implementation in certain locations: `ERC1155Supply.totalSupply`, `ERC721.ownerOf`, `ERC721.balanceOf` in `ERC721Enumerable`, and `ERC20.totalSupply` in `ERC20FlashMint`.
5+
Overrides are now used internally for a number of functions that were previously hardcoded to their default implementation in certain locations: `ERC1155Supply.totalSupply`, `ERC721.ownerOf`, `ERC721.balanceOf` and `ERC721.totalSupply` in `ERC721Enumerable`, `ERC20.totalSupply` in `ERC20FlashMint`, and `ERC1967._getImplementation` in `ERC1967Proxy`.

contracts/mocks/proxy/UUPSUpgradeableMock.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ contract UUPSUpgradeableMock is NonUpgradeableMock, UUPSUpgradeable {
2323

2424
contract UUPSUpgradeableUnsafeMock is UUPSUpgradeableMock {
2525
function upgradeTo(address newImplementation) public override {
26-
ERC1967Upgrade._upgradeToAndCall(newImplementation, bytes(""), false);
26+
_upgradeToAndCall(newImplementation, bytes(""), false);
2727
}
2828

2929
function upgradeToAndCall(address newImplementation, bytes memory data) public payable override {
30-
ERC1967Upgrade._upgradeToAndCall(newImplementation, data, false);
30+
_upgradeToAndCall(newImplementation, data, false);
3131
}
3232
}

contracts/proxy/ERC1967/ERC1967Proxy.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ contract ERC1967Proxy is Proxy, ERC1967Upgrade {
3131
* `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
3232
*/
3333
function _implementation() internal view virtual override returns (address impl) {
34-
return ERC1967Upgrade._getImplementation();
34+
return _getImplementation();
3535
}
3636
}

contracts/token/ERC721/extensions/ERC721Enumerable.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import "../ERC721.sol";
77
import "./IERC721Enumerable.sol";
88

99
/**
10-
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
11-
* enumerability of all the token ids in the contract as well as all token ids owned by each
12-
* account.
10+
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds enumerability
11+
* of all the token ids in the contract as well as all token ids owned by each account.
12+
*
13+
* CAUTION: `ERC721` extensions that implement custom `balanceOf` logic, such as `ERC721Consecutive`,
14+
* interfere with enumerability and should not be used together with `ERC721Enumerable`.
1315
*/
1416
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
1517
// Mapping from owner to list of owned token IDs
@@ -50,7 +52,7 @@ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
5052
* @dev See {IERC721Enumerable-tokenByIndex}.
5153
*/
5254
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
53-
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
55+
require(index < totalSupply(), "ERC721Enumerable: global index out of bounds");
5456
return _allTokens[index];
5557
}
5658

@@ -116,7 +118,7 @@ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
116118
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
117119
// then delete the last slot (swap and pop).
118120

119-
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
121+
uint256 lastTokenIndex = balanceOf(from) - 1;
120122
uint256 tokenIndex = _ownedTokensIndex[tokenId];
121123

122124
// When the token to delete is the last token, the swap operation is unnecessary

0 commit comments

Comments
 (0)