-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathDelayedImplementationManager.sol
More file actions
65 lines (59 loc) · 2.16 KB
/
DelayedImplementationManager.sol
File metadata and controls
65 lines (59 loc) · 2.16 KB
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
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.8.2;
import "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title DelayedImplementationManager
* @author Kongliang Zhong - <kongliang@loopring.org>
*/
contract DelayedImplementationManagerV2 is Ownable {
address public currImpl;
address public nextImpl;
uint public nextEffectiveTime;
event UpgradeScheduled(address nextImpl, uint effectiveTime);
event UpgradeCancelled(address nextImpl);
event ImplementationChanged(address newImpl);
constructor(address initImpl) {
require(initImpl != address(0), "ZERO_ADDRESS");
currImpl = initImpl;
}
/**
* @dev Allows the proxy owner to upgrade the current version of the proxy.
* @param _nextImpl representing the address of the next implementation to be set.
* @param _daysToDelay representing the amount of days after the next implementation take effect.
*/
function delayedUpgradeTo(
address _nextImpl,
uint _daysToDelay
) public onlyOwner {
if (_nextImpl == address(0)) {
require(
nextImpl != address(0) && _daysToDelay == 0,
"INVALID_ARGS"
);
emit UpgradeCancelled(nextImpl);
nextImpl = address(0);
} else {
// remove it only for test
// require(_daysToDelay >= 1, "INVALID_DAYS");
// solhint-disable-next-line not-rely-on-time
uint _nextEffectiveTime = block.timestamp + _daysToDelay * 1 days;
nextImpl = _nextImpl;
nextEffectiveTime = _nextEffectiveTime;
emit UpgradeScheduled(_nextImpl, _nextEffectiveTime);
}
}
/**
* @dev Allows everyone to replace implementation after effective time.
*/
function executeUpgrade() public {
require(
// solhint-disable-next-line not-rely-on-time
nextImpl != address(0) && block.timestamp >= nextEffectiveTime,
"NOT_IN_EFFECT"
);
currImpl = nextImpl;
nextImpl = address(0);
emit ImplementationChanged(currImpl);
}
}