-
Notifications
You must be signed in to change notification settings - Fork 1
/
BOGProxyAdmin.sol
99 lines (81 loc) · 4.19 KB
/
BOGProxyAdmin.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
//SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.7;
/**
* $$$$$$$\ $$\ $$$$$$$$\ $$\
* $$ __$$\ $$ | $$ _____|\__|
* $$ | $$ | $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$$ | $$ | $$\ $$$$$$$\ $$$$$$\ $$$$$$$\ $$$$$$$\ $$$$$$\
* $$$$$$$\ |$$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\ $$ __$$ | $$$$$\ $$ |$$ __$$\ \____$$\ $$ __$$\ $$ _____|$$ __$$\
* $$ __$$\ $$ / $$ |$$ / $$ |$$ / $$ |$$$$$$$$ |$$ / $$ | $$ __| $$ |$$ | $$ | $$$$$$$ |$$ | $$ |$$ / $$$$$$$$ |
* $$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ |$$ ____|$$ | $$ | $$ | $$ |$$ | $$ |$$ __$$ |$$ | $$ |$$ | $$ ____|
* $$$$$$$ |\$$$$$$ |\$$$$$$$ |\$$$$$$$ |\$$$$$$$\ \$$$$$$$ |$$\ $$ | $$ |$$ | $$ |\$$$$$$$ |$$ | $$ |\$$$$$$$\ \$$$$$$$\
* \_______/ \______/ \____$$ | \____$$ | \_______| \_______|\__|\__| \__|\__| \__| \_______|\__| \__| \_______| \_______|
* $$\ $$ |$$\ $$ |
* \$$$$$$ |\$$$$$$ |
* \______/ \______/
*
* https://bogged.finance/
*/
import "./BoggedFinanceProxy.sol";
contract BOGProxyAdmin {
address public owner;
BoggedFinanceProxy proxy;
uint256 public delay = 12 hours;
mapping (bytes32 => uint256) public timestamp;
constructor (BoggedFinanceProxy _proxy) {
owner = msg.sender;
proxy = _proxy;
}
modifier onlyOwner() {
require(msg.sender == owner, "BOGProxyAdmin: ONLY_OWNER"); _;
}
function schedule(address target, bytes memory data, uint256 nonce) external onlyOwner {
bytes32 hash = getOperationHash(target, data, nonce);
require(timestamp[hash] == 0, "BOGProxyAdmin: DUPLICATE_OPERATION");
timestamp[hash] = block.timestamp;
emit ScheduledCall(target, data, nonce);
}
function execute(address target, bytes memory data, uint256 nonce) external onlyOwner {
bytes32 hash = getOperationHash(target, data, nonce);
require(isReady(hash), "BOGProxyAdmin: NOT_READY");
(bool success, ) = target.call(data);
require(success, "BOGProxyAdmin: CALL_FAILED");
delete timestamp[hash];
emit ExecutedCall(target, data, nonce);
}
function cancel(address target, bytes memory data, uint256 nonce) external onlyOwner {
bytes32 hash = getOperationHash(target, data, nonce);
require(isPending(hash), "BOGProxyAdmin: !EXISTING_OPERATION");
delete timestamp[hash];
emit CancelledCall(target, data, nonce);
}
function getOperationHash(address target, bytes memory data, uint256 nonce) public pure returns (bytes32) {
return bytes32(keccak256(abi.encode(target, data, nonce)));
}
function isPending(bytes32 hash) public view returns (bool) {
return timestamp[hash] > 0;
}
function isReady(bytes32 hash) public view returns (bool) {
return isPending(hash) && timestamp[hash] + delay <= block.timestamp;
}
function pauseProxy() external onlyOwner {
proxy.pause();
}
function unpauseProxy() external onlyOwner {
proxy.unpause();
}
function setDelay(uint256 _delay) external {
require(msg.sender == address(this), "BOGProxyAdmin: TIMELOCKED_FUNCTION");
delay = _delay;
emit DelayUpdated(delay);
}
function transferOwnership(address newOwner) external {
require(msg.sender == address(this), "BOGProxyAdmin: TIMELOCKED_FUNCTION");
owner = newOwner;
emit OwnershipTransferred(newOwner);
}
event ScheduledCall(address target, bytes data, uint256 nonce);
event ExecutedCall(address target, bytes data, uint256 nonce);
event CancelledCall(address target, bytes data, uint256 nonce);
event DelayUpdated(uint256 delay);
event OwnershipTransferred(address newOwner);
}