forked from limitbreakinc/creator-token-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EOARegistryAccess.sol
60 lines (49 loc) · 2.48 KB
/
EOARegistryAccess.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "../interfaces/IEOARegistry.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title EOARegistryAccess
* @author Limit Break, Inc.
* @notice A contract mixin that provides access to an external EOA registry.
* For use when a contract needs the ability to check if an address is a verified EOA.
* @dev Take care and carefully consider whether or not to use this. Restricting operations to EOA only accounts can break Defi composability,
* so if Defi composability is an objective, this is not a good option. Be advised that in the future, EOA accounts might not be a thing
* but this is yet to be determined. See https://eips.ethereum.org/EIPS/eip-4337 for more information.
*/
abstract contract EOARegistryAccess is Ownable {
/// @dev Thrown when the EOA Registry address being set does not implement the `IEOARegistry` interface.
error InvalidEOARegistryContract();
/// @dev Points to an external contract that implements the `IEOARegistry` interface.
IEOARegistry private eoaRegistry;
/// @dev Emitted whenever the contract owner changes the EOA registry
event EOARegistryUpdated(address oldRegistry, address newRegistry);
/// @notice Allows contract owner to set the pointer to the EOA registry.
///
/// Throws when the specified address in non-zero and does not implement `IEOARegistry`.
/// Throws when caller is not the contract owner.
///
/// Postconditions:
/// ---------------
/// The eoa registry address is set to the specified address.
/// An `EOARegistryUpdated` event has been emitted.
///
/// @param eoaRegistry_ The address of the EOA Registry to set for verified EOA lookups.
function setEOARegistry(address eoaRegistry_) public onlyOwner {
bool isValidEOARegistry = false;
if(eoaRegistry_.code.length > 0) {
try IERC165(eoaRegistry_).supportsInterface(type(IEOARegistry).interfaceId) returns (bool supportsInterface) {
isValidEOARegistry = supportsInterface;
} catch {}
}
if(eoaRegistry_ != address(0) && !isValidEOARegistry) {
revert InvalidEOARegistryContract();
}
emit EOARegistryUpdated(address(eoaRegistry), eoaRegistry_);
eoaRegistry = IEOARegistry(eoaRegistry_);
}
/// @notice Returns the address of the EOA registry.
function getEOARegistry() public view returns (IEOARegistry) {
return eoaRegistry;
}
}