Skip to content

Commit

Permalink
fix(contracts): not upgrade already deployed contract (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
seolaoh authored Aug 8, 2024
1 parent 2ec4403 commit bc896c5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/contracts/src/deploy-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export const deploy = async (
name: string,
opts: DeployOptions = {}
): Promise<Contract | null> => {
const created = await deployImpl(hre, name, opts)
const [created, newlyDeployed] = await deployImpl(hre, name, opts)
if (!newlyDeployed) {
return created
}

if (opts.isProxyImpl) {
const { deployer } = await hre.getNamedAccounts()
Expand Down Expand Up @@ -107,7 +110,10 @@ export const deployAndUpgradeByDeployer = async (
name: string,
opts: DeployOptions = {}
): Promise<Contract | null> => {
const created = await deployImpl(hre, name, opts)
const [created, newlyDeployed] = await deployImpl(hre, name, opts)
if (!newlyDeployed) {
return created
}

const { deployer } = await hre.getNamedAccounts()
const proxyName = name + 'Proxy'
Expand Down Expand Up @@ -158,12 +164,13 @@ export const deployAndUpgradeByDeployer = async (
* @param opts.args Arguments to pass to the contract constructor.
* @param opts.postDeployAction Action to perform after the contract is deployed.
* @returns A deployed contract object.
* @returns If the contract is newly deployed or not.
*/
const deployImpl = async (
hre: HardhatRuntimeEnvironment,
name: string,
opts: DeployOptions = {}
): Promise<Contract | null> => {
): Promise<[Contract | null, boolean]> => {
const { deployer } = await hre.getNamedAccounts()

// Wrap in a try/catch in case there is not a deployConfig for the current network.
Expand Down Expand Up @@ -194,7 +201,7 @@ const deployImpl = async (

// If the contract is not newly deployed, do not proceed further.
if (!result.newlyDeployed) {
return created
return [created, false]
}

// Always wait for the transaction to be mined, just in case.
Expand All @@ -211,7 +218,7 @@ const deployImpl = async (
await opts.postDeployAction(created)
}

return created
return [created, true]
}

/**
Expand Down

0 comments on commit bc896c5

Please sign in to comment.