diff --git a/src/DeploymentFactory.ts b/src/DeploymentFactory.ts index ffbf43ba..981c30de 100644 --- a/src/DeploymentFactory.ts +++ b/src/DeploymentFactory.ts @@ -6,7 +6,7 @@ import { import { ContractFactory, PayableOverrides, Signer, ethers } from 'ethers'; import { Artifact } from 'hardhat/types'; import * as zk from 'zksync-ethers'; -import { Address, DeployOptions, ExtendedArtifact } from '../types'; +import { Address, Deployment, DeployOptions, ExtendedArtifact } from '../types'; import { getAddress } from '@ethersproject/address'; import { keccak256 as solidityKeccak256 } from '@ethersproject/solidity'; import { hexConcat } from '@ethersproject/bytes'; @@ -52,19 +52,33 @@ export class DeploymentFactory { this.args = args; } - // TODO add ZkSyncArtifact - private async extractFactoryDeps(artifact: any): Promise { + public async extractFactoryDeps(artifact: any): Promise { + const visited = new Set(); + visited.add(`${artifact.sourceName}:${artifact.contractName}`); + return await this._extractFactoryDepsRecursive(artifact, visited); + } + + private async _extractFactoryDepsRecursive( + artifact: any, + visited: Set + ): Promise { // Load all the dependency bytecodes. // We transform it into an array of bytecodes. const factoryDeps: string[] = []; for (const dependencyHash in artifact.factoryDeps) { + if (!dependencyHash) continue; const dependencyContract = artifact.factoryDeps[dependencyHash]; - const dependencyBytecodeString = ( - await this.getArtifact(dependencyContract) - ).bytecode; - factoryDeps.push(dependencyBytecodeString); + if (!visited.has(dependencyContract)) { + const dependencyArtifact = await this.getArtifact(dependencyContract); + factoryDeps.push(dependencyArtifact.bytecode); + visited.add(dependencyContract); + const transitiveDeps = await this._extractFactoryDepsRecursive( + dependencyArtifact, + visited + ); + factoryDeps.push(...transitiveDeps); + } } - return factoryDeps; } @@ -137,17 +151,16 @@ export class DeploymentFactory { } public async compareDeploymentTransaction( - transaction: TransactionResponse + transaction: TransactionResponse, + deployment: Deployment ): Promise { const newTransaction = await this.getDeployTransaction(); const newData = newTransaction.data?.toString(); if (this.isZkSync) { - const deserialize = zk.utils.parseTransaction(transaction.data) as any; - const desFlattened = hexConcat(deserialize.customData.factoryDeps); - const factoryDeps = await this.extractFactoryDeps(this.artifact); - const newFlattened = hexConcat(factoryDeps); + const currentFlattened = hexConcat(deployment.factoryDeps || []); + const newFlattened = hexConcat(newTransaction.customData?.factoryDeps); - return deserialize.data !== newData || desFlattened != newFlattened; + return transaction.data !== newData || currentFlattened != newFlattened; } else { return transaction.data !== newData; } @@ -163,9 +176,9 @@ export class DeploymentFactory { } if (this.isZkSync) { - const deployedAddresses = zk.utils.getDeployedContracts(receipt).map( - (info) => info.deployedAddress, - ); + const deployedAddresses = zk.utils + .getDeployedContracts(receipt) + .map((info) => info.deployedAddress); return deployedAddresses[deployedAddresses.length - 1]; } diff --git a/src/DeploymentsManager.ts b/src/DeploymentsManager.ts index 70f43f2c..bcfd957e 100644 --- a/src/DeploymentsManager.ts +++ b/src/DeploymentsManager.ts @@ -890,6 +890,7 @@ export class DeploymentsManager { if (deployment.factoryDeps?.length) { obj.factoryDeps = deployment.factoryDeps; } + this.db.deployments[name] = obj; if (obj.address === undefined && obj.transactionHash !== undefined) { let receiptFetched; diff --git a/src/helpers.ts b/src/helpers.ts index b79b4ce0..86e8575e 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -633,13 +633,16 @@ export function addHelpers( options, create2Address ); + const deployment = { ...preDeployment, address, receipt, transactionHash: receipt.transactionHash, libraries: options.libraries, + factoryDeps: unsignedTx.customData?.factoryDeps || [], }; + await saveDeployment(name, deployment); if (options.log || hardwareWallet) { print( @@ -878,7 +881,8 @@ export function addHelpers( if (transaction) { const differences = await factory.compareDeploymentTransaction( - transaction + transaction, + deployment ); return {differences, address: deployment.address}; } else {