generated from BreadchainCoop/solidity-foundry-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathUpgradeExecute.s.sol
More file actions
61 lines (49 loc) · 2.48 KB
/
UpgradeExecute.s.sol
File metadata and controls
61 lines (49 loc) · 2.48 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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {ProxyAdmin} from '@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol';
import {ITransparentUpgradeableProxy} from '@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol';
import {console2} from 'forge-std/console2.sol';
import {Common} from 'script/Common.sol';
contract UpgradeExecute is Common {
error NewImplementationHasNoCode(address implementation);
error NewImplementationMatchesCurrent(address implementation);
error AlreadyUpgraded(address implementation);
function run() public {
address proxy = vm.envAddress('PROXY_ADDRESS');
address expectedAdminOwner = vm.envAddress('EXPECTED_ADMIN_OWNER');
address expectedCurrentImplementation = vm.envAddress('EXPECTED_CURRENT_IMPLEMENTATION');
address newImplementation = vm.envAddress('NEW_IMPLEMENTATION');
bytes memory upgradeCalldata = _upgradeCalldataOrEmpty();
address currentImplementation = _readAddressFromSlot(proxy, _ERC1967_IMPLEMENTATION_SLOT);
if (currentImplementation == newImplementation) revert AlreadyUpgraded(newImplementation);
address proxyAdmin = _assertDeployment(proxy, expectedCurrentImplementation, expectedAdminOwner);
if (newImplementation.code.length == 0) revert NewImplementationHasNoCode(newImplementation);
if (newImplementation == expectedCurrentImplementation) {
revert NewImplementationMatchesCurrent(newImplementation);
}
console2.log('Executing upgrade');
console2.log('Proxy', proxy);
console2.log('ProxyAdmin', proxyAdmin);
console2.log('AdminOwner', expectedAdminOwner);
console2.log('CurrentImplementation', currentImplementation);
console2.log('NewImplementation', newImplementation);
console2.log('CalldataLength');
console2.log(upgradeCalldata.length);
vm.startBroadcast();
ProxyAdmin(proxyAdmin)
.upgradeAndCall(ITransparentUpgradeableProxy(payable(proxy)), newImplementation, upgradeCalldata);
vm.stopBroadcast();
_assertDeployment(proxy, newImplementation, expectedAdminOwner);
console2.log('Upgrade successful');
console2.log('Proxy', proxy);
console2.log('ProxyAdmin', proxyAdmin);
console2.log('CurrentImplementation', _readAddressFromSlot(proxy, _ERC1967_IMPLEMENTATION_SLOT));
}
function _upgradeCalldataOrEmpty() internal view returns (bytes memory data) {
try vm.envBytes('UPGRADE_CALLDATA') returns (bytes memory envData) {
return envData;
} catch {
return bytes('');
}
}
}