-
Notifications
You must be signed in to change notification settings - Fork 4
/
Registry.sol
92 lines (77 loc) · 3.63 KB
/
Registry.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.8.0;
import 'solmate/src/utils/CREATE3.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import './interfaces/IRegistry.sol';
/**
* @title Registry
* @dev Curated list of Mimic implementations
*/
contract Registry is IRegistry, Ownable {
// List of registered implementations
mapping (address => bool) public override isRegistered;
// List of stateless implementations
mapping (address => bool) public override isStateless;
// List of deprecated implementations
mapping (address => bool) public override isDeprecated;
/**
* @dev Creates a new Registry contract
* @param owner Address that will own the registry
*/
constructor(address owner) {
_transferOwnership(owner);
}
/**
* @dev Creates and registers an implementation
* @param name Name of the implementation
* @param code Code of the implementation to create and register
* @param stateless Whether the new implementation is considered stateless or not
*/
function create(string memory name, bytes memory code, bool stateless) external override onlyOwner {
address implementation = CREATE3.deploy(keccak256(abi.encode(name)), code, 0);
_register(name, implementation, stateless);
}
/**
* @dev Registers an implementation
* @param name Name logged for the implementation
* @param implementation Address of the implementation to be registered
* @param stateless Whether the given implementation is considered stateless or not
*/
function register(string memory name, address implementation, bool stateless) external override onlyOwner {
_register(name, implementation, stateless);
}
/**
* @dev Deprecates an implementation
* @param implementation Address of the implementation to be deprecated
*/
function deprecate(address implementation) external override onlyOwner {
if (implementation == address(0)) revert RegistryImplementationAddressZero();
if (!isRegistered[implementation]) revert RegistryImplementationNotRegistered(implementation);
if (isDeprecated[implementation]) revert RegistryImplementationDeprecated(implementation);
isDeprecated[implementation] = true;
emit Deprecated(implementation);
}
/**
* @dev Registers an implementation
* @param name Name of the implementation
* @param implementation Address of the implementation to be registered
* @param stateless Whether the given implementation is considered stateless or not
*/
function _register(string memory name, address implementation, bool stateless) internal {
if (implementation == address(0)) revert RegistryImplementationAddressZero();
if (isRegistered[implementation]) revert RegistryImplementationRegistered(implementation);
isRegistered[implementation] = true;
isStateless[implementation] = stateless;
emit Registered(implementation, name, stateless);
}
}