Skip to content

Commit e815c96

Browse files
committed
feature
1 parent 417c1b6 commit e815c96

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ ALLOCATOR=<llocator_address>
1414
TERMINATION_ORACLE=<termination_oracle_address>
1515
ORACLE=<oracle_address>
1616
# Upgradeable contract envs
17-
UPGRADE_PROXY_ADDRESS_TEST=
17+
UPGRADE_PROXY_ADDRESS_TEST=0x2871dc22C60479cc89896EBA2bEb150130171230
1818
UPGRADE_PROXY_ADDRESS_CALIBNET=
1919
UPGRADE_PROXY_ADDRESS_MAINNET=
20-
UPGRADE_CONTRACT_NAME=
21-
UPGRADE_CALLDATA=
20+
UPGRADE_CONTRACT_NAME=Client
21+
UPGRADE_CALLDATA=0x0
2222

foundry.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
[profile.default]
2-
src = "src"
2+
solc_version = "0.8.25"
3+
evm_version = "cancun"
4+
optimizer_runs = 200
5+
fs_permissions = [
6+
{ access = "read-write", path = "./deployments/" }
7+
]
8+
src = "src"
39
out = "out"
410
libs = ["lib"]
511
via_ir = true

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ devnet_deploy:
3939

4040
upgrade:
4141
forge clean && forge build
42-
forge script script/Upgrade.s.sol:Upgrade --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
42+
forge script script/Upgrade.s.sol:Upgrade --rpc-url $RPC_TEST --private-key $PRIVATE_KEY_TEST --broadcast
4343

4444
# CI equivalent check
4545
check: fmt-check lint test check-coverage build check-abis

script/Upgrade.s.sol

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
pragma solidity ^0.8.25;
44

55
import {Script} from "forge-std/Script.sol";
6+
import {DeployUtils} from "./utils/DeployUtils.sol";
7+
import {stdJson} from "forge-std/StdJson.sol";
68

79
interface IUpgradeable {
810
function upgradeToAndCall(address newImpl, bytes calldata data) external;
911
}
1012

11-
contract Upgrade is Script {
13+
contract Upgrade is Script, DeployUtils {
14+
using stdJson for string;
15+
1216
address internal proxy;
1317
string internal name;
1418
bytes internal cd;
@@ -18,6 +22,14 @@ contract Upgrade is Script {
1822
name = vm.envString("UPGRADE_CONTRACT_NAME");
1923
cd = vm.envOr("UPGRADE_CALLDATA", bytes(""));
2024

25+
string memory json = readLatestDeploymentArtifact(name);
26+
(,,, bytes memory deployedCodeHash) = deserializeContract(json, name);
27+
bytes32 hash = generateContractHash(name);
28+
29+
if (hash == abi.decode(deployedCodeHash, (bytes32))) {
30+
revert("Code hash is unchanged, upgrade skipped");
31+
}
32+
2133
vm.startBroadcast(vm.envUint("PRIVATE_KEY_TEST"));
2234

2335
address impl = vm.deployCode(string.concat(name, ".sol:", name));

script/utils/DeployUtils.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ contract DeployUtils is Script {
3030
json.serialize(contractName, serialized);
3131
}
3232

33+
function readLatestDeploymentArtifact(string memory contractName) internal view returns (string memory json) {
34+
json = vm.readFile(string.concat("./deployments/", network(), "/latest.json"));
35+
}
36+
37+
function deserializeContract(string memory json, string memory contractName)
38+
internal
39+
returns (bytes memory proxy, bytes memory impl, bytes memory codeHash, bytes memory deployedCodeHash)
40+
{
41+
proxy = json.parseRaw(string.concat(".", contractName, ".proxy"));
42+
impl = json.parseRaw(string.concat(".", contractName, ".impl"));
43+
codeHash = json.parseRaw(string.concat(".", contractName, ".codeHash"));
44+
deployedCodeHash = json.parseRaw(string.concat(".", contractName, ".deployedCodeHash"));
45+
}
46+
47+
function generateContractHash(string memory contractName) internal view returns (bytes32 hash) {
48+
hash = keccak256(vm.getDeployedCode(string.concat(contractName, ".sol:", contractName)));
49+
}
50+
3351
function network() internal view returns (string memory) {
3452
if (block.chainid == 31415926) return "devnet";
3553
else if (block.chainid == 314159) return "calibnet";

0 commit comments

Comments
 (0)