Skip to content

Commit

Permalink
fix: return valid address for zksync deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
kiriyaga committed Mar 12, 2024
1 parent 8e13436 commit fe4fb90
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
36 changes: 34 additions & 2 deletions src/DeploymentFactory.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import {
TransactionReceipt,
TransactionRequest,
TransactionResponse,
} from '@ethersproject/providers';
import {ContractFactory, PayableOverrides, Signer} from 'ethers';
import {ContractFactory, PayableOverrides, Signer, ethers} from 'ethers';
import {Artifact} from 'hardhat/types';
import * as zk from 'zksync-ethers';
import {Address, ExtendedArtifact} from '../types';
import {Address, DeployOptions, ExtendedArtifact} from '../types';
import {getAddress} from '@ethersproject/address';
import {keccak256 as solidityKeccak256} from '@ethersproject/solidity';
import {hexConcat} from '@ethersproject/bytes';
import {CONTRACT_DEPLOYER_ADDRESS} from 'zksync-ethers/build/src/utils';

export class DeploymentFactory {
private factory: ContractFactory;
Expand Down Expand Up @@ -151,4 +153,34 @@ export class DeploymentFactory {
return transaction.data !== newData;
}
}

getDeployedAddress(
receipt: TransactionReceipt,
options: DeployOptions,
create2Address: string | undefined
): string {
if (options.deterministicDeployment && create2Address) {
return create2Address;
}

if (this.isZkSync) {
const addressBytesLen = 40;
const addresses = receipt.logs
.filter(
(log) =>
log.topics[0] ==
ethers.utils.id('ContractDeployed(address,bytes32,address)') &&
log.address == CONTRACT_DEPLOYER_ADDRESS
)
.map((log) => {
const address = `0x${log.topics[3].slice(
log.topics[3].length - addressBytesLen
)}`;
return address;
});
return addresses[addresses.length - 1];
}

return receipt.contractAddress;
}
}
9 changes: 5 additions & 4 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,11 @@ export function addHelpers(
}
tx = await onPendingTx(tx, name, preDeployment);
const receipt = await tx.wait(options.waitConfirmations);
const address =
options.deterministicDeployment && create2Address
? create2Address
: receipt.contractAddress;
const address = factory.getDeployedAddress(
receipt,
options,
create2Address
);
const deployment = {
...preDeployment,
address,
Expand Down

0 comments on commit fe4fb90

Please sign in to comment.