-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathChangeOwnerToTimelock.s.sol
More file actions
140 lines (122 loc) · 4.8 KB
/
ChangeOwnerToTimelock.s.sol
File metadata and controls
140 lines (122 loc) · 4.8 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
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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import {Script, console} from "lib/forge-std/src/Script.sol";
import {HelperConfig} from "../../HelperConfig.s.sol";
import {TimelockController} from "@openzeppelin/contracts/governance/TimelockController.sol";
import {LiquidityBridgeContractV2} from "../../../src/legacy/LiquidityBridgeContractV2.sol";
import {LiquidityBridgeContractAdmin} from "../../../src/legacy/LiquidityBridgeContractAdmin.sol";
contract ChangeOwnerToTimelock is Script {
bytes32 internal constant ADMIN_SLOT =
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
error ProxyAddressNotProvided();
error TimelockProposerIsZero();
error TimelockExecutorIsZero();
error OnlyCurrentLbcOwnerCanTransferOwnership();
error ContractOwnerTransferFailed();
error AdminAddressNotFound();
error OnlyCurrentProxyAdminOwnerCanTransferOwnership();
error ProxyAdminOwnerTransferFailed();
function run() external {
HelperConfig helper = new HelperConfig();
HelperConfig.NetworkConfig memory cfg = helper.getConfig();
uint256 deployerKey = helper.getDeployerPrivateKey();
vm.rememberKey(deployerKey);
address proxyAddress = cfg.existingProxy;
if (proxyAddress == address(0)) {
revert ProxyAddressNotProvided();
}
if (cfg.timelockProposer == address(0)) {
revert TimelockProposerIsZero();
}
if (cfg.timelockExecutor == address(0)) {
revert TimelockExecutorIsZero();
}
address[] memory proposers = new address[](1);
proposers[0] = cfg.timelockProposer;
address[] memory executors = new address[](1);
executors[0] = cfg.timelockExecutor;
vm.startBroadcast(deployerKey);
TimelockController timelock = new TimelockController(
cfg.timelockMinDelay,
proposers,
executors,
address(0)
);
_transferContractOwnership(proxyAddress, address(timelock));
_transferProxyAdminOwnership(proxyAddress, address(timelock));
vm.stopBroadcast();
_logFinalState(proxyAddress, timelock, cfg);
}
function _transferContractOwnership(
address proxyAddress,
address timelock
) internal {
LiquidityBridgeContractV2 contract_ = LiquidityBridgeContractV2(
payable(proxyAddress)
);
address currentOwner = contract_.owner();
if (currentOwner != timelock) {
if (currentOwner != msg.sender) {
revert OnlyCurrentLbcOwnerCanTransferOwnership();
}
contract_.transferOwnership(timelock);
}
if (contract_.owner() != timelock) {
revert ContractOwnerTransferFailed();
}
}
function _transferProxyAdminOwnership(
address proxyAddress,
address timelock
) internal {
address adminAddress = address(
uint160(uint256(vm.load(proxyAddress, ADMIN_SLOT)))
);
if (adminAddress == address(0)) {
revert AdminAddressNotFound();
}
LiquidityBridgeContractAdmin admin = LiquidityBridgeContractAdmin(
adminAddress
);
address currentAdminOwner = admin.owner();
if (currentAdminOwner != timelock) {
if (currentAdminOwner != msg.sender) {
revert OnlyCurrentProxyAdminOwnerCanTransferOwnership();
}
admin.transferOwnership(timelock);
}
if (admin.owner() != timelock) {
revert ProxyAdminOwnerTransferFailed();
}
}
function _logFinalState(
address proxyAddress,
TimelockController timelock,
HelperConfig.NetworkConfig memory cfg
) internal view {
LiquidityBridgeContractV2 contract_ = LiquidityBridgeContractV2(
payable(proxyAddress)
);
address adminAddress = address(
uint160(uint256(vm.load(proxyAddress, ADMIN_SLOT)))
);
LiquidityBridgeContractAdmin admin = LiquidityBridgeContractAdmin(
adminAddress
);
console.log("=== Timelock ownership setup complete ===");
console.log("Timelock:", address(timelock));
console.log("Timelock minDelay:", timelock.getMinDelay());
console.log("LBC owner:", contract_.owner());
console.log("Expected timelock:", address(timelock));
console.log("ProxyAdmin owner:", admin.owner());
console.log("Expected timelock:", address(timelock));
console.log(
"Proposer role granted:",
timelock.hasRole(timelock.PROPOSER_ROLE(), cfg.timelockProposer)
);
console.log(
"Executor role granted:",
timelock.hasRole(timelock.EXECUTOR_ROLE(), cfg.timelockExecutor)
);
}
}