Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(contracts): not upgrade already deployed contract #371

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading