Skip to content

Commit

Permalink
feat(utils): make unsafeAllow parameters configurable (#551)
Browse files Browse the repository at this point in the history
This is the follow up to a comment in the Blast deployments PR.

---------

Signed-off-by: bennett <[email protected]>
  • Loading branch information
bmzig authored Jul 18, 2024
1 parent 9be0637 commit 79a88b6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions utils/utils.hre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@ import hre from "hardhat";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployment, DeploymentSubmission } from "hardhat-deploy/types";
import { getContractFactory } from "./utils";
import { CHAIN_IDs } from "@across-protocol/constants";

type unsafeAllowTypes = (
| "delegatecall"
| "state-variable-immutable"
| "constructor"
| "selfdestruct"
| "state-variable-assignment"
| "external-library-linking"
| "struct-definition"
| "enum-definition"
| "missing-public-upgradeto"
)[];
/**
* @description Resolve the HubPool deployment, as well as the HubPool and SpokePool chain IDs for a new deployment.
* @dev This function relies on having companionNetworks defined in the HardhatUserConfig.
Expand Down Expand Up @@ -30,20 +42,25 @@ export async function deployNewProxy(
initArgs: FnArgs[],
implementationOnly = false
): Promise<void> {
const { deployments, run, upgrades } = hre;
const { deployments, run, upgrades, getChainId } = hre;
let chainId = Number(await getChainId());

let instance: string;
let unsafeAllowArgs = ["delegatecall"]; // Remove after upgrading openzeppelin-contracts-upgradeable post v4.9.3.
if ([CHAIN_IDs.BLAST, CHAIN_IDs.BLAST_SEPOLIA].includes(chainId)) {
unsafeAllowArgs.push("state-variable-immutable");
}
if (implementationOnly) {
instance = (await upgrades.deployImplementation(await getContractFactory(name, {}), {
constructorArgs,
kind: "uups",
unsafeAllow: ["delegatecall", "state-variable-immutable"],
unsafeAllow: unsafeAllowArgs as unsafeAllowTypes,
})) as string;
console.log(`New ${name} implementation deployed @ ${instance}`);
} else {
const proxy = await upgrades.deployProxy(await getContractFactory(name, {}), initArgs, {
kind: "uups",
unsafeAllow: ["delegatecall", "state-variable-immutable"], // Remove after upgrading openzeppelin-contracts-upgradeable post v4.9.3.
unsafeAllow: unsafeAllowArgs as unsafeAllowTypes,
constructorArgs,
initializer: "initialize",
});
Expand Down

0 comments on commit 79a88b6

Please sign in to comment.