-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOwnableWithGuardian.sol
51 lines (41 loc) · 1.34 KB
/
OwnableWithGuardian.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
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0;
import {Ownable} from 'openzeppelin-contracts/contracts/access/Ownable.sol';
import {IWithGuardian} from './interfaces/IWithGuardian.sol';
abstract contract OwnableWithGuardian is Ownable, IWithGuardian {
address private _guardian;
constructor(address initialOwner) Ownable(initialOwner) {
_updateGuardian(_msgSender());
}
modifier onlyGuardian() {
_checkGuardian();
_;
}
modifier onlyOwnerOrGuardian() {
_checkOwnerOrGuardian();
_;
}
function guardian() public view override returns (address) {
return _guardian;
}
/// @inheritdoc IWithGuardian
function updateGuardian(address newGuardian) external override onlyOwnerOrGuardian {
_updateGuardian(newGuardian);
}
/**
* @dev method to update the guardian
* @param newGuardian the new guardian address
*/
function _updateGuardian(address newGuardian) internal {
address oldGuardian = _guardian;
_guardian = newGuardian;
emit GuardianUpdated(oldGuardian, newGuardian);
}
function _checkGuardian() internal view {
if (guardian() != _msgSender()) revert OnlyGuardianInvalidCaller(_msgSender());
}
function _checkOwnerOrGuardian() internal view {
if (_msgSender() != owner() && _msgSender() != guardian())
revert OnlyGuardianOrOwnerInvalidCaller(_msgSender());
}
}