Skip to content

Commit 9a6ac9c

Browse files
authored
chore: Use Upgrade.sol in deploymentsUtil (#1302)
* chore: Use Upgrade.sol in deploymentsUtil Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> * skip oz verification Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> * add back checks Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> --------- Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com>
1 parent e0f4dbe commit 9a6ac9c

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

script/utils/DeploymentUtils.sol

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Script } from "forge-std/Script.sol";
55
import { Test } from "forge-std/Test.sol";
66
import { console } from "forge-std/console.sol";
77
import { Config } from "forge-std/Config.sol";
8-
import { Upgrades, Core, UnsafeUpgrades } from "@openzeppelin/foundry-upgrades/src/LegacyUpgrades.sol";
8+
import { Upgrades } from "@openzeppelin/foundry-upgrades/src/Upgrades.sol";
99
import { Options } from "@openzeppelin/foundry-upgrades/src/Options.sol";
1010
import { ERC1967Proxy } from "@openzeppelin/contracts-v4/proxy/ERC1967/ERC1967Proxy.sol";
1111
import { Constants } from "./Constants.sol";
@@ -86,7 +86,7 @@ contract DeploymentUtils is Script, Test, Constants, DeployedAddresses, Config {
8686
) public returns (DeploymentResult memory result) {
8787
uint256 chainId = block.chainid;
8888

89-
contractName = string(abi.encodePacked("contracts/", contractName, ".sol:", contractName));
89+
contractName = string(abi.encodePacked(contractName, ".sol:", contractName));
9090

9191
// Check if a SpokePool already exists on this chain
9292
address existingProxy = getDeployedAddress("SpokePool", chainId, false);
@@ -99,7 +99,13 @@ contract DeploymentUtils is Script, Test, Constants, DeployedAddresses, Config {
9999
Options memory opts;
100100

101101
opts.constructorData = constructorArgs;
102-
// opts.referenceBuildInfoDir = "artifacts";
102+
opts.unsafeAllow = "delegatecall";
103+
// Runs OZ upgrade safety checks via FFI before deployment.
104+
// NOTE: If the script reverts with no error message, the revert is likely from OZ validation
105+
// (revert strings are stripped in production builds). To debug:
106+
// 1. Run `forge clean && forge build` to ensure a fresh build, then re-run the script.
107+
// 2. Re-run with `--revert-strings default` to see the full error message.
108+
opts.unsafeSkipAllChecks = false;
103109

104110
if (implementationOnly && existingProxy != address(0)) {
105111
console.log(
@@ -110,20 +116,20 @@ contract DeploymentUtils is Script, Test, Constants, DeployedAddresses, Config {
110116
);
111117

112118
// For upgrades, we'll use the prepareUpgrade method from LegacyUpgrades
113-
address implementation = Core.deploy(contractName, constructorArgs, opts);
119+
address implementation = Upgrades.deployImplementation(contractName, opts);
114120

115121
result = DeploymentResult({ proxy: existingProxy, implementation: implementation, isNewProxy: false });
116122

117123
console.log("New", contractName, "implementation deployed @", implementation);
118124
} else {
119-
address implementation = Core.deploy(contractName, constructorArgs, opts);
125+
// Deploy implementation first, then proxy using the OZ v4 ERC1967Proxy directly
126+
// to avoid vm.getCode ambiguity with multiple ERC1967Proxy artifacts.
127+
address implementation = Upgrades.deployImplementation(contractName, opts);
128+
address proxy = address(new ERC1967Proxy(implementation, initArgs));
120129

121-
ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), initArgs);
130+
result = DeploymentResult({ proxy: proxy, implementation: implementation, isNewProxy: true });
122131

123-
// For now, return a placeholder result
124-
result = DeploymentResult({ proxy: address(proxy), implementation: implementation, isNewProxy: true });
125-
126-
console.log("New", contractName, "proxy deployed @", address(proxy));
132+
console.log("New", contractName, "proxy deployed @", proxy);
127133
console.log("New", contractName, "implementation deployed @", implementation);
128134
}
129135

0 commit comments

Comments
 (0)