AddressSet
Inherits: IAddressSet, Ownable
Title: AddressSet
Author: Golem Foundation
Managed set of addresses for allowlists and blocklists
Wrapper around OpenZeppelin's EnumerableSet with owner controls USE CASES:
- Allowlists: Control who can interact with a contract
- Blocklists: Prevent specific addresses from interacting
- Registry: Track set of authorized addresses FEATURES:
- O(1) add, remove, contains operations
- Enumerable (can iterate through all addresses)
- Owner-only modifications
- Batch operations supported
- Duplicate prevention GAS CONSIDERATIONS:
- Add: ~40k gas first time, ~20k subsequent
- Remove: ~20k gas
- Contains: ~200 gas (view)
- Batch operations save gas vs multiple transactions
Note: security-contact: [email protected]
State Variables
_addresses
Internal EnumerableSet storage
Uses OpenZeppelin's gas-optimized implementation
EnumerableSet.AddressSet private _addresses
Functions
constructor
constructor() Ownable(msg.sender);
contains
function contains(address account) external view override returns (bool);
values
Get all addresses in the set
function values() external view returns (address[] memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address[] | Array of all addresses |
length
Get number of addresses in the set
function length() external view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Number of addresses |
add
function add(address[] memory accounts) external override onlyOwner;
add
function add(address account) external override onlyOwner;
remove
Remove multiple addresses from the set
Reverts on first address not in the set
function remove(address[] memory accounts) external override onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
accounts | address[] | Addresses to remove |
remove
Remove an address from the set
Reverts if address is not in the set
function remove(address account) external override onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
account | address | Address to remove |
Events
AddressSetAltered
Emitted when an address is added to or removed from the set
event AddressSetAltered(address indexed account, AddressSetOperation indexed operation);
Parameters
| Name | Type | Description |
|---|---|---|
account | address | Address that was modified |
operation | AddressSetOperation | Type of operation (Add or Remove) |
Errors
IllegalAddressSetOperation
error IllegalAddressSetOperation(address account, string reason);
EmptyArray
error EmptyArray();
Enums
AddressSetOperation
Operation types for address set modifications
enum AddressSetOperation {
Add,
Remove
}