Skip to content

Commit

Permalink
fix(create:zk): pass ArtifactId
Browse files Browse the repository at this point in the history
refactor(create:zk): `remove_zk_contract` more similar to upstream
  • Loading branch information
Karrq committed Nov 26, 2024
1 parent ef159a7 commit faccfe9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
21 changes: 15 additions & 6 deletions crates/cli/src/utils/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,20 @@ pub fn remove_zk_contract(
output: &mut foundry_compilers::zksync::compile::output::ProjectCompileOutput,
path: &Path,
name: &str,
) -> Result<ZkContractArtifact> {
let contract = if let Some(contract) = output.remove(path, name) {
contract
} else {
) -> Result<(ZkContractArtifact, ArtifactId)> {
let mut other = Vec::new();

let Some(id) = output.artifact_ids().find_map(|(id, _)| {
if id.name == name && id.source == path {
Some(id)
} else {
other.push(id.name);
None
}
}) else {
let mut err = format!("could not find artifact: `{name}`");
if let Some(suggestion) =
super::did_you_mean(name, output.artifacts().map(|(name, _)| name)).pop()
super::did_you_mean(name, other).pop()
{
if suggestion != name {
err = format!(
Expand All @@ -99,7 +106,9 @@ pub fn remove_zk_contract(
eyre::bail!(err)
};

Ok(contract)
let contract = output.remove(id.path.as_ref(), &id.name).expect("contract found to exist in zk output");

Ok((contract, id))
}

/// Helper function for finding a contract by ContractName
Expand Down
7 changes: 5 additions & 2 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl CreateArgs {
let zk_compiler = ProjectCompiler::new().files([target_path.clone()]);
let mut zk_output = zk_compiler.zksync_compile(&zk_project)?;

let artifact = remove_zk_contract(&mut zk_output, &target_path, &self.contract.name)?;
let (artifact, id) = remove_zk_contract(&mut zk_output, &target_path, &self.contract.name)?;

let ZkContractArtifact { bytecode, hash, factory_dependencies, abi, .. } = artifact;

Expand Down Expand Up @@ -267,6 +267,7 @@ impl CreateArgs {
chain_id,
sender,
config.transaction_timeout,
id,
zk_data,
None,
)
Expand All @@ -286,6 +287,7 @@ impl CreateArgs {
chain_id,
deployer,
config.transaction_timeout,
id,
zk_data,
Some(zk_signer),
)
Expand Down Expand Up @@ -596,6 +598,7 @@ impl CreateArgs {
chain: u64,
deployer_address: Address,
timeout: u64,
id: ArtifactId,
zk_data: ZkSyncData,
zk_signer: Option<WalletSigner>,
) -> Result<()> {
Expand Down Expand Up @@ -677,7 +680,7 @@ impl CreateArgs {
constructor_args = Some(hex::encode(encoded_args));
}

self.verify_preflight_check(constructor_args.clone(), chain).await?;
self.verify_preflight_check(constructor_args.clone(), chain, &id).await?;
}

// Deploy the actual contract
Expand Down

0 comments on commit faccfe9

Please sign in to comment.