Skip to content

Commit

Permalink
Remove address override (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau authored Jul 4, 2023
1 parent b56a7e1 commit 000c4fd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
1 change: 1 addition & 0 deletions packages/plugin-hardhat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Use `hardhat-verify` for proxy verification. ([#829](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/829))
- Remove address override for deployments. ([#832](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/832))

## 2.0.0-alpha.0 (2023-06-20)

Expand Down
26 changes: 3 additions & 23 deletions packages/plugin-hardhat/src/utils/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { Deployment, RemoteDeploymentId } from '@openzeppelin/upgrades-core';
import debug from './debug';
import type { ethers, ContractFactory } from 'ethers';
import { getCreateAddress } from 'ethers';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { platformDeploy } from '../platform/deploy';
import { PlatformDeployOptions, UpgradeOptions } from './options';
import { getSigner } from './ethers';

export interface DeployTransaction {
deployTransaction?: ethers.TransactionResponse;
Expand All @@ -30,31 +27,14 @@ async function ethersDeploy(
...args: unknown[]
): Promise<Required<Deployment & DeployTransaction> & RemoteDeploymentId> {
const contractInstance = await factory.deploy(...args);
const deployTransaction = contractInstance.deploymentTransaction();

const deployTransaction = contractInstance.deploymentTransaction();
if (deployTransaction === null) {
throw new Error('Broken invariant: deploymentTransaction is null');
}

const signer = getSigner(factory.runner);
const contractAddress = await contractInstance.getAddress();

let address = contractAddress;

if (signer !== undefined) {
const from = await signer.getAddress();

// Some RPC endpoints can return an incorrect address. See https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/487
// As a workaround, calculate the correct address using the address and nonce.
address = getCreateAddress({
from: from,
nonce: deployTransaction.nonce,
});
if (address !== contractAddress) {
debug(`overriding contract address from ${contractAddress} to ${address} for nonce ${deployTransaction.nonce}`);
}
}

const address = await contractInstance.getAddress();
const txHash = deployTransaction.hash;

return { address, txHash, deployTransaction };
}

0 comments on commit 000c4fd

Please sign in to comment.