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

feat(zk_toolbox): Dev command #2347

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
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
48 changes: 32 additions & 16 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
defaults::LOCAL_RPC_URL,
messages::{
MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_DEPLOY_ERC20_PROMPT, MSG_DEPLOY_PAYMASTER_PROMPT,
MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR,
MSG_DEV_ARG_HELP, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR,
MSG_L1_RPC_URL_PROMPT,
},
};
Expand All @@ -29,15 +29,22 @@ pub struct EcosystemArgs {
}

impl EcosystemArgs {
pub fn fill_values_with_prompt(self, l1_network: L1Network) -> EcosystemArgsFinal {
pub fn fill_values_with_prompt(self, l1_network: L1Network, dev: bool) -> EcosystemArgsFinal {
let deploy_ecosystem = self.deploy_ecosystem.unwrap_or_else(|| {
PromptConfirm::new(MSG_DEPLOY_ECOSYSTEM_PROMPT)
.default(true)
.ask()
if dev {
return true;
} else {
PromptConfirm::new(MSG_DEPLOY_ECOSYSTEM_PROMPT)
.default(true)
.ask()
}
});

let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| {
let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT);
if dev {
return LOCAL_RPC_URL.to_string();
}
if l1_network == L1Network::Localhost {
prompt = prompt.default(LOCAL_RPC_URL);
}
Expand Down Expand Up @@ -81,27 +88,35 @@ pub struct EcosystemInitArgs {
#[clap(flatten, next_help_heading = MSG_GENESIS_ARGS_HELP)]
#[serde(flatten)]
pub genesis_args: GenesisArgs,
#[clap(long, help = MSG_DEV_ARG_HELP)]
pub dev: bool,
}

impl EcosystemInitArgs {
pub fn fill_values_with_prompt(self, l1_network: L1Network) -> EcosystemInitArgsFinal {
let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| {
PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT)
.default(true)
.ask()
});
let deploy_erc20 = self.deploy_erc20.unwrap_or_else(|| {
PromptConfirm::new(MSG_DEPLOY_ERC20_PROMPT)
.default(true)
.ask()
});
let ecosystem = self.ecosystem.fill_values_with_prompt(l1_network);
let (deploy_paymaster, deploy_erc20) = if self.dev {
(true, true)
} else {
let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| {
PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT)
.default(true)
.ask()
});
let deploy_erc20 = self.deploy_erc20.unwrap_or_else(|| {
PromptConfirm::new(MSG_DEPLOY_ERC20_PROMPT)
.default(true)
.ask()
});
(deploy_paymaster, deploy_erc20)
};
let ecosystem = self.ecosystem.fill_values_with_prompt(l1_network, self.dev);

EcosystemInitArgsFinal {
deploy_paymaster,
deploy_erc20,
ecosystem,
forge_args: self.forge_args.clone(),
dev: self.dev,
}
}
}
Expand All @@ -112,4 +127,5 @@ pub struct EcosystemInitArgsFinal {
pub deploy_erc20: bool,
pub ecosystem: EcosystemArgsFinal,
pub forge_args: ForgeScriptArgs,
pub dev: bool,
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> {
Err(_) => create_initial_deployments_config(shell, &ecosystem_config.config)?,
};

let genesis_args = args.genesis_args.clone();
let mut genesis_args = args.genesis_args.clone();
if args.dev {
genesis_args.use_default = true;
}
let mut final_ecosystem_args = args.fill_values_with_prompt(ecosystem_config.l1_network);

logger::info(MSG_INITIALIZING_ECOSYSTEM);
Expand Down
2 changes: 2 additions & 0 deletions zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub(super) const MSG_LINK_TO_CODE_SELECTION_PATH: &str = "I have the code alread
/// Ecosystem and chain init related messages
pub(super) const MSG_L1_RPC_URL_HELP: &str = "L1 RPC URL";
pub(super) const MSG_GENESIS_ARGS_HELP: &str = "Genesis options";
pub(super) const MSG_DEV_ARG_HELP: &str =
"Deploy ecosystem using all defaults. Suitable for local development";
pub(super) const MSG_DEPLOY_ECOSYSTEM_PROMPT: &str =
"Do you want to deploy ecosystem contracts? (Not needed if you already have an existing one)";
pub(super) const MSG_L1_RPC_URL_PROMPT: &str = "What is the RPC URL of the L1 network?";
Expand Down
Loading