Skip to content

Commit

Permalink
Use named arguments in mapping types (#4433)
Browse files Browse the repository at this point in the history
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
  • Loading branch information
ernestognw and Amxx authored Aug 9, 2023
1 parent 48b8601 commit cb0ffef
Show file tree
Hide file tree
Showing 29 changed files with 48 additions and 60 deletions.
10 changes: 5 additions & 5 deletions contracts/access/AccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ import {ERC165} from "../utils/introspection/ERC165.sol";
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
mapping(address account => bool) hasRole;
bytes32 adminRole;
}

mapping(bytes32 => RoleData) private _roles;
mapping(bytes32 role => RoleData) private _roles;

bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

Expand All @@ -76,7 +76,7 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].members[account];
return _roles[role].hasRole[account];
}

/**
Expand Down Expand Up @@ -182,7 +182,7 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
Expand All @@ -199,7 +199,7 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion contracts/access/extensions/AccessControlEnumerable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {EnumerableSet} from "../../utils/structs/EnumerableSet.sol";
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet;

mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;
mapping(bytes32 role => EnumerableSet.AddressSet) private _roleMembers;

/**
* @dev See {IERC165-supportsInterface}.
Expand Down
2 changes: 1 addition & 1 deletion contracts/finance/VestingWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract VestingWallet is Context, Ownable {
error VestingWalletInvalidBeneficiary(address beneficiary);

uint256 private _released;
mapping(address => uint256) private _erc20Released;
mapping(address token => uint256) private _erc20Released;
uint64 private immutable _start;
uint64 private immutable _duration;

Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/Governor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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
// {onlyGovernance} modifier needs to be whitelisted in this queue. Whitelisting is set in {_beforeExecute},
Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/TimelockController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
bytes32 public constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE");
uint256 internal constant _DONE_TIMESTAMP = uint256(1);

mapping(bytes32 => uint256) private _timestamps;
mapping(bytes32 id => uint256) private _timestamps;
uint256 private _minDelay;

enum OperationState {
Expand Down
4 changes: 2 additions & 2 deletions contracts/governance/extensions/GovernorCountingSimple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ abstract contract GovernorCountingSimple is Governor {
uint256 againstVotes;
uint256 forVotes;
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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {Math} from "../../utils/math/Math.sol";
abstract contract GovernorPreventLateQuorum is Governor {
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.
event ProposalExtended(uint256 indexed proposalId, uint64 extendedDeadline);
Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/extensions/GovernorStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract contract GovernorStorage is Governor {
}

uint256[] private _proposalIds;
mapping(uint256 => ProposalDetails) private _proposalDetails;
mapping(uint256 proposalId => ProposalDetails) private _proposalDetails;

/**
* @dev Hook into the proposing mechanism
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {SafeCast} from "../../utils/math/SafeCast.sol";
*/
abstract contract GovernorTimelockControl is Governor {
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.
Expand Down
8 changes: 4 additions & 4 deletions contracts/governance/utils/Votes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
bytes32 private constant _DELEGATION_TYPEHASH =
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;

Expand Down Expand Up @@ -124,7 +124,7 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
* @dev Returns the delegate that `account` has chosen.
*/
function delegates(address account) public view virtual returns (address) {
return _delegation[account];
return _delegatee[account];
}

/**
Expand Down Expand Up @@ -166,7 +166,7 @@ abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
*/
function _delegate(address account, address delegatee) internal virtual {
address oldDelegate = delegates(account);
_delegation[account] = delegatee;
_delegatee[account] = delegatee;

emit DelegateChanged(account, oldDelegate, delegatee);
_moveDelegateVotes(oldDelegate, delegatee, _getVotingUnits(account));
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ERC165/ERC165InterfacesSupported.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract SupportsInterfaceWithLookupMock is IERC165 {
/**
* @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
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/StorageSlotMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract StorageSlotMock {
return slot.getUint256Slot().value;
}

mapping(uint256 => string) public stringMap;
mapping(uint256 key => string) public stringMap;

function setString(bytes32 slot, string calldata value) public {
slot.getStringSlot().value = value;
Expand All @@ -57,7 +57,7 @@ contract StorageSlotMock {
return stringMap[key].getStringSlot().value;
}

mapping(uint256 => bytes) public bytesMap;
mapping(uint256 key => bytes) public bytesMap;

function setBytes(bytes32 slot, bytes calldata value) public {
slot.getBytesSlot().value = value;
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/VotesMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.20;
import {Votes} from "../governance/utils/Votes.sol";

abstract contract VotesMock is Votes {
mapping(address => uint256) private _votingUnits;
mapping(address voter => uint256) private _votingUnits;

function getTotalSupply() public view returns (uint256) {
return _getTotalSupply();
Expand Down
8 changes: 4 additions & 4 deletions contracts/mocks/token/ERC20VotesLegacyMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ abstract contract ERC20VotesLegacyMock is IVotes, ERC20Permit {
bytes32 private constant _DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");

mapping(address => address) private _delegates;
mapping(address => Checkpoint[]) private _checkpoints;
mapping(address account => address) private _delegatee;
mapping(address delegatee => Checkpoint[]) private _checkpoints;
Checkpoint[] private _totalSupplyCheckpoints;

/**
Expand All @@ -42,7 +42,7 @@ abstract contract ERC20VotesLegacyMock is IVotes, ERC20Permit {
* @dev Get the address `account` is currently delegating to.
*/
function delegates(address account) public view virtual returns (address) {
return _delegates[account];
return _delegatee[account];
}

/**
Expand Down Expand Up @@ -188,7 +188,7 @@ abstract contract ERC20VotesLegacyMock is IVotes, ERC20Permit {
function _delegate(address delegator, address delegatee) internal virtual {
address currentDelegate = delegates(delegator);
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = delegatee;
_delegatee[delegator] = delegatee;

emit DelegateChanged(delegator, currentDelegate, delegatee);

Expand Down
6 changes: 2 additions & 4 deletions contracts/token/ERC1155/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IER
using Arrays for uint256[];
using Arrays for address[];

// Mapping from token ID to account balances
mapping(uint256 => mapping(address => uint256)) private _balances;
mapping(uint256 id => mapping(address account => uint256)) private _balances;

// Mapping from account to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
mapping(address account => mapping(address operator => bool)) private _operatorApprovals;

// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
string private _uri;
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC1155/extensions/ERC1155Supply.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {ERC1155} from "../ERC1155.sol";
* CAUTION: This extension should not be added in an upgrade to an already deployed contract.
*/
abstract contract ERC1155Supply is ERC1155 {
mapping(uint256 => uint256) private _totalSupply;
mapping(uint256 id => uint256) private _totalSupply;
uint256 private _totalSupplyAll;

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC1155/extensions/ERC1155URIStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract contract ERC1155URIStorage is ERC1155 {
string private _baseURI = "";

// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
mapping(uint256 tokenId => string) private _tokenURIs;

/**
* @dev See {IERC1155MetadataURI-uri}.
Expand Down
4 changes: 2 additions & 2 deletions contracts/token/ERC20/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
* allowances. See {IERC20-approve}.
*/
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;

Expand Down
12 changes: 4 additions & 8 deletions contracts/token/ERC721/ERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
// Token symbol
string private _symbol;

// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
mapping(uint256 tokenId => address) private _owners;

// Mapping owner address to token count
mapping(address => uint256) private _balances;
mapping(address owner => uint256) private _balances;

// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
mapping(uint256 tokenId => address) private _tokenApprovals;

// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;

/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
Expand Down
12 changes: 3 additions & 9 deletions contracts/token/ERC721/extensions/ERC721Enumerable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ import {IERC165} from "../../../utils/introspection/ERC165.sol";
* interfere with enumerability and should not be used together with `ERC721Enumerable`.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
mapping(address owner => mapping(uint256 index => 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;

// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
mapping(uint256 tokenId => uint256) private _allTokensIndex;

/**
* @dev An `owner`'s token query was out of bounds for `index`.
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/extensions/ERC721URIStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract contract ERC721URIStorage is IERC4906, ERC721 {
using Strings for uint256;

// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
mapping(uint256 tokenId => string) private _tokenURIs;

/**
* @dev See {IERC165-supportsInterface}
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/common/ERC2981.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract contract ERC2981 is IERC2981, ERC165 {
}

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).
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/Nonces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract contract Nonces {
*/
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.
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/structs/BitMaps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pragma solidity ^0.8.20;
*/
library BitMaps {
struct BitMap {
mapping(uint256 => uint256) _data;
mapping(uint256 bucket => uint256) _data;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/structs/DoubleEndedQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ library DoubleEndedQueue {
struct Bytes32Deque {
uint128 _begin;
uint128 _end;
mapping(uint128 => bytes32) _data;
mapping(uint128 index => bytes32) _data;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/structs/EnumerableMap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ library EnumerableMap {
struct Bytes32ToBytes32Map {
// Storage of keys
EnumerableSet.Bytes32Set _keys;
mapping(bytes32 => bytes32) _values;
mapping(bytes32 key => bytes32) _values;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/structs/EnumerableSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ library EnumerableSet {
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
mapping(bytes32 value => uint256) _indexes;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate/templates/EnumerableMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ error EnumerableMapNonexistentKey(bytes32 key);
struct Bytes32ToBytes32Map {
// Storage of keys
EnumerableSet.Bytes32Set _keys;
mapping(bytes32 => bytes32) _values;
mapping(bytes32 key => bytes32) _values;
}
/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate/templates/EnumerableSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct Set {
bytes32[] _values;
// Position of the value in the \`values\` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
mapping(bytes32 value => uint256) _indexes;
}
/**
Expand Down

0 comments on commit cb0ffef

Please sign in to comment.