UNPKG

@openzeppelin/hardhat-upgrades

Version:

[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/upgrades-plugins/hardhat-upgrades) [![NPM Package](https://img.shields.io/npm/v/@openzeppelin/hardhat-upgrades.svg)](https://www.npmjs.org/package/@openzeppelin/h

50 lines (41 loc) • 1.91 kB
import type { Deployment, RemoteDeploymentId } from '@openzeppelin/upgrades-core'; import type { ethers, ContractFactory, ContractMethodArgs } from 'ethers'; import { HardhatRuntimeEnvironment } from 'hardhat/types/hre'; import { defenderDeploy } from '../defender/deploy.js'; import { EthersDeployOptions, DefenderDeployOptions, UpgradeOptions } from './options.js'; export interface DeployTransaction { deployTransaction?: ethers.TransactionResponse; } // Defender always includes RemoteDeploymentId, while ethers always includes DeployTransaction export type EthersOrDefenderDeployment = Required<Deployment> & DeployTransaction & RemoteDeploymentId; export type DefenderDeployment = Required<Deployment & RemoteDeploymentId> & DeployTransaction; export type EthersDeployment = Required<Deployment & DeployTransaction> & RemoteDeploymentId; export async function deploy( hre: HardhatRuntimeEnvironment, opts: UpgradeOptions & EthersDeployOptions & DefenderDeployOptions, factory: ContractFactory, ...args: unknown[] ): Promise<EthersOrDefenderDeployment> { if (opts?.useDefenderDeploy) { // For defenderDeploy, we'll handle connection internally for now return await defenderDeploy(hre, factory, opts, ...args); } else { if (opts.txOverrides !== undefined) { args.push(opts.txOverrides); } return await ethersDeploy(factory, ...args); } } async function ethersDeploy( factory: ContractFactory, ...args: ContractMethodArgs<unknown[]> ): Promise<EthersDeployment> { const contractInstance = await factory.deploy(...args); const deployTransaction = contractInstance.deploymentTransaction(); if (deployTransaction === null) { throw new Error('Broken invariant: deploymentTransaction is null'); } const address = await contractInstance.getAddress(); const txHash = deployTransaction.hash; return { address, txHash, deployTransaction }; }