-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToucanContractRegistry.sol
233 lines (198 loc) · 6.5 KB
/
ToucanContractRegistry.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// SPDX-FileCopyrightText: 2021 Toucan Labs
//
// SPDX-License-Identifier: UNLICENSED
// If you encounter a vulnerability or an issue, please contact <security@toucan.earth> or visit security.toucan.earth
pragma solidity 0.8.14;
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
import './interfaces/IPausable.sol';
import './interfaces/IToucanContractRegistry.sol';
import './ToucanContractRegistryStorage.sol';
/// @dev The ToucanContractRegistry is queried by other contracts for current addresses
contract ToucanContractRegistry is
ToucanContractRegistryStorage,
OwnableUpgradeable,
AccessControlUpgradeable,
IToucanContractRegistry,
UUPSUpgradeable
{
// ----------------------------------------
// Constants
// ----------------------------------------
/// @dev Version-related parameters. VERSION keeps track of production
/// releases. VERSION_RELEASE_CANDIDATE keeps track of iterations
/// of a VERSION in our staging environment.
string public constant VERSION = '1.0.0';
uint256 public constant VERSION_RELEASE_CANDIDATE = 1;
/// @dev All roles related to accessing this contract
bytes32 public constant PAUSER_ROLE = keccak256('PAUSER_ROLE');
// ----------------------------------------
// Modifiers
// ----------------------------------------
modifier onlyBy(address _factory, address _owner) {
require(
_factory == _msgSender() || _owner == _msgSender(),
'Caller is not the factory'
);
_;
}
/// @dev modifier that only lets the contract's owner and granted pausers pause the system
modifier onlyPausers() {
require(
hasRole(PAUSER_ROLE, msg.sender) || owner() == msg.sender,
'Caller is not authorized'
);
_;
}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
/// @notice security function that pauses all contracts part of the carbon bri dge
function pauseSystem() external onlyPausers {
IPausable cpv = IPausable(_carbonProjectVintagesAddress);
if (!cpv.paused()) cpv.pause();
IPausable cp = IPausable(_carbonProjectsAddress);
if (!cp.paused()) cp.pause();
IPausable cob = IPausable(_carbonOffsetBatchesAddress);
if (!cob.paused()) cob.pause();
IPausable tcof = IPausable(_toucanCarbonOffsetsFactoryAddress);
if (!tcof.paused()) tcof.pause();
}
function unpauseSystem() external onlyOwner {
IPausable cpv = IPausable(_carbonProjectVintagesAddress);
if (cpv.paused()) cpv.unpause();
IPausable cp = IPausable(_carbonProjectsAddress);
if (cp.paused()) cp.unpause();
IPausable cob = IPausable(_carbonOffsetBatchesAddress);
if (cob.paused()) cob.unpause();
IPausable tcof = IPausable(_toucanCarbonOffsetsFactoryAddress);
if (tcof.paused()) tcof.unpause();
}
// ----------------------------------------
// Upgradable related functions
// ----------------------------------------
function initialize() external virtual initializer {
__Ownable_init();
__AccessControl_init_unchained();
__UUPSUpgradeable_init_unchained();
/// @dev granting the deployer==owner the rights to grant other roles
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
}
function _authorizeUpgrade(address newImplementation)
internal
virtual
override
onlyOwner
{}
// ----------------------------------------
// Setters
// ----------------------------------------
function setCarbonOffsetBatchesAddress(address _address)
external
virtual
onlyOwner
{
require(_address != address(0), 'Error: zero address provided');
_carbonOffsetBatchesAddress = _address;
}
function setCarbonProjectsAddress(address _address)
external
virtual
onlyOwner
{
require(_address != address(0), 'Error: zero address provided');
_carbonProjectsAddress = _address;
}
function setCarbonProjectVintagesAddress(address _address)
external
virtual
onlyOwner
{
require(_address != address(0), 'Error: zero address provided');
_carbonProjectVintagesAddress = _address;
}
function setToucanCarbonOffsetsFactoryAddress(address _address)
external
virtual
onlyOwner
{
require(_address != address(0), 'Error: zero address provided');
_toucanCarbonOffsetsFactoryAddress = _address;
}
function setCarbonOffsetBadgesAddress(address _address)
external
virtual
onlyOwner
{
require(_address != address(0), 'Error: zero address provided');
_carbonOffsetBadgesAddress = _address;
}
/// @dev function to add valid TCO2 contracts
function addERC20(address _address)
external
virtual
override
onlyBy(_toucanCarbonOffsetsFactoryAddress, owner())
{
projectVintageERC20Registry[_address] = true;
}
// ----------------------------------------
// Getters
// ----------------------------------------
function carbonOffsetBatchesAddress()
external
view
virtual
override
returns (address)
{
return _carbonOffsetBatchesAddress;
}
function carbonProjectsAddress()
external
view
virtual
override
returns (address)
{
return _carbonProjectsAddress;
}
function carbonProjectVintagesAddress()
external
view
virtual
override
returns (address)
{
return _carbonProjectVintagesAddress;
}
function toucanCarbonOffsetsFactoryAddress()
external
view
virtual
override
returns (address)
{
return _toucanCarbonOffsetsFactoryAddress;
}
function carbonOffsetBadgesAddress()
external
view
virtual
override
returns (address)
{
return _carbonOffsetBadgesAddress;
}
function checkERC20(address _address)
external
view
virtual
override
returns (bool)
{
return projectVintageERC20Registry[_address];
}
}