From 5e1fda061dd4a80f65e58dad2e1e3757aa511514 Mon Sep 17 00:00:00 2001 From: Jagoda Berry Rybacka Date: Tue, 23 Jan 2024 13:35:29 +0100 Subject: [PATCH 1/2] Extrct deployment transaction from upgraded contract After proxy contract is upgraded we had a problem with extracting deployment transaction via `contract.deploymentTransaction()` from ethers. It was happening because OpenZeppelin's `upgradeProxy` was replacing deployment tx on the proxy contract but the field was different than what ethers function expected. Let's make it work by directly using the field that `upgradeProxy` adds on the contact's object. --- src/upgrades.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/upgrades.ts b/src/upgrades.ts index 6f659b0..580cd8b 100644 --- a/src/upgrades.ts +++ b/src/upgrades.ts @@ -1,6 +1,10 @@ import "@openzeppelin/hardhat-upgrades" -import type { Contract, ContractFactory } from "ethers" +import type { + Contract, + ContractFactory, + ContractTransactionResponse, +} from "ethers" import type { Artifact, FactoryOptions, @@ -149,7 +153,11 @@ async function upgradeProxy( opts?.proxyOpts )) as T - const deploymentTransaction = newContractInstance.deploymentTransaction() + // This is a workaround to get the deployment transaction. The upgradeProxy attaches + // the deployment transaction to the field under a different name than ethers + // contract.deploymentTransaction() function expects. + const deploymentTransaction = + newContractInstance.deployTransaction as unknown as ContractTransactionResponse // Let the transaction propagate across the ethereum nodes. This is mostly to // wait for all Alchemy nodes to catch up their state. From e077028eca6d83786121b41970c38f09a41ced9e Mon Sep 17 00:00:00 2001 From: Jagoda Berry Rybacka Date: Tue, 23 Jan 2024 17:06:19 +0100 Subject: [PATCH 2/2] Update comment for a workaround to link tracking issue --- src/upgrades.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/upgrades.ts b/src/upgrades.ts index 580cd8b..af1ee24 100644 --- a/src/upgrades.ts +++ b/src/upgrades.ts @@ -156,6 +156,8 @@ async function upgradeProxy( // This is a workaround to get the deployment transaction. The upgradeProxy attaches // the deployment transaction to the field under a different name than ethers // contract.deploymentTransaction() function expects. + // TODO: Remove this workaround once the issue is fixed on the OpenZeppelin side. + // Tracked in: https://github.com/keep-network/hardhat-helpers/issues/49 const deploymentTransaction = newContractInstance.deployTransaction as unknown as ContractTransactionResponse