Skip to content

Commit

Permalink
Convert type of receipt from ethers v6 to hardhat-deploy
Browse files Browse the repository at this point in the history
hardhat-deploy plugin expects different type of the receipt compared
to what ethers v6 returns. This commit changes the type of the receipt
from ethers v6 to hardhat-deploy.
  • Loading branch information
nkuba committed Aug 8, 2024
1 parent e9a1348 commit b70adc5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/upgrades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
Contract,
ContractFactory,
ContractTransactionResponse,
TransactionReceiptParams,
} from "ethers"
import type {
Artifact,
Expand All @@ -15,7 +16,7 @@ import type {
DeployProxyOptions,
UpgradeProxyOptions,
} from "@openzeppelin/hardhat-upgrades/src/utils/options"
import { Libraries } from "hardhat-deploy/types"
import { Libraries, Receipt } from "hardhat-deploy/types"

export interface HardhatUpgradesHelpers {
deployProxy<T extends Contract>(
Expand Down Expand Up @@ -115,6 +116,7 @@ export async function deployProxy<T extends Contract>(
libraries: opts?.factoryOpts?.libraries,
devdoc: "Contract deployed as upgradable proxy",
args: opts?.proxyOpts?.constructorArgs,
receipt: convertReceipt(transactionReceipt),
}

await deployments.save(name, deployment)
Expand Down Expand Up @@ -199,13 +201,35 @@ async function upgradeProxy<T extends Contract>(
libraries: opts?.factoryOpts?.libraries,
devdoc: "Contract deployed as upgradable proxy",
args: opts?.proxyOpts?.constructorArgs,
receipt: convertReceipt(transactionReceipt),
}

await deployments.save(proxyDeploymentName, deployment)

return [newContractInstance, deployment]
}

function convertReceipt(tx: TransactionReceiptParams): Receipt {
return {
...tx,
transactionHash: tx.hash,
transactionIndex: tx.index,
cumulativeGasUsed: tx.cumulativeGasUsed.toString(),
gasUsed: tx.gasUsed.toString(),
contractAddress: tx.contractAddress!,
to: tx.to!,
from: tx.from!,
status: tx.status!,
logs: tx.logs.map((log) => {
return {
...log,
logIndex: log.index,
topics: log.topics.map((topic) => topic),
}
}),
}
}

export default function (
hre: HardhatRuntimeEnvironment
): HardhatUpgradesHelpers {
Expand Down

0 comments on commit b70adc5

Please sign in to comment.