Use named arguments in mapping types (#4433)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
pull/4526/head
Ernesto García 2 years ago committed by GitHub
parent 48b860124c
commit cb0ffefe2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      contracts/access/AccessControl.sol
  2. 2
      contracts/access/extensions/AccessControlEnumerable.sol
  3. 2
      contracts/finance/VestingWallet.sol
  4. 2
      contracts/governance/Governor.sol
  5. 2
      contracts/governance/TimelockController.sol
  6. 4
      contracts/governance/extensions/GovernorCountingSimple.sol
  7. 2
      contracts/governance/extensions/GovernorPreventLateQuorum.sol
  8. 2
      contracts/governance/extensions/GovernorStorage.sol
  9. 2
      contracts/governance/extensions/GovernorTimelockControl.sol
  10. 8
      contracts/governance/utils/Votes.sol
  11. 2
      contracts/mocks/ERC165/ERC165InterfacesSupported.sol
  12. 4
      contracts/mocks/StorageSlotMock.sol
  13. 2
      contracts/mocks/VotesMock.sol
  14. 8
      contracts/mocks/token/ERC20VotesLegacyMock.sol
  15. 6
      contracts/token/ERC1155/ERC1155.sol
  16. 2
      contracts/token/ERC1155/extensions/ERC1155Supply.sol
  17. 2
      contracts/token/ERC1155/extensions/ERC1155URIStorage.sol
  18. 4
      contracts/token/ERC20/ERC20.sol
  19. 12
      contracts/token/ERC721/ERC721.sol
  20. 12
      contracts/token/ERC721/extensions/ERC721Enumerable.sol
  21. 2
      contracts/token/ERC721/extensions/ERC721URIStorage.sol
  22. 2
      contracts/token/common/ERC2981.sol
  23. 2
      contracts/utils/Nonces.sol
  24. 2
      contracts/utils/structs/BitMaps.sol
  25. 2
      contracts/utils/structs/DoubleEndedQueue.sol
  26. 2
      contracts/utils/structs/EnumerableMap.sol
  27. 2
      contracts/utils/structs/EnumerableSet.sol
  28. 2
      scripts/generate/templates/EnumerableMap.js
  29. 2
      scripts/generate/templates/EnumerableSet.js

@ -48,11 +48,11 @@ import {ERC165} from "../utils/introspection/ERC165.sol";
*/ */
abstract contract AccessControl is Context, IAccessControl, ERC165 { abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData { struct RoleData {
mapping(address => bool) members; mapping(address account => bool) hasRole;
bytes32 adminRole; bytes32 adminRole;
} }
mapping(bytes32 => RoleData) private _roles; mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
@ -76,7 +76,7 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
* @dev Returns `true` if `account` has been granted `role`. * @dev Returns `true` if `account` has been granted `role`.
*/ */
function hasRole(bytes32 role, address account) public view virtual returns (bool) { function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].members[account]; return _roles[role].hasRole[account];
} }
/** /**
@ -182,7 +182,7 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
*/ */
function _grantRole(bytes32 role, address account) internal virtual returns (bool) { function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) { if (!hasRole(role, account)) {
_roles[role].members[account] = true; _roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender()); emit RoleGranted(role, account, _msgSender());
return true; return true;
} else { } else {
@ -199,7 +199,7 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
*/ */
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) { function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) { if (hasRole(role, account)) {
_roles[role].members[account] = false; _roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender()); emit RoleRevoked(role, account, _msgSender());
return true; return true;
} else { } else {

@ -13,7 +13,7 @@ import {EnumerableSet} from "../../utils/structs/EnumerableSet.sol";
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl { abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet; using EnumerableSet for EnumerableSet.AddressSet;
mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers; mapping(bytes32 role => EnumerableSet.AddressSet) private _roleMembers;
/** /**
* @dev See {IERC165-supportsInterface}. * @dev See {IERC165-supportsInterface}.

@ -37,7 +37,7 @@ contract VestingWallet is Context, Ownable {
error VestingWalletInvalidBeneficiary(address beneficiary); error VestingWalletInvalidBeneficiary(address beneficiary);
uint256 private _released; uint256 private _released;
mapping(address => uint256) private _erc20Released; mapping(address token => uint256) private _erc20Released;
uint64 private immutable _start; uint64 private immutable _start;
uint64 private immutable _duration; uint64 private immutable _duration;

@ -46,7 +46,7 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
bytes32 private constant _ALL_PROPOSAL_STATES_BITMAP = bytes32((2 ** (uint8(type(ProposalState).max) + 1)) - 1); bytes32 private constant _ALL_PROPOSAL_STATES_BITMAP = bytes32((2 ** (uint8(type(ProposalState).max) + 1)) - 1);
string private _name; string private _name;
mapping(uint256 => ProposalCore) private _proposals; mapping(uint256 proposalId => ProposalCore) private _proposals;
// This queue keeps track of the governor operating on itself. Calls to functions protected by the // This queue keeps track of the governor operating on itself. Calls to functions protected by the
// {onlyGovernance} modifier needs to be whitelisted in this queue. Whitelisting is set in {_beforeExecute}, // {onlyGovernance} modifier needs to be whitelisted in this queue. Whitelisting is set in {_beforeExecute},

@ -27,7 +27,7 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
bytes32 public constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE"); bytes32 public constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE");
uint256 internal constant _DONE_TIMESTAMP = uint256(1); uint256 internal constant _DONE_TIMESTAMP = uint256(1);
mapping(bytes32 => uint256) private _timestamps; mapping(bytes32 id => uint256) private _timestamps;
uint256 private _minDelay; uint256 private _minDelay;
enum OperationState { enum OperationState {

@ -22,10 +22,10 @@ abstract contract GovernorCountingSimple is Governor {
uint256 againstVotes; uint256 againstVotes;
uint256 forVotes; uint256 forVotes;
uint256 abstainVotes; uint256 abstainVotes;
mapping(address => bool) hasVoted; mapping(address voter => bool) hasVoted;
} }
mapping(uint256 => ProposalVote) private _proposalVotes; mapping(uint256 proposalId => ProposalVote) private _proposalVotes;
/** /**
* @dev See {IGovernor-COUNTING_MODE}. * @dev See {IGovernor-COUNTING_MODE}.

@ -18,7 +18,7 @@ import {Math} from "../../utils/math/Math.sol";
abstract contract GovernorPreventLateQuorum is Governor { abstract contract GovernorPreventLateQuorum is Governor {
uint48 private _voteExtension; uint48 private _voteExtension;
mapping(uint256 => uint48) private _extendedDeadlines; mapping(uint256 proposalId => uint48) private _extendedDeadlines;
/// @dev Emitted when a proposal deadline is pushed back due to reaching quorum late in its voting period. /// @dev Emitted when a proposal deadline is pushed back due to reaching quorum late in its voting period.
event ProposalExtended(uint256 indexed proposalId, uint64 extendedDeadline); event ProposalExtended(uint256 indexed proposalId, uint64 extendedDeadline);

@ -21,7 +21,7 @@ abstract contract GovernorStorage is Governor {
} }
uint256[] private _proposalIds; uint256[] private _proposalIds;
mapping(uint256 => ProposalDetails) private _proposalDetails; mapping(uint256 proposalId => ProposalDetails) private _proposalDetails;
/** /**
* @dev Hook into the proposing mechanism * @dev Hook into the proposing mechanism

@ -24,7 +24,7 @@ import {SafeCast} from "../../utils/math/SafeCast.sol";
*/ */
abstract contract GovernorTimelockControl is Governor { abstract contract GovernorTimelockControl is Governor {
TimelockController private _timelock; TimelockController private _timelock;
mapping(uint256 => bytes32) private _timelockIds; mapping(uint256 proposalId => bytes32) private _timelockIds;
/** /**
* @dev Emitted when the timelock controller used for proposal execution is modified. * @dev Emitted when the timelock controller used for proposal execution is modified.

@ -34,9 +34,9 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
bytes32 private constant _DELEGATION_TYPEHASH = bytes32 private constant _DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
mapping(address => address) private _delegation; mapping(address account => address) private _delegatee;
mapping(address => Checkpoints.Trace224) private _delegateCheckpoints; mapping(address delegatee => Checkpoints.Trace224) private _delegateCheckpoints;
Checkpoints.Trace224 private _totalCheckpoints; Checkpoints.Trace224 private _totalCheckpoints;
@ -124,7 +124,7 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
* @dev Returns the delegate that `account` has chosen. * @dev Returns the delegate that `account` has chosen.
*/ */
function delegates(address account) public view virtual returns (address) { function delegates(address account) public view virtual returns (address) {
return _delegation[account]; return _delegatee[account];
} }
/** /**
@ -166,7 +166,7 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
*/ */
function _delegate(address account, address delegatee) internal virtual { function _delegate(address account, address delegatee) internal virtual {
address oldDelegate = delegates(account); address oldDelegate = delegates(account);
_delegation[account] = delegatee; _delegatee[account] = delegatee;
emit DelegateChanged(account, oldDelegate, delegatee); emit DelegateChanged(account, oldDelegate, delegatee);
_moveDelegateVotes(oldDelegate, delegatee, _getVotingUnits(account)); _moveDelegateVotes(oldDelegate, delegatee, _getVotingUnits(account));

@ -23,7 +23,7 @@ contract SupportsInterfaceWithLookupMock is IERC165 {
/** /**
* @dev A mapping of interface id to whether or not it's supported. * @dev A mapping of interface id to whether or not it's supported.
*/ */
mapping(bytes4 => bool) private _supportedInterfaces; mapping(bytes4 interfaceId => bool) private _supportedInterfaces;
/** /**
* @dev A contract implementing SupportsInterfaceWithLookup * @dev A contract implementing SupportsInterfaceWithLookup

@ -39,7 +39,7 @@ contract StorageSlotMock {
return slot.getUint256Slot().value; return slot.getUint256Slot().value;
} }
mapping(uint256 => string) public stringMap; mapping(uint256 key => string) public stringMap;
function setString(bytes32 slot, string calldata value) public { function setString(bytes32 slot, string calldata value) public {
slot.getStringSlot().value = value; slot.getStringSlot().value = value;
@ -57,7 +57,7 @@ contract StorageSlotMock {
return stringMap[key].getStringSlot().value; return stringMap[key].getStringSlot().value;
} }
mapping(uint256 => bytes) public bytesMap; mapping(uint256 key => bytes) public bytesMap;
function setBytes(bytes32 slot, bytes calldata value) public { function setBytes(bytes32 slot, bytes calldata value) public {
slot.getBytesSlot().value = value; slot.getBytesSlot().value = value;

@ -5,7 +5,7 @@ pragma solidity ^0.8.20;
import {Votes} from "../governance/utils/Votes.sol"; import {Votes} from "../governance/utils/Votes.sol";
abstract contract VotesMock is Votes { abstract contract VotesMock is Votes {
mapping(address => uint256) private _votingUnits; mapping(address voter => uint256) private _votingUnits;
function getTotalSupply() public view returns (uint256) { function getTotalSupply() public view returns (uint256) {
return _getTotalSupply(); return _getTotalSupply();

@ -20,8 +20,8 @@ abstract contract ERC20VotesLegacyMock is IVotes, ERC20Permit {
bytes32 private constant _DELEGATION_TYPEHASH = bytes32 private constant _DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
mapping(address => address) private _delegates; mapping(address account => address) private _delegatee;
mapping(address => Checkpoint[]) private _checkpoints; mapping(address delegatee => Checkpoint[]) private _checkpoints;
Checkpoint[] private _totalSupplyCheckpoints; Checkpoint[] private _totalSupplyCheckpoints;
/** /**
@ -42,7 +42,7 @@ abstract contract ERC20VotesLegacyMock is IVotes, ERC20Permit {
* @dev Get the address `account` is currently delegating to. * @dev Get the address `account` is currently delegating to.
*/ */
function delegates(address account) public view virtual returns (address) { function delegates(address account) public view virtual returns (address) {
return _delegates[account]; return _delegatee[account];
} }
/** /**
@ -188,7 +188,7 @@ abstract contract ERC20VotesLegacyMock is IVotes, ERC20Permit {
function _delegate(address delegator, address delegatee) internal virtual { function _delegate(address delegator, address delegatee) internal virtual {
address currentDelegate = delegates(delegator); address currentDelegate = delegates(delegator);
uint256 delegatorBalance = balanceOf(delegator); uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee; _delegatee[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee); emit DelegateChanged(delegator, currentDelegate, delegatee);

@ -20,11 +20,9 @@ abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IER
using Arrays for uint256[]; using Arrays for uint256[];
using Arrays for address[]; using Arrays for address[];
// Mapping from token ID to account balances mapping(uint256 id => mapping(address account => uint256)) private _balances;
mapping(uint256 => mapping(address => uint256)) private _balances;
// Mapping from account to operator approvals mapping(address account => mapping(address operator => bool)) private _operatorApprovals;
mapping(address => mapping(address => bool)) private _operatorApprovals;
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
string private _uri; string private _uri;

@ -19,7 +19,7 @@ import {ERC1155} from "../ERC1155.sol";
* CAUTION: This extension should not be added in an upgrade to an already deployed contract. * CAUTION: This extension should not be added in an upgrade to an already deployed contract.
*/ */
abstract contract ERC1155Supply is ERC1155 { abstract contract ERC1155Supply is ERC1155 {
mapping(uint256 => uint256) private _totalSupply; mapping(uint256 id => uint256) private _totalSupply;
uint256 private _totalSupplyAll; uint256 private _totalSupplyAll;
/** /**

@ -17,7 +17,7 @@ abstract contract ERC1155URIStorage is ERC1155 {
string private _baseURI = ""; string private _baseURI = "";
// Optional mapping for token URIs // Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs; mapping(uint256 tokenId => string) private _tokenURIs;
/** /**
* @dev See {IERC1155MetadataURI-uri}. * @dev See {IERC1155MetadataURI-uri}.

@ -36,9 +36,9 @@ import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
* allowances. See {IERC20-approve}. * allowances. See {IERC20-approve}.
*/ */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors { abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address => uint256) private _balances; mapping(address account => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances; mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply; uint256 private _totalSupply;

@ -25,17 +25,13 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
// Token symbol // Token symbol
string private _symbol; string private _symbol;
// Mapping from token ID to owner address mapping(uint256 tokenId => address) private _owners;
mapping(uint256 => address) private _owners;
// Mapping owner address to token count mapping(address owner => uint256) private _balances;
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address mapping(uint256 tokenId => address) private _tokenApprovals;
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;
mapping(address => mapping(address => bool)) private _operatorApprovals;
/** /**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.

@ -15,17 +15,11 @@ import {IERC165} from "../../../utils/introspection/ERC165.sol";
* interfere with enumerability and should not be used together with `ERC721Enumerable`. * interfere with enumerability and should not be used together with `ERC721Enumerable`.
*/ */
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs mapping(address owner => mapping(uint256 index => uint256)) private _ownedTokens;
mapping(address => mapping(uint256 => uint256)) private _ownedTokens; mapping(uint256 tokenId => uint256) private _ownedTokensIndex;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens; uint256[] private _allTokens;
mapping(uint256 tokenId => uint256) private _allTokensIndex;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/** /**
* @dev An `owner`'s token query was out of bounds for `index`. * @dev An `owner`'s token query was out of bounds for `index`.

@ -15,7 +15,7 @@ abstract contract ERC721URIStorage is IERC4906, ERC721 {
using Strings for uint256; using Strings for uint256;
// Optional mapping for token URIs // Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs; mapping(uint256 tokenId => string) private _tokenURIs;
/** /**
* @dev See {IERC165-supportsInterface} * @dev See {IERC165-supportsInterface}

@ -26,7 +26,7 @@ abstract contract ERC2981 is IERC2981, ERC165 {
} }
RoyaltyInfo private _defaultRoyaltyInfo; RoyaltyInfo private _defaultRoyaltyInfo;
mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo; mapping(uint256 tokenId => RoyaltyInfo) private _tokenRoyaltyInfo;
/** /**
* @dev The default royalty set is invalid (eg. (numerator / denominator) >= 1). * @dev The default royalty set is invalid (eg. (numerator / denominator) >= 1).

@ -10,7 +10,7 @@ abstract contract Nonces {
*/ */
error InvalidAccountNonce(address account, uint256 currentNonce); error InvalidAccountNonce(address account, uint256 currentNonce);
mapping(address => uint256) private _nonces; mapping(address account => uint256) private _nonces;
/** /**
* @dev Returns an the next unused nonce for an address. * @dev Returns an the next unused nonce for an address.

@ -17,7 +17,7 @@ pragma solidity ^0.8.20;
*/ */
library BitMaps { library BitMaps {
struct BitMap { struct BitMap {
mapping(uint256 => uint256) _data; mapping(uint256 bucket => uint256) _data;
} }
/** /**

@ -45,7 +45,7 @@ library DoubleEndedQueue {
struct Bytes32Deque { struct Bytes32Deque {
uint128 _begin; uint128 _begin;
uint128 _end; uint128 _end;
mapping(uint128 => bytes32) _data; mapping(uint128 index => bytes32) _data;
} }
/** /**

@ -65,7 +65,7 @@ library EnumerableMap {
struct Bytes32ToBytes32Map { struct Bytes32ToBytes32Map {
// Storage of keys // Storage of keys
EnumerableSet.Bytes32Set _keys; EnumerableSet.Bytes32Set _keys;
mapping(bytes32 => bytes32) _values; mapping(bytes32 key => bytes32) _values;
} }
/** /**

@ -53,7 +53,7 @@ library EnumerableSet {
bytes32[] _values; bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0 // Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set. // means a value is not in the set.
mapping(bytes32 => uint256) _indexes; mapping(bytes32 value => uint256) _indexes;
} }
/** /**

@ -74,7 +74,7 @@ error EnumerableMapNonexistentKey(bytes32 key);
struct Bytes32ToBytes32Map { struct Bytes32ToBytes32Map {
// Storage of keys // Storage of keys
EnumerableSet.Bytes32Set _keys; EnumerableSet.Bytes32Set _keys;
mapping(bytes32 => bytes32) _values; mapping(bytes32 key => bytes32) _values;
} }
/** /**

@ -63,7 +63,7 @@ struct Set {
bytes32[] _values; bytes32[] _values;
// Position of the value in the \`values\` array, plus 1 because index 0 // Position of the value in the \`values\` array, plus 1 because index 0
// means a value is not in the set. // means a value is not in the set.
mapping(bytes32 => uint256) _indexes; mapping(bytes32 value => uint256) _indexes;
} }
/** /**

Loading…
Cancel
Save