-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGuardian.sol
69 lines (57 loc) · 1.83 KB
/
Guardian.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
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.26;
import {Root} from "src/Root.sol";
import {IGuardian} from "src/interfaces/IGuardian.sol";
import {IGateway} from "src/interfaces/gateway/IGateway.sol";
interface ISafe {
function isOwner(address signer) external view returns (bool);
}
contract Guardian is IGuardian {
Root public immutable root;
ISafe public immutable safe;
IGateway public immutable gateway;
constructor(address safe_, address root_, address gateway_) {
root = Root(root_);
safe = ISafe(safe_);
gateway = IGateway(gateway_);
}
modifier onlySafe() {
require(msg.sender == address(safe), "Guardian/not-the-authorized-safe");
_;
}
modifier onlySafeOrOwner() {
require(
msg.sender == address(safe) || _isSafeOwner(msg.sender), "Guardian/not-the-authorized-safe-or-its-owner"
);
_;
}
// --- Admin actions ---
/// @inheritdoc IGuardian
function pause() external onlySafeOrOwner {
root.pause();
}
/// @inheritdoc IGuardian
function unpause() external onlySafe {
root.unpause();
}
/// @inheritdoc IGuardian
function scheduleRely(address target) external onlySafe {
root.scheduleRely(target);
}
/// @inheritdoc IGuardian
function cancelRely(address target) external onlySafe {
root.cancelRely(target);
}
/// @inheritdoc IGuardian
function disputeMessageRecovery(address adapter, bytes32 messageHash) external onlySafe {
gateway.disputeMessageRecovery(adapter, messageHash);
}
// --- Helpers ---
function _isSafeOwner(address addr) internal view returns (bool) {
try safe.isOwner(addr) returns (bool isOwner) {
return isOwner;
} catch {
return false;
}
}
}