From 79a88b628ebd6e5de41d68836e7e6be2105ac7c1 Mon Sep 17 00:00:00 2001 From: bmzig <57361391+bmzig@users.noreply.github.com> Date: Thu, 18 Jul 2024 06:06:34 -0600 Subject: [PATCH] feat(utils): make unsafeAllow parameters configurable (#551) This is the follow up to a comment in the Blast deployments PR. --------- Signed-off-by: bennett --- utils/utils.hre.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/utils/utils.hre.ts b/utils/utils.hre.ts index 0ffebcd55..116a66d33 100644 --- a/utils/utils.hre.ts +++ b/utils/utils.hre.ts @@ -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. @@ -30,20 +42,25 @@ export async function deployNewProxy( initArgs: FnArgs[], implementationOnly = false ): Promise { - 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", });