From c025a75af06a53f6b72418e534eb1b983d093c89 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Thu, 21 Nov 2024 21:41:02 -0300 Subject: [PATCH 01/15] Add l1_wallets_path to ChainConfig --- zkstack_cli/crates/config/src/chain.rs | 7 +++++++ zkstack_cli/crates/config/src/ecosystem.rs | 1 + .../zkstack/src/commands/chain/args/create.rs | 17 ++++++++++++++--- .../crates/zkstack/src/commands/chain/create.rs | 6 ++++++ .../src/commands/ecosystem/args/create.rs | 5 +++-- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/zkstack_cli/crates/config/src/chain.rs b/zkstack_cli/crates/config/src/chain.rs index f4c57d67c2e1..cf396de3a977 100644 --- a/zkstack_cli/crates/config/src/chain.rs +++ b/zkstack_cli/crates/config/src/chain.rs @@ -39,6 +39,7 @@ pub struct ChainConfigInternal { pub link_to_code: Option, pub external_node_config_path: Option, pub artifacts_path: Option, + pub l1_wallets_path: Option, pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode, pub base_token: BaseToken, pub wallet_creation: WalletCreation, @@ -68,6 +69,7 @@ pub struct ChainConfig { pub shell: OnceCell, pub legacy_bridge: Option, pub evm_emulator: bool, + pub l1_wallets_path: PathBuf, } impl Serialize for ChainConfig { @@ -172,6 +174,7 @@ impl ChainConfig { wallet_creation: self.wallet_creation, legacy_bridge: self.legacy_bridge, evm_emulator: self.evm_emulator, + l1_wallets_path: Some(self.l1_wallets_path.clone()), } } @@ -186,6 +189,9 @@ impl ChainConfig { let artifacts = chain_internal .artifacts_path .context("Artifacts path not found")?; + let l1_wallets_path = chain_internal + .l1_wallets_path + .context("L1 wallets path not found")?; Ok(Self { id: chain_internal.id, @@ -204,6 +210,7 @@ impl ChainConfig { artifacts, evm_emulator: chain_internal.evm_emulator, shell: shell.into(), + l1_wallets_path, }) } } diff --git a/zkstack_cli/crates/config/src/ecosystem.rs b/zkstack_cli/crates/config/src/ecosystem.rs index 15836d748002..5841732e3eac 100644 --- a/zkstack_cli/crates/config/src/ecosystem.rs +++ b/zkstack_cli/crates/config/src/ecosystem.rs @@ -186,6 +186,7 @@ impl EcosystemConfig { .unwrap_or_else(|| self.get_chain_artifacts_path(name)), legacy_bridge: config.legacy_bridge, evm_emulator: config.evm_emulator, + l1_wallets_path: self.get_wallets_path(), }) } diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs index c6f2f8b28362..32d042932272 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs @@ -23,9 +23,10 @@ use crate::{ MSG_L1_BATCH_COMMIT_DATA_GENERATOR_MODE_PROMPT, MSG_L1_COMMIT_DATA_GENERATOR_MODE_HELP, MSG_L1_NETWORK_HELP, MSG_L1_NETWORK_PROMPT, MSG_NUMBER_VALIDATOR_GREATHER_THAN_ZERO_ERR, MSG_NUMBER_VALIDATOR_NOT_ZERO_ERR, MSG_PROVER_MODE_HELP, MSG_PROVER_VERSION_PROMPT, - MSG_SET_AS_DEFAULT_HELP, MSG_SET_AS_DEFAULT_PROMPT, MSG_WALLET_CREATION_HELP, - MSG_WALLET_CREATION_PROMPT, MSG_WALLET_CREATION_VALIDATOR_ERR, MSG_WALLET_PATH_HELP, - MSG_WALLET_PATH_INVALID_ERR, MSG_WALLET_PATH_PROMPT, + MSG_SET_AS_DEFAULT_HELP, MSG_SET_AS_DEFAULT_PROMPT, MSG_WALLETS_PATH_HELP, + MSG_WALLETS_PATH_PROMPT, MSG_WALLET_CREATION_HELP, MSG_WALLET_CREATION_PROMPT, + MSG_WALLET_CREATION_VALIDATOR_ERR, MSG_WALLET_PATH_HELP, MSG_WALLET_PATH_INVALID_ERR, + MSG_WALLET_PATH_PROMPT, }, utils::link_to_code::get_link_to_code, }; @@ -74,6 +75,8 @@ pub struct ChainCreateArgs { evm_emulator: Option, #[clap(long, help = MSG_L1_NETWORK_HELP, value_enum)] pub l1_network: Option, + #[clap(long, help = MSG_WALLETS_PATH_HELP)] + pub l1_wallets_path: Option, } impl ChainCreateArgs { @@ -88,6 +91,7 @@ impl ChainCreateArgs { link_to_code: Option, chains_path: Option, era_chain_id: L2ChainId, + l1_wallets_path: Option, ) -> anyhow::Result { let mut chain_name = self .chain_name @@ -240,6 +244,11 @@ impl ChainCreateArgs { .ask() }); + let l1_wallets_path = l1_wallets_path.unwrap_or_else(|| { + self.l1_wallets_path + .map_or_else(|| Prompt::new(MSG_WALLETS_PATH_PROMPT).ask(), PathBuf::from) + }); + let set_as_default = self.set_as_default.unwrap_or_else(|| { if number_of_chains == 0 { return true; @@ -265,6 +274,7 @@ impl ChainCreateArgs { era_chain_id, internal_id, l1_network, + l1_wallets_path, }) } } @@ -286,6 +296,7 @@ pub struct ChainCreateArgsFinal { pub era_chain_id: L2ChainId, pub internal_id: u32, pub l1_network: L1Network, + pub l1_wallets_path: PathBuf, } #[derive(Debug, Clone, EnumIter, Display, PartialEq, Eq)] diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/create.rs b/zkstack_cli/crates/zkstack/src/commands/chain/create.rs index 4ef5f8573ed1..72581f841e21 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/create.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/create.rs @@ -55,6 +55,10 @@ fn create( .as_ref() .map(|ecosystem| ecosystem.link_to_code.clone().display().to_string()); + let wallets_path = ecosystem + .as_ref() + .map(|ecosystem| ecosystem.get_wallets_path()); + let args = args .fill_values_with_prompt( shell, @@ -65,6 +69,7 @@ fn create( link_to_code, chains_path, era_chain_id, + wallets_path, ) .context(MSG_ARGS_VALIDATOR_ERR)?; @@ -132,6 +137,7 @@ pub(crate) fn create_chain_inner(args: ChainCreateArgsFinal, shell: &Shell) -> a shell: OnceCell::from(shell.clone()), legacy_bridge, evm_emulator: args.evm_emulator, + l1_wallets_path: args.l1_wallets_path, }; create_wallets( diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/create.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/create.rs index 05cfeafd4752..3e391fe614f3 100644 --- a/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/create.rs +++ b/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/create.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use clap::{Parser, ValueHint}; use common::{Prompt, PromptConfirm, PromptSelect}; -use config::get_default_era_chain_id; +use config::{get_default_era_chain_id, WALLETS_FILE}; use serde::{Deserialize, Serialize}; use slugify_rs::slugify; use strum::IntoEnumIterator; @@ -54,8 +54,8 @@ impl EcosystemCreateArgs { self.chain.set_as_default = Some(true); let chains_path = PathBuf::from("chains"); - let era_chain_id = get_default_era_chain_id(); + let l1_wallets_path = PathBuf::from("configs").join(WALLETS_FILE); let chain = self.chain.fill_values_with_prompt( shell, @@ -66,6 +66,7 @@ impl EcosystemCreateArgs { Some(link_to_code.clone()), Some(chains_path), era_chain_id, + Some(l1_wallets_path), )?; let start_containers = self.start_containers.unwrap_or_else(|| { From 9010f44443c5ce5466cf18696615f37026398268 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Thu, 21 Nov 2024 21:43:56 -0300 Subject: [PATCH 02/15] Use l1_wallets_path in chain init --- .../zkstack/src/commands/chain/args/init/mod.rs | 13 ------------- .../crates/zkstack/src/commands/chain/init/mod.rs | 2 +- .../crates/zkstack/src/commands/ecosystem/init.rs | 2 -- 3 files changed, 1 insertion(+), 16 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs index 84e7d71bc8ae..9057725c4708 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs @@ -15,7 +15,6 @@ use crate::{ MSG_DEPLOY_PAYMASTER_PROMPT, MSG_DEV_ARG_HELP, MSG_ECOSYSTEM_CONTRACTS_PATH_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, MSG_NO_PORT_REALLOCATION_HELP, MSG_SERVER_DB_NAME_HELP, MSG_SERVER_DB_URL_HELP, - MSG_WALLETS_PATH_HELP, MSG_WALLETS_PATH_PROMPT, }, }; @@ -41,8 +40,6 @@ pub struct InitArgs { pub no_port_reallocation: bool, #[clap(long, help = MSG_ECOSYSTEM_CONTRACTS_PATH_HELP)] pub ecosystem_contracts_path: Option, - #[clap(long, help = MSG_WALLETS_PATH_HELP)] - pub wallets_path: Option, #[clap(long, help = MSG_DEV_ARG_HELP)] pub dev: bool, } @@ -108,14 +105,6 @@ impl InitArgs { get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem.clone(), chain)? }; - let wallets_path = ecosystem.map_or_else( - || { - self.wallets_path - .map_or_else(|| Prompt::new(MSG_WALLETS_PATH_PROMPT).ask(), PathBuf::from) - }, - |e| e.get_wallets_path(), - ); - Ok(InitArgsFinal { forge_args: self.forge_args, genesis_args: genesis.fill_values_with_prompt(chain), @@ -123,7 +112,6 @@ impl InitArgs { l1_rpc_url, no_port_reallocation: self.no_port_reallocation, ecosystem_contracts_path, - wallets_path, dev: self.dev, }) } @@ -137,6 +125,5 @@ pub struct InitArgsFinal { pub l1_rpc_url: String, pub no_port_reallocation: bool, pub ecosystem_contracts_path: PathBuf, - pub wallets_path: PathBuf, pub dev: bool, } diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs index 9a61600b37d5..84f4058fae26 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -86,7 +86,7 @@ pub async fn init( init_configs_args.no_port_reallocation = true; } let mut contracts_config = init_configs(&init_configs_args, shell, chain_config).await?; - let wallets = WalletsConfig::read(shell, init_args.wallets_path.clone())?; + let wallets = WalletsConfig::read(shell, chain_config.l1_wallets_path.clone())?; // Fund some wallet addresses with ETH or base token (only for Localhost) distribute_eth(chain_config, init_args.l1_rpc_url.clone(), &wallets).await?; diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs index c0da87b139af..c839c18a05b9 100644 --- a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs +++ b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs @@ -350,7 +350,6 @@ async fn init_chains( } let ecosystem_contracts_path = Some(ecosystem_config.get_contracts_path().display().to_string()); - let wallets_path = Some(ecosystem_config.get_wallets_path().display().to_string()); logger::debug(format!( "Ecosystem contracts path: {:?}", ecosystem_contracts_path @@ -372,7 +371,6 @@ async fn init_chains( no_port_reallocation: final_init_args.no_port_reallocation, dev: final_init_args.dev, ecosystem_contracts_path: ecosystem_contracts_path.clone(), - wallets_path: wallets_path.clone(), }; let final_chain_init_args = chain_init_args .fill_values_with_prompt(Some(ecosystem_config.clone()), &chain_config)?; From 700f63b81f2297b9e40587b41a6bfe4e85d5e638 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Thu, 21 Nov 2024 22:19:49 -0300 Subject: [PATCH 03/15] Make deploy_l2_contracts independent from Ecosystem --- .../src/commands/chain/deploy_l2_contracts.rs | 83 +++++-------------- 1 file changed, 21 insertions(+), 62 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs b/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs index 01536afeaf1f..aa8367758929 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs @@ -17,6 +17,7 @@ use config::{ }, script_params::DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS, }, + get_default_era_chain_id, traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, zkstack_config::ZkStackConfig, ChainConfig, ContractsConfig, WalletsConfig, @@ -46,87 +47,45 @@ pub async fn run( shell: &Shell, deploy_option: Deploy2ContractsOption, ) -> anyhow::Result<()> { - let ecosystem_config = ZkStackConfig::ecosystem(shell)?; - let chain_config = ecosystem_config - .load_current_chain() - .context(MSG_CHAIN_NOT_INITIALIZED)?; + let chain = ZkStackConfig::current_chain(shell).context(MSG_CHAIN_NOT_INITIALIZED)?; + let ecosystem = ZkStackConfig::ecosystem(shell).ok(); - let mut contracts = chain_config.get_contracts_config()?; - let era_chain_id = ecosystem_config.era_chain_id; - let wallets = ecosystem_config.get_wallets()?; + let mut contracts = chain.get_contracts_config()?; + let era_chain_id = ecosystem + .as_ref() + .map_or(get_default_era_chain_id(), |e| e.era_chain_id); + let wallets = ecosystem.as_ref().map_or( + WalletsConfig::read(shell, chain.l1_wallets_path.clone()), + |e| e.get_wallets(), + )?; let spinner = Spinner::new(MSG_DEPLOYING_L2_CONTRACT_SPINNER); match deploy_option { Deploy2ContractsOption::All => { - deploy_l2_contracts( - shell, - &chain_config, - era_chain_id, - &wallets, - &mut contracts, - args, - ) - .await?; + deploy_l2_contracts(shell, &chain, era_chain_id, &wallets, &mut contracts, args) + .await?; } Deploy2ContractsOption::Upgrader => { - deploy_upgrader( - shell, - &chain_config, - era_chain_id, - &wallets, - &mut contracts, - args, - ) - .await?; + deploy_upgrader(shell, &chain, era_chain_id, &wallets, &mut contracts, args).await?; } Deploy2ContractsOption::ConsensusRegistry => { - deploy_consensus_registry( - shell, - &chain_config, - era_chain_id, - &wallets, - &mut contracts, - args, - ) - .await?; + deploy_consensus_registry(shell, &chain, era_chain_id, &wallets, &mut contracts, args) + .await?; } Deploy2ContractsOption::Multicall3 => { - deploy_multicall3( - shell, - &chain_config, - era_chain_id, - &wallets, - &mut contracts, - args, - ) - .await?; + deploy_multicall3(shell, &chain, era_chain_id, &wallets, &mut contracts, args).await?; } Deploy2ContractsOption::TimestampAsserter => { - deploy_timestamp_asserter( - shell, - &chain_config, - era_chain_id, - &wallets, - &mut contracts, - args, - ) - .await?; + deploy_timestamp_asserter(shell, &chain, era_chain_id, &wallets, &mut contracts, args) + .await?; } Deploy2ContractsOption::InitiailizeBridges => { - initialize_bridges( - shell, - &chain_config, - era_chain_id, - &wallets, - &mut contracts, - args, - ) - .await? + initialize_bridges(shell, &chain, era_chain_id, &wallets, &mut contracts, args).await? } } - contracts.save_with_base_path(shell, &chain_config.configs)?; + contracts.save_with_base_path(shell, &chain.configs)?; spinner.finish(); Ok(()) From ec0b53f34b3ed9f95df091f2ba6646b8581427ed Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Thu, 21 Nov 2024 22:20:54 -0300 Subject: [PATCH 04/15] lint --- .../crates/zkstack/completion/_zkstack.zsh | 3 ++- .../crates/zkstack/completion/zkstack.fish | 3 ++- .../crates/zkstack/completion/zkstack.sh | 18 +++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/zkstack_cli/crates/zkstack/completion/_zkstack.zsh b/zkstack_cli/crates/zkstack/completion/_zkstack.zsh index 9a45735aa25e..a92b35f9971a 100644 --- a/zkstack_cli/crates/zkstack/completion/_zkstack.zsh +++ b/zkstack_cli/crates/zkstack/completion/_zkstack.zsh @@ -83,6 +83,7 @@ in-file\:"Specify file with wallets"))' \ '--set-as-default=[Set as default chain]' \ '--evm-emulator=[Enable EVM emulator]' \ '--l1-network=[L1 Network]:L1_NETWORK:(localhost sepolia holesky mainnet)' \ +'--l1-wallets-path=[Wallets path]:L1_WALLETS_PATH:_default' \ '--start-containers=[Start reth and postgres containers after creation]' \ '--chain=[Chain to use]:CHAIN:_default' \ '--legacy-bridge[]' \ @@ -245,6 +246,7 @@ in-file\:"Specify file with wallets"))' \ '--set-as-default=[Set as default chain]' \ '--evm-emulator=[Enable EVM emulator]' \ '--l1-network=[L1 Network]:L1_NETWORK:(localhost sepolia holesky mainnet)' \ +'--l1-wallets-path=[Wallets path]:L1_WALLETS_PATH:_default' \ '--chain=[Chain to use]:CHAIN:_default' \ '--legacy-bridge[]' \ '-v[Verbose mode]' \ @@ -287,7 +289,6 @@ _arguments "${_arguments_options[@]}" : \ '--deploy-paymaster=[]' \ '--l1-rpc-url=[L1 RPC URL]:L1_RPC_URL:_default' \ '--ecosystem-contracts-path=[Ecosystem contracts path]:ECOSYSTEM_CONTRACTS_PATH:_default' \ -'--wallets-path=[Wallets path]:WALLETS_PATH:_default' \ '--chain=[Chain to use]:CHAIN:_default' \ '--resume[]' \ '-d[]' \ diff --git a/zkstack_cli/crates/zkstack/completion/zkstack.fish b/zkstack_cli/crates/zkstack/completion/zkstack.fish index 20ea0c60c834..1322551596e8 100644 --- a/zkstack_cli/crates/zkstack/completion/zkstack.fish +++ b/zkstack_cli/crates/zkstack/completion/zkstack.fish @@ -72,6 +72,7 @@ complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_se complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l set-as-default -d 'Set as default chain' -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l evm-emulator -d 'Enable EVM emulator' -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l l1-network -d 'L1 Network' -r -f -a "{localhost\t'',sepolia\t'',holesky\t'',mainnet\t''}" +complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l l1-wallets-path -d 'Wallets path' -r complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l start-containers -d 'Start reth and postgres containers after creation' -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l chain -d 'Chain to use' -r complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l legacy-bridge @@ -161,6 +162,7 @@ complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_s complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l set-as-default -d 'Set as default chain' -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l evm-emulator -d 'Enable EVM emulator' -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l l1-network -d 'L1 Network' -r -f -a "{localhost\t'',sepolia\t'',holesky\t'',mainnet\t''}" +complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l l1-wallets-path -d 'Wallets path' -r complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l chain -d 'Chain to use' -r complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l legacy-bridge complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -s v -l verbose -d 'Verbose mode' @@ -188,7 +190,6 @@ complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_s complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l deploy-paymaster -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l l1-rpc-url -d 'L1 RPC URL' -r complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l ecosystem-contracts-path -d 'Ecosystem contracts path' -r -complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l wallets-path -d 'Wallets path' -r complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l chain -d 'Chain to use' -r complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l resume complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -s d -l dont-drop diff --git a/zkstack_cli/crates/zkstack/completion/zkstack.sh b/zkstack_cli/crates/zkstack/completion/zkstack.sh index 5dd12b32ee1b..8501bbcd6b28 100644 --- a/zkstack_cli/crates/zkstack/completion/zkstack.sh +++ b/zkstack_cli/crates/zkstack/completion/zkstack.sh @@ -1652,7 +1652,7 @@ _zkstack() { return 0 ;; zkstack__chain__create) - opts="-v -h --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --l1-network --verbose --chain --ignore-prerequisites --help" + opts="-v -h --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --l1-network --l1-wallets-path --verbose --chain --ignore-prerequisites --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -1717,6 +1717,10 @@ _zkstack() { COMPREPLY=($(compgen -W "localhost sepolia holesky mainnet" -- "${cur}")) return 0 ;; + --l1-wallets-path) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; --chain) COMPREPLY=($(compgen -f "${cur}")) return 0 @@ -2555,7 +2559,7 @@ _zkstack() { return 0 ;; zkstack__chain__init) - opts="-a -d -v -h --verify --verifier --verifier-url --verifier-api-key --resume --additional-args --server-db-url --server-db-name --dont-drop --deploy-paymaster --l1-rpc-url --no-port-reallocation --ecosystem-contracts-path --wallets-path --dev --verbose --chain --ignore-prerequisites --help configs help" + opts="-a -d -v -h --verify --verifier --verifier-url --verifier-api-key --resume --additional-args --server-db-url --server-db-name --dont-drop --deploy-paymaster --l1-rpc-url --no-port-reallocation --ecosystem-contracts-path --dev --verbose --chain --ignore-prerequisites --help configs help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -2605,10 +2609,6 @@ _zkstack() { COMPREPLY=($(compgen -f "${cur}")) return 0 ;; - --wallets-path) - COMPREPLY=($(compgen -f "${cur}")) - return 0 - ;; --chain) COMPREPLY=($(compgen -f "${cur}")) return 0 @@ -5321,7 +5321,7 @@ _zkstack() { return 0 ;; zkstack__ecosystem__create) - opts="-v -h --ecosystem-name --l1-network --link-to-code --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --l1-network --start-containers --verbose --chain --ignore-prerequisites --help" + opts="-v -h --ecosystem-name --l1-network --link-to-code --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --l1-network --l1-wallets-path --start-containers --verbose --chain --ignore-prerequisites --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -5401,6 +5401,10 @@ _zkstack() { COMPREPLY=($(compgen -W "localhost sepolia holesky mainnet" -- "${cur}")) return 0 ;; + --l1-wallets-path) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; --start-containers) COMPREPLY=($(compgen -W "true false" -- "${cur}")) return 0 From b77c2cf2d6a2b2840360201573a850662d2b6756 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 22 Nov 2024 08:33:27 -0300 Subject: [PATCH 05/15] Pre load chain and ecosystem --- .../src/commands/chain/deploy_l2_contracts.rs | 13 ++--- .../crates/zkstack/src/commands/chain/mod.rs | 49 ++++++++++++++++--- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs b/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs index aa8367758929..71e81664a678 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs @@ -19,17 +19,13 @@ use config::{ }, get_default_era_chain_id, traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, - zkstack_config::ZkStackConfig, - ChainConfig, ContractsConfig, WalletsConfig, + ChainConfig, ContractsConfig, EcosystemConfig, WalletsConfig, }; use xshell::Shell; use zksync_basic_types::L2ChainId; use crate::{ - messages::{ - MSG_CHAIN_NOT_INITIALIZED, MSG_DEPLOYING_L2_CONTRACT_SPINNER, - MSG_L1_SECRETS_MUST_BE_PRESENTED, - }, + messages::{MSG_DEPLOYING_L2_CONTRACT_SPINNER, MSG_L1_SECRETS_MUST_BE_PRESENTED}, utils::forge::{check_the_balance, fill_forge_private_key}, }; @@ -46,10 +42,9 @@ pub async fn run( args: ForgeScriptArgs, shell: &Shell, deploy_option: Deploy2ContractsOption, + chain: ChainConfig, + ecosystem: Option, ) -> anyhow::Result<()> { - let chain = ZkStackConfig::current_chain(shell).context(MSG_CHAIN_NOT_INITIALIZED)?; - let ecosystem = ZkStackConfig::ecosystem(shell).ok(); - let mut contracts = chain.get_contracts_config()?; let era_chain_id = ecosystem .as_ref() diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs index 5d0c39851baf..5865e79eee34 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs @@ -91,6 +91,7 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> } let chain = ZkStackConfig::current_chain(shell).context(MSG_CHAIN_NOT_FOUND_ERR)?; + let ecosystem = ZkStackConfig::ecosystem(shell).ok(); match cmd { ChainCommands::Create(args) => create::run(args, shell), @@ -99,23 +100,59 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> ChainCommands::Genesis(args) => genesis::run(args, shell, chain).await, ChainCommands::RegisterChain(args) => register_chain::run(args, shell).await, ChainCommands::DeployL2Contracts(args) => { - deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::All).await + deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::All, chain, ecosystem) + .await } ChainCommands::AcceptChainOwnership(args) => accept_chain_ownership::run(args, shell).await, ChainCommands::DeployConsensusRegistry(args) => { - deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::ConsensusRegistry).await + deploy_l2_contracts::run( + args, + shell, + Deploy2ContractsOption::ConsensusRegistry, + chain, + ecosystem, + ) + .await } ChainCommands::DeployMulticall3(args) => { - deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::Multicall3).await + deploy_l2_contracts::run( + args, + shell, + Deploy2ContractsOption::Multicall3, + chain, + ecosystem, + ) + .await } ChainCommands::DeployTimestampAsserter(args) => { - deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::TimestampAsserter).await + deploy_l2_contracts::run( + args, + shell, + Deploy2ContractsOption::TimestampAsserter, + chain, + ecosystem, + ) + .await } ChainCommands::DeployUpgrader(args) => { - deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::Upgrader).await + deploy_l2_contracts::run( + args, + shell, + Deploy2ContractsOption::Upgrader, + chain, + ecosystem, + ) + .await } ChainCommands::InitializeBridges(args) => { - deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::InitiailizeBridges).await + deploy_l2_contracts::run( + args, + shell, + Deploy2ContractsOption::InitiailizeBridges, + chain, + ecosystem, + ) + .await } ChainCommands::DeployPaymaster(args) => deploy_paymaster::run(args, shell, chain).await, ChainCommands::UpdateTokenMultiplierSetter(args) => { From 14565024d8a7fd0c74b83cd2720853655cb9a107 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 22 Nov 2024 08:36:03 -0300 Subject: [PATCH 06/15] Preload chain for accept_chain_ownership --- .../commands/chain/accept_chain_ownership.rs | 18 +++++++----------- .../crates/zkstack/src/commands/chain/mod.rs | 4 +++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/accept_chain_ownership.rs b/zkstack_cli/crates/zkstack/src/commands/chain/accept_chain_ownership.rs index d107ccd75dd7..b98d81581272 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/accept_chain_ownership.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/accept_chain_ownership.rs @@ -1,23 +1,19 @@ use anyhow::Context; use common::{forge::ForgeScriptArgs, logger, spinner::Spinner}; -use config::zkstack_config::ZkStackConfig; +use config::ChainConfig; use xshell::Shell; use crate::{ accept_ownership::accept_admin, messages::{ - MSG_ACCEPTING_ADMIN_SPINNER, MSG_CHAIN_NOT_INITIALIZED, MSG_CHAIN_OWNERSHIP_TRANSFERRED, + MSG_ACCEPTING_ADMIN_SPINNER, MSG_CHAIN_OWNERSHIP_TRANSFERRED, MSG_L1_SECRETS_MUST_BE_PRESENTED, }, }; -pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { - let ecosystem_config = ZkStackConfig::ecosystem(shell)?; - let chain_config = ecosystem_config - .load_current_chain() - .context(MSG_CHAIN_NOT_INITIALIZED)?; - let contracts = chain_config.get_contracts_config()?; - let secrets = chain_config.get_secrets_config()?; +pub async fn run(args: ForgeScriptArgs, shell: &Shell, chain: ChainConfig) -> anyhow::Result<()> { + let contracts = chain.get_contracts_config()?; + let secrets = chain.get_secrets_config()?; let l1_rpc_url = secrets .l1 .context(MSG_L1_SECRETS_MUST_BE_PRESENTED)? @@ -28,9 +24,9 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { let spinner = Spinner::new(MSG_ACCEPTING_ADMIN_SPINNER); accept_admin( shell, - &chain_config.path_to_foundry(), + &chain.path_to_foundry(), contracts.l1.chain_admin_addr, - &chain_config.get_wallets_config()?.governor, + &chain.get_wallets_config()?.governor, contracts.l1.diamond_proxy_addr, &args, l1_rpc_url.clone(), diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs index 5865e79eee34..4344c41f6c9d 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs @@ -103,7 +103,9 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::All, chain, ecosystem) .await } - ChainCommands::AcceptChainOwnership(args) => accept_chain_ownership::run(args, shell).await, + ChainCommands::AcceptChainOwnership(args) => { + accept_chain_ownership::run(args, shell, chain).await + } ChainCommands::DeployConsensusRegistry(args) => { deploy_l2_contracts::run( args, From 93fab5f5d5cc0772607e58ad790f0e9ded27749a Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 22 Nov 2024 08:42:57 -0300 Subject: [PATCH 07/15] Preload chain and ecosystem configs for chain init --- .../src/commands/chain/init/configs.rs | 19 +++++----- .../zkstack/src/commands/chain/init/mod.rs | 38 +++++++++++-------- .../crates/zkstack/src/commands/chain/mod.rs | 2 +- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs index 9595e91c7e3e..baa05fdd86fd 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs @@ -3,9 +3,7 @@ use common::logger; use config::{ copy_configs, set_l1_rpc_url, traits::{ReadConfig, SaveConfigWithBasePath}, - update_from_chain_config, - zkstack_config::ZkStackConfig, - ChainConfig, ContractsConfig, + update_from_chain_config, ChainConfig, ContractsConfig, EcosystemConfig, }; use ethers::types::Address; use xshell::Shell; @@ -19,7 +17,7 @@ use crate::{ portal::update_portal_config, }, messages::{ - MSG_CHAIN_CONFIGS_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, MSG_CONSENSUS_CONFIG_MISSING_ERR, + MSG_CHAIN_CONFIGS_INITIALIZED, MSG_CONSENSUS_CONFIG_MISSING_ERR, MSG_PORTAL_FAILED_TO_CREATE_CONFIG_ERR, }, utils::{ @@ -28,12 +26,15 @@ use crate::{ }, }; -pub async fn run(args: InitConfigsArgs, shell: &Shell) -> anyhow::Result<()> { - let ecosystem_config = ZkStackConfig::ecosystem(shell)?; - let chain_config = ZkStackConfig::current_chain(shell).context(MSG_CHAIN_NOT_FOUND_ERR)?; - let args = args.fill_values_with_prompt(Some(ecosystem_config), &chain_config)?; +pub async fn run( + args: InitConfigsArgs, + shell: &Shell, + chain: ChainConfig, + ecosystem: Option, +) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt(ecosystem, &chain)?; - init_configs(&args, shell, &chain_config).await?; + init_configs(&args, shell, &chain).await?; logger::outro(MSG_CHAIN_CONFIGS_INITIALIZED); Ok(()) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs index 84f4058fae26..fb68a3485841 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -4,7 +4,6 @@ use common::{git, logger, spinner::Spinner}; use config::{ get_default_era_chain_id, traits::{ReadConfig, SaveConfigWithBasePath}, - zkstack_config::ZkStackConfig, ChainConfig, EcosystemConfig, WalletsConfig, }; use types::BaseToken; @@ -27,10 +26,9 @@ use crate::{ }, messages::{ msg_initializing_chain, MSG_ACCEPTING_ADMIN_SPINNER, MSG_CHAIN_INITIALIZED, - MSG_CHAIN_NOT_FOUND_ERR, MSG_DEPLOYING_PAYMASTER, MSG_GENESIS_DATABASE_ERR, - MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG, - MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER, MSG_WALLETS_CONFIG_MUST_BE_PRESENT, - MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND, + MSG_DEPLOYING_PAYMASTER, MSG_GENESIS_DATABASE_ERR, MSG_REGISTERING_CHAIN_SPINNER, + MSG_SELECTED_CONFIG, MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER, + MSG_WALLETS_CONFIG_MUST_BE_PRESENT, MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND, }, }; @@ -52,23 +50,33 @@ pub struct ChainInitCommand { args: InitArgs, } -pub(crate) async fn run(args: ChainInitCommand, shell: &Shell) -> anyhow::Result<()> { +pub(crate) async fn run( + args: ChainInitCommand, + shell: &Shell, + chain: ChainConfig, + ecosystem: Option, +) -> anyhow::Result<()> { match args.command { - Some(ChainInitSubcommands::Configs(args)) => configs::run(args, shell).await, - None => run_init(args.args, shell).await, + Some(ChainInitSubcommands::Configs(args)) => { + configs::run(args, shell, chain, ecosystem).await + } + None => run_init(args.args, shell, chain, ecosystem).await, } } -async fn run_init(args: InitArgs, shell: &Shell) -> anyhow::Result<()> { - let ecosystem = ZkStackConfig::ecosystem(shell).ok(); - let chain_config = ZkStackConfig::current_chain(shell).context(MSG_CHAIN_NOT_FOUND_ERR)?; - let args = args.fill_values_with_prompt(ecosystem.clone(), &chain_config)?; +async fn run_init( + args: InitArgs, + shell: &Shell, + chain: ChainConfig, + ecosystem: Option, +) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt(ecosystem.clone(), &chain)?; - logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); + logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain)); logger::info(msg_initializing_chain("")); - git::submodule_update(shell, chain_config.link_to_code.clone())?; + git::submodule_update(shell, chain.link_to_code.clone())?; - init(&args, shell, ecosystem, &chain_config).await?; + init(&args, shell, ecosystem, &chain).await?; logger::success(MSG_CHAIN_INITIALIZED); Ok(()) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs index 4344c41f6c9d..eb32b9e11947 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs @@ -95,7 +95,7 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> match cmd { ChainCommands::Create(args) => create::run(args, shell), - ChainCommands::Init(args) => init::run(*args, shell).await, + ChainCommands::Init(args) => init::run(*args, shell, chain, ecosystem).await, ChainCommands::BuildTransactions(args) => build_transactions::run(args, shell).await, ChainCommands::Genesis(args) => genesis::run(args, shell, chain).await, ChainCommands::RegisterChain(args) => register_chain::run(args, shell).await, From 82b028ceb144ffc5b177a3ebcfde28291a166287 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 22 Nov 2024 08:46:16 -0300 Subject: [PATCH 08/15] Preload chain and ecosystem config for build_transactions --- .../src/commands/chain/build_transactions.rs | 46 ++++++++++--------- .../crates/zkstack/src/commands/chain/mod.rs | 4 +- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/build_transactions.rs b/zkstack_cli/crates/zkstack/src/commands/chain/build_transactions.rs index 313b3a509050..f40472e4b8b1 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/build_transactions.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/build_transactions.rs @@ -1,8 +1,8 @@ use anyhow::Context; use common::{git, logger, spinner::Spinner}; use config::{ - copy_configs, traits::SaveConfigWithBasePath, update_from_chain_config, - zkstack_config::ZkStackConfig, + copy_configs, traits::SaveConfigWithBasePath, update_from_chain_config, ChainConfig, + EcosystemConfig, }; use ethers::utils::hex::ToHex; use xshell::Shell; @@ -12,9 +12,9 @@ use crate::{ args::build_transactions::BuildTransactionsArgs, register_chain::register_chain, }, messages::{ - MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_NOT_FOUND_ERR, - MSG_CHAIN_TRANSACTIONS_BUILT, MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG, - MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR, MSG_PREPARING_CONFIG_SPINNER, MSG_SELECTED_CONFIG, + MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_TRANSACTIONS_BUILT, + MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG, MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR, + MSG_ECOSYSTEM_CONFIG_INVALID_ERR, MSG_PREPARING_CONFIG_SPINNER, MSG_SELECTED_CONFIG, MSG_WRITING_OUTPUT_FILES_SPINNER, }, }; @@ -27,39 +27,41 @@ const SCRIPT_CONFIG_FILE_SRC: &str = "contracts/l1-contracts/script-config/register-hyperchain.toml"; const SCRIPT_CONFIG_FILE_DST: &str = "register-hyperchain.toml"; -pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::Result<()> { - let config = ZkStackConfig::ecosystem(shell)?; - let chain_config = config - .load_current_chain() - .context(MSG_CHAIN_NOT_FOUND_ERR)?; +pub(crate) async fn run( + args: BuildTransactionsArgs, + shell: &Shell, + chain: ChainConfig, + ecosystem: Option, +) -> anyhow::Result<()> { + let ecosystem = ecosystem.context(MSG_ECOSYSTEM_CONFIG_INVALID_ERR)?; - let args = args.fill_values_with_prompt(config.default_chain.clone()); + let args = args.fill_values_with_prompt(ecosystem.default_chain.clone()); - git::submodule_update(shell, config.link_to_code.clone())?; + git::submodule_update(shell, ecosystem.link_to_code.clone())?; let spinner = Spinner::new(MSG_PREPARING_CONFIG_SPINNER); - copy_configs(shell, &config.link_to_code, &chain_config.configs)?; + copy_configs(shell, &ecosystem.link_to_code, &chain.configs)?; - logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); + logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain)); - let mut genesis_config = chain_config.get_genesis_config()?; - update_from_chain_config(&mut genesis_config, &chain_config)?; + let mut genesis_config = chain.get_genesis_config()?; + update_from_chain_config(&mut genesis_config, &chain)?; // Copy ecosystem contracts - let mut contracts_config = config + let mut contracts_config = ecosystem .get_contracts_config() .context(MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG)?; - contracts_config.l1.base_token_addr = chain_config.base_token.address; + contracts_config.l1.base_token_addr = chain.base_token.address; spinner.finish(); let spinner = Spinner::new(MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER); - let wallets = config.get_wallets()?; + let wallets = ecosystem.get_wallets()?; let governor: String = wallets.governor.address.encode_hex_upper(); register_chain( shell, args.forge_args.clone(), - &chain_config, + &chain, &mut contracts_config, &wallets, args.l1_rpc_url.clone(), @@ -77,12 +79,12 @@ pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::R .context(MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR)?; shell.copy_file( - config.link_to_code.join(REGISTER_CHAIN_TXNS_FILE_SRC), + ecosystem.link_to_code.join(REGISTER_CHAIN_TXNS_FILE_SRC), args.out.join(REGISTER_CHAIN_TXNS_FILE_DST), )?; shell.copy_file( - config.link_to_code.join(SCRIPT_CONFIG_FILE_SRC), + ecosystem.link_to_code.join(SCRIPT_CONFIG_FILE_SRC), args.out.join(SCRIPT_CONFIG_FILE_DST), )?; spinner.finish(); diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs index eb32b9e11947..697368ecec1e 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs @@ -96,7 +96,9 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> match cmd { ChainCommands::Create(args) => create::run(args, shell), ChainCommands::Init(args) => init::run(*args, shell, chain, ecosystem).await, - ChainCommands::BuildTransactions(args) => build_transactions::run(args, shell).await, + ChainCommands::BuildTransactions(args) => { + build_transactions::run(args, shell, chain, ecosystem).await + } ChainCommands::Genesis(args) => genesis::run(args, shell, chain).await, ChainCommands::RegisterChain(args) => register_chain::run(args, shell).await, ChainCommands::DeployL2Contracts(args) => { From 4cb7a607f5d5aa2bf25d8a849d0084c86471dc7c Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 22 Nov 2024 08:52:45 -0300 Subject: [PATCH 09/15] Preload chain config for set_token_multiplier_setter --- .../crates/zkstack/src/commands/chain/mod.rs | 2 +- .../chain/set_token_multiplier_setter.rs | 26 +++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs index 697368ecec1e..439d755a2f82 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs @@ -160,7 +160,7 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> } ChainCommands::DeployPaymaster(args) => deploy_paymaster::run(args, shell, chain).await, ChainCommands::UpdateTokenMultiplierSetter(args) => { - set_token_multiplier_setter::run(args, shell).await + set_token_multiplier_setter::run(args, shell, chain).await } ChainCommands::Server(args) => server::run(shell, args, chain).await, ChainCommands::ContractVerifier(args) => contract_verifier::run(shell, args, chain).await, diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/set_token_multiplier_setter.rs b/zkstack_cli/crates/zkstack/src/commands/chain/set_token_multiplier_setter.rs index 644d33e41805..aa52d3e86be1 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/set_token_multiplier_setter.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/set_token_multiplier_setter.rs @@ -7,9 +7,7 @@ use common::{ spinner::Spinner, wallets::Wallet, }; -use config::{ - forge_interface::script_params::ACCEPT_GOVERNANCE_SCRIPT_PARAMS, zkstack_config::ZkStackConfig, -}; +use config::{forge_interface::script_params::ACCEPT_GOVERNANCE_SCRIPT_PARAMS, ChainConfig}; use ethers::{abi::parse_abi, contract::BaseContract, utils::hex}; use lazy_static::lazy_static; use xshell::Shell; @@ -17,9 +15,9 @@ use zksync_basic_types::Address; use crate::{ messages::{ - MSG_CHAIN_NOT_INITIALIZED, MSG_L1_SECRETS_MUST_BE_PRESENTED, - MSG_TOKEN_MULTIPLIER_SETTER_UPDATED_TO, MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER, - MSG_WALLETS_CONFIG_MUST_BE_PRESENT, MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND, + MSG_L1_SECRETS_MUST_BE_PRESENTED, MSG_TOKEN_MULTIPLIER_SETTER_UPDATED_TO, + MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER, MSG_WALLETS_CONFIG_MUST_BE_PRESENT, + MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND, }, utils::forge::{check_the_balance, fill_forge_private_key}, }; @@ -33,20 +31,16 @@ lazy_static! { ); } -pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { - let ecosystem_config = ZkStackConfig::ecosystem(shell)?; - let chain_config = ecosystem_config - .load_current_chain() - .context(MSG_CHAIN_NOT_INITIALIZED)?; - let contracts_config = chain_config.get_contracts_config()?; - let l1_url = chain_config +pub async fn run(args: ForgeScriptArgs, shell: &Shell, chain: ChainConfig) -> anyhow::Result<()> { + let contracts_config = chain.get_contracts_config()?; + let l1_url = chain .get_secrets_config()? .l1 .context(MSG_L1_SECRETS_MUST_BE_PRESENTED)? .l1_rpc_url .expose_str() .to_string(); - let token_multiplier_setter_address = chain_config + let token_multiplier_setter_address = chain .get_wallets_config() .context(MSG_WALLETS_CONFIG_MUST_BE_PRESENT)? .token_multiplier_setter @@ -56,8 +50,8 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { let spinner = Spinner::new(MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER); set_token_multiplier_setter( shell, - &chain_config.path_to_foundry(), - &chain_config.get_wallets_config()?.governor, + &chain.path_to_foundry(), + &chain.get_wallets_config()?.governor, contracts_config.l1.chain_admin_addr, token_multiplier_setter_address, &args.clone(), From 30181f30cbf67da643de21bb2e205d722475e43a Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 22 Nov 2024 13:11:45 -0300 Subject: [PATCH 10/15] Make chain create unreachable --- zkstack_cli/crates/zkstack/src/commands/chain/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs index 439d755a2f82..d744c76b3b73 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs @@ -94,7 +94,6 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> let ecosystem = ZkStackConfig::ecosystem(shell).ok(); match cmd { - ChainCommands::Create(args) => create::run(args, shell), ChainCommands::Init(args) => init::run(*args, shell, chain, ecosystem).await, ChainCommands::BuildTransactions(args) => { build_transactions::run(args, shell, chain, ecosystem).await @@ -165,5 +164,6 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> ChainCommands::Server(args) => server::run(shell, args, chain).await, ChainCommands::ContractVerifier(args) => contract_verifier::run(shell, args, chain).await, ChainCommands::Consensus(cmd) => cmd.run(shell).await, + ChainCommands::Create(_) => unreachable!("Chain create is handled before loading chain"), } } From b604f5307bfd4c1f9d3084abc627aff66a15872d Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 25 Nov 2024 10:27:54 -0300 Subject: [PATCH 11/15] Revert "Make deploy_l2_contracts independent from Ecosystem" This reverts commit 700f63b81f2297b9e40587b41a6bfe4e85d5e638. --- .../src/commands/chain/deploy_l2_contracts.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs b/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs index 71e81664a678..e483511b89ef 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs @@ -17,7 +17,6 @@ use config::{ }, script_params::DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS, }, - get_default_era_chain_id, traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, ChainConfig, ContractsConfig, EcosystemConfig, WalletsConfig, }; @@ -43,16 +42,11 @@ pub async fn run( shell: &Shell, deploy_option: Deploy2ContractsOption, chain: ChainConfig, - ecosystem: Option, + ecosystem: EcosystemConfig, ) -> anyhow::Result<()> { let mut contracts = chain.get_contracts_config()?; - let era_chain_id = ecosystem - .as_ref() - .map_or(get_default_era_chain_id(), |e| e.era_chain_id); - let wallets = ecosystem.as_ref().map_or( - WalletsConfig::read(shell, chain.l1_wallets_path.clone()), - |e| e.get_wallets(), - )?; + let era_chain_id = ecosystem.era_chain_id; + let wallets = ecosystem.get_wallets()?; let spinner = Spinner::new(MSG_DEPLOYING_L2_CONTRACT_SPINNER); From 618c41f03dba1d3f1aaf2b4d72bddd6a823913f8 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 25 Nov 2024 10:30:34 -0300 Subject: [PATCH 12/15] fix chain:run --- .../crates/zkstack/src/commands/chain/mod.rs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs index d744c76b3b73..0260cc630713 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs @@ -14,7 +14,7 @@ use crate::{ args::create::ChainCreateArgs, deploy_l2_contracts::Deploy2ContractsOption, genesis::GenesisCommand, init::ChainInitCommand, }, - messages::MSG_CHAIN_NOT_FOUND_ERR, + messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_ECOSYSTEM_CONFIG_INVALID_ERR}, }; mod accept_chain_ownership; @@ -101,8 +101,14 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> ChainCommands::Genesis(args) => genesis::run(args, shell, chain).await, ChainCommands::RegisterChain(args) => register_chain::run(args, shell).await, ChainCommands::DeployL2Contracts(args) => { - deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::All, chain, ecosystem) - .await + deploy_l2_contracts::run( + args, + shell, + Deploy2ContractsOption::All, + chain, + ecosystem.context(MSG_ECOSYSTEM_CONFIG_INVALID_ERR)?, + ) + .await } ChainCommands::AcceptChainOwnership(args) => { accept_chain_ownership::run(args, shell, chain).await @@ -113,7 +119,7 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> shell, Deploy2ContractsOption::ConsensusRegistry, chain, - ecosystem, + ecosystem.context(MSG_ECOSYSTEM_CONFIG_INVALID_ERR)?, ) .await } @@ -123,7 +129,7 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> shell, Deploy2ContractsOption::Multicall3, chain, - ecosystem, + ecosystem.context(MSG_ECOSYSTEM_CONFIG_INVALID_ERR)?, ) .await } @@ -133,7 +139,7 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> shell, Deploy2ContractsOption::TimestampAsserter, chain, - ecosystem, + ecosystem.context(MSG_ECOSYSTEM_CONFIG_INVALID_ERR)?, ) .await } @@ -143,7 +149,7 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> shell, Deploy2ContractsOption::Upgrader, chain, - ecosystem, + ecosystem.context(MSG_ECOSYSTEM_CONFIG_INVALID_ERR)?, ) .await } @@ -153,7 +159,7 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()> shell, Deploy2ContractsOption::InitiailizeBridges, chain, - ecosystem, + ecosystem.context(MSG_ECOSYSTEM_CONFIG_INVALID_ERR)?, ) .await } From 5f321450978ea6cb765a7d61f4872b5c7b7885bb Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 25 Nov 2024 10:31:13 -0300 Subject: [PATCH 13/15] Revert "Use l1_wallets_path in chain init" This reverts commit 9010f44443c5ce5466cf18696615f37026398268. --- .../zkstack/src/commands/chain/args/init/mod.rs | 13 +++++++++++++ .../crates/zkstack/src/commands/chain/init/mod.rs | 2 +- .../crates/zkstack/src/commands/ecosystem/init.rs | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs index 9057725c4708..84e7d71bc8ae 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs @@ -15,6 +15,7 @@ use crate::{ MSG_DEPLOY_PAYMASTER_PROMPT, MSG_DEV_ARG_HELP, MSG_ECOSYSTEM_CONTRACTS_PATH_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, MSG_NO_PORT_REALLOCATION_HELP, MSG_SERVER_DB_NAME_HELP, MSG_SERVER_DB_URL_HELP, + MSG_WALLETS_PATH_HELP, MSG_WALLETS_PATH_PROMPT, }, }; @@ -40,6 +41,8 @@ pub struct InitArgs { pub no_port_reallocation: bool, #[clap(long, help = MSG_ECOSYSTEM_CONTRACTS_PATH_HELP)] pub ecosystem_contracts_path: Option, + #[clap(long, help = MSG_WALLETS_PATH_HELP)] + pub wallets_path: Option, #[clap(long, help = MSG_DEV_ARG_HELP)] pub dev: bool, } @@ -105,6 +108,14 @@ impl InitArgs { get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem.clone(), chain)? }; + let wallets_path = ecosystem.map_or_else( + || { + self.wallets_path + .map_or_else(|| Prompt::new(MSG_WALLETS_PATH_PROMPT).ask(), PathBuf::from) + }, + |e| e.get_wallets_path(), + ); + Ok(InitArgsFinal { forge_args: self.forge_args, genesis_args: genesis.fill_values_with_prompt(chain), @@ -112,6 +123,7 @@ impl InitArgs { l1_rpc_url, no_port_reallocation: self.no_port_reallocation, ecosystem_contracts_path, + wallets_path, dev: self.dev, }) } @@ -125,5 +137,6 @@ pub struct InitArgsFinal { pub l1_rpc_url: String, pub no_port_reallocation: bool, pub ecosystem_contracts_path: PathBuf, + pub wallets_path: PathBuf, pub dev: bool, } diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs index fb68a3485841..51f2d5c615b0 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -94,7 +94,7 @@ pub async fn init( init_configs_args.no_port_reallocation = true; } let mut contracts_config = init_configs(&init_configs_args, shell, chain_config).await?; - let wallets = WalletsConfig::read(shell, chain_config.l1_wallets_path.clone())?; + let wallets = WalletsConfig::read(shell, init_args.wallets_path.clone())?; // Fund some wallet addresses with ETH or base token (only for Localhost) distribute_eth(chain_config, init_args.l1_rpc_url.clone(), &wallets).await?; diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs index c839c18a05b9..c0da87b139af 100644 --- a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs +++ b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs @@ -350,6 +350,7 @@ async fn init_chains( } let ecosystem_contracts_path = Some(ecosystem_config.get_contracts_path().display().to_string()); + let wallets_path = Some(ecosystem_config.get_wallets_path().display().to_string()); logger::debug(format!( "Ecosystem contracts path: {:?}", ecosystem_contracts_path @@ -371,6 +372,7 @@ async fn init_chains( no_port_reallocation: final_init_args.no_port_reallocation, dev: final_init_args.dev, ecosystem_contracts_path: ecosystem_contracts_path.clone(), + wallets_path: wallets_path.clone(), }; let final_chain_init_args = chain_init_args .fill_values_with_prompt(Some(ecosystem_config.clone()), &chain_config)?; From b639f12c8180a59d65e6d6ce33deb850c7d477a1 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 25 Nov 2024 10:31:26 -0300 Subject: [PATCH 14/15] Revert "Add l1_wallets_path to ChainConfig" This reverts commit c025a75af06a53f6b72418e534eb1b983d093c89. --- zkstack_cli/crates/config/src/chain.rs | 7 ------- zkstack_cli/crates/config/src/ecosystem.rs | 1 - .../zkstack/src/commands/chain/args/create.rs | 17 +++-------------- .../crates/zkstack/src/commands/chain/create.rs | 6 ------ .../src/commands/ecosystem/args/create.rs | 5 ++--- 5 files changed, 5 insertions(+), 31 deletions(-) diff --git a/zkstack_cli/crates/config/src/chain.rs b/zkstack_cli/crates/config/src/chain.rs index cf396de3a977..f4c57d67c2e1 100644 --- a/zkstack_cli/crates/config/src/chain.rs +++ b/zkstack_cli/crates/config/src/chain.rs @@ -39,7 +39,6 @@ pub struct ChainConfigInternal { pub link_to_code: Option, pub external_node_config_path: Option, pub artifacts_path: Option, - pub l1_wallets_path: Option, pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode, pub base_token: BaseToken, pub wallet_creation: WalletCreation, @@ -69,7 +68,6 @@ pub struct ChainConfig { pub shell: OnceCell, pub legacy_bridge: Option, pub evm_emulator: bool, - pub l1_wallets_path: PathBuf, } impl Serialize for ChainConfig { @@ -174,7 +172,6 @@ impl ChainConfig { wallet_creation: self.wallet_creation, legacy_bridge: self.legacy_bridge, evm_emulator: self.evm_emulator, - l1_wallets_path: Some(self.l1_wallets_path.clone()), } } @@ -189,9 +186,6 @@ impl ChainConfig { let artifacts = chain_internal .artifacts_path .context("Artifacts path not found")?; - let l1_wallets_path = chain_internal - .l1_wallets_path - .context("L1 wallets path not found")?; Ok(Self { id: chain_internal.id, @@ -210,7 +204,6 @@ impl ChainConfig { artifacts, evm_emulator: chain_internal.evm_emulator, shell: shell.into(), - l1_wallets_path, }) } } diff --git a/zkstack_cli/crates/config/src/ecosystem.rs b/zkstack_cli/crates/config/src/ecosystem.rs index 5841732e3eac..15836d748002 100644 --- a/zkstack_cli/crates/config/src/ecosystem.rs +++ b/zkstack_cli/crates/config/src/ecosystem.rs @@ -186,7 +186,6 @@ impl EcosystemConfig { .unwrap_or_else(|| self.get_chain_artifacts_path(name)), legacy_bridge: config.legacy_bridge, evm_emulator: config.evm_emulator, - l1_wallets_path: self.get_wallets_path(), }) } diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs index 32d042932272..c6f2f8b28362 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs @@ -23,10 +23,9 @@ use crate::{ MSG_L1_BATCH_COMMIT_DATA_GENERATOR_MODE_PROMPT, MSG_L1_COMMIT_DATA_GENERATOR_MODE_HELP, MSG_L1_NETWORK_HELP, MSG_L1_NETWORK_PROMPT, MSG_NUMBER_VALIDATOR_GREATHER_THAN_ZERO_ERR, MSG_NUMBER_VALIDATOR_NOT_ZERO_ERR, MSG_PROVER_MODE_HELP, MSG_PROVER_VERSION_PROMPT, - MSG_SET_AS_DEFAULT_HELP, MSG_SET_AS_DEFAULT_PROMPT, MSG_WALLETS_PATH_HELP, - MSG_WALLETS_PATH_PROMPT, MSG_WALLET_CREATION_HELP, MSG_WALLET_CREATION_PROMPT, - MSG_WALLET_CREATION_VALIDATOR_ERR, MSG_WALLET_PATH_HELP, MSG_WALLET_PATH_INVALID_ERR, - MSG_WALLET_PATH_PROMPT, + MSG_SET_AS_DEFAULT_HELP, MSG_SET_AS_DEFAULT_PROMPT, MSG_WALLET_CREATION_HELP, + MSG_WALLET_CREATION_PROMPT, MSG_WALLET_CREATION_VALIDATOR_ERR, MSG_WALLET_PATH_HELP, + MSG_WALLET_PATH_INVALID_ERR, MSG_WALLET_PATH_PROMPT, }, utils::link_to_code::get_link_to_code, }; @@ -75,8 +74,6 @@ pub struct ChainCreateArgs { evm_emulator: Option, #[clap(long, help = MSG_L1_NETWORK_HELP, value_enum)] pub l1_network: Option, - #[clap(long, help = MSG_WALLETS_PATH_HELP)] - pub l1_wallets_path: Option, } impl ChainCreateArgs { @@ -91,7 +88,6 @@ impl ChainCreateArgs { link_to_code: Option, chains_path: Option, era_chain_id: L2ChainId, - l1_wallets_path: Option, ) -> anyhow::Result { let mut chain_name = self .chain_name @@ -244,11 +240,6 @@ impl ChainCreateArgs { .ask() }); - let l1_wallets_path = l1_wallets_path.unwrap_or_else(|| { - self.l1_wallets_path - .map_or_else(|| Prompt::new(MSG_WALLETS_PATH_PROMPT).ask(), PathBuf::from) - }); - let set_as_default = self.set_as_default.unwrap_or_else(|| { if number_of_chains == 0 { return true; @@ -274,7 +265,6 @@ impl ChainCreateArgs { era_chain_id, internal_id, l1_network, - l1_wallets_path, }) } } @@ -296,7 +286,6 @@ pub struct ChainCreateArgsFinal { pub era_chain_id: L2ChainId, pub internal_id: u32, pub l1_network: L1Network, - pub l1_wallets_path: PathBuf, } #[derive(Debug, Clone, EnumIter, Display, PartialEq, Eq)] diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/create.rs b/zkstack_cli/crates/zkstack/src/commands/chain/create.rs index 72581f841e21..4ef5f8573ed1 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/create.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/create.rs @@ -55,10 +55,6 @@ fn create( .as_ref() .map(|ecosystem| ecosystem.link_to_code.clone().display().to_string()); - let wallets_path = ecosystem - .as_ref() - .map(|ecosystem| ecosystem.get_wallets_path()); - let args = args .fill_values_with_prompt( shell, @@ -69,7 +65,6 @@ fn create( link_to_code, chains_path, era_chain_id, - wallets_path, ) .context(MSG_ARGS_VALIDATOR_ERR)?; @@ -137,7 +132,6 @@ pub(crate) fn create_chain_inner(args: ChainCreateArgsFinal, shell: &Shell) -> a shell: OnceCell::from(shell.clone()), legacy_bridge, evm_emulator: args.evm_emulator, - l1_wallets_path: args.l1_wallets_path, }; create_wallets( diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/create.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/create.rs index 3e391fe614f3..05cfeafd4752 100644 --- a/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/create.rs +++ b/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/create.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use clap::{Parser, ValueHint}; use common::{Prompt, PromptConfirm, PromptSelect}; -use config::{get_default_era_chain_id, WALLETS_FILE}; +use config::get_default_era_chain_id; use serde::{Deserialize, Serialize}; use slugify_rs::slugify; use strum::IntoEnumIterator; @@ -54,8 +54,8 @@ impl EcosystemCreateArgs { self.chain.set_as_default = Some(true); let chains_path = PathBuf::from("chains"); + let era_chain_id = get_default_era_chain_id(); - let l1_wallets_path = PathBuf::from("configs").join(WALLETS_FILE); let chain = self.chain.fill_values_with_prompt( shell, @@ -66,7 +66,6 @@ impl EcosystemCreateArgs { Some(link_to_code.clone()), Some(chains_path), era_chain_id, - Some(l1_wallets_path), )?; let start_containers = self.start_containers.unwrap_or_else(|| { From ef841d423bc4ad2a428b46209b14da61fbecf75e Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 25 Nov 2024 10:33:13 -0300 Subject: [PATCH 15/15] lint --- .../crates/zkstack/completion/_zkstack.zsh | 3 +-- .../crates/zkstack/completion/zkstack.fish | 3 +-- .../crates/zkstack/completion/zkstack.sh | 18 +++++++----------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/zkstack_cli/crates/zkstack/completion/_zkstack.zsh b/zkstack_cli/crates/zkstack/completion/_zkstack.zsh index a92b35f9971a..9a45735aa25e 100644 --- a/zkstack_cli/crates/zkstack/completion/_zkstack.zsh +++ b/zkstack_cli/crates/zkstack/completion/_zkstack.zsh @@ -83,7 +83,6 @@ in-file\:"Specify file with wallets"))' \ '--set-as-default=[Set as default chain]' \ '--evm-emulator=[Enable EVM emulator]' \ '--l1-network=[L1 Network]:L1_NETWORK:(localhost sepolia holesky mainnet)' \ -'--l1-wallets-path=[Wallets path]:L1_WALLETS_PATH:_default' \ '--start-containers=[Start reth and postgres containers after creation]' \ '--chain=[Chain to use]:CHAIN:_default' \ '--legacy-bridge[]' \ @@ -246,7 +245,6 @@ in-file\:"Specify file with wallets"))' \ '--set-as-default=[Set as default chain]' \ '--evm-emulator=[Enable EVM emulator]' \ '--l1-network=[L1 Network]:L1_NETWORK:(localhost sepolia holesky mainnet)' \ -'--l1-wallets-path=[Wallets path]:L1_WALLETS_PATH:_default' \ '--chain=[Chain to use]:CHAIN:_default' \ '--legacy-bridge[]' \ '-v[Verbose mode]' \ @@ -289,6 +287,7 @@ _arguments "${_arguments_options[@]}" : \ '--deploy-paymaster=[]' \ '--l1-rpc-url=[L1 RPC URL]:L1_RPC_URL:_default' \ '--ecosystem-contracts-path=[Ecosystem contracts path]:ECOSYSTEM_CONTRACTS_PATH:_default' \ +'--wallets-path=[Wallets path]:WALLETS_PATH:_default' \ '--chain=[Chain to use]:CHAIN:_default' \ '--resume[]' \ '-d[]' \ diff --git a/zkstack_cli/crates/zkstack/completion/zkstack.fish b/zkstack_cli/crates/zkstack/completion/zkstack.fish index 1322551596e8..20ea0c60c834 100644 --- a/zkstack_cli/crates/zkstack/completion/zkstack.fish +++ b/zkstack_cli/crates/zkstack/completion/zkstack.fish @@ -72,7 +72,6 @@ complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_se complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l set-as-default -d 'Set as default chain' -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l evm-emulator -d 'Enable EVM emulator' -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l l1-network -d 'L1 Network' -r -f -a "{localhost\t'',sepolia\t'',holesky\t'',mainnet\t''}" -complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l l1-wallets-path -d 'Wallets path' -r complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l start-containers -d 'Start reth and postgres containers after creation' -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l chain -d 'Chain to use' -r complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l legacy-bridge @@ -162,7 +161,6 @@ complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_s complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l set-as-default -d 'Set as default chain' -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l evm-emulator -d 'Enable EVM emulator' -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l l1-network -d 'L1 Network' -r -f -a "{localhost\t'',sepolia\t'',holesky\t'',mainnet\t''}" -complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l l1-wallets-path -d 'Wallets path' -r complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l chain -d 'Chain to use' -r complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l legacy-bridge complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -s v -l verbose -d 'Verbose mode' @@ -190,6 +188,7 @@ complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_s complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l deploy-paymaster -r -f -a "{true\t'',false\t''}" complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l l1-rpc-url -d 'L1 RPC URL' -r complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l ecosystem-contracts-path -d 'Ecosystem contracts path' -r +complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l wallets-path -d 'Wallets path' -r complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l chain -d 'Chain to use' -r complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l resume complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -s d -l dont-drop diff --git a/zkstack_cli/crates/zkstack/completion/zkstack.sh b/zkstack_cli/crates/zkstack/completion/zkstack.sh index 8501bbcd6b28..5dd12b32ee1b 100644 --- a/zkstack_cli/crates/zkstack/completion/zkstack.sh +++ b/zkstack_cli/crates/zkstack/completion/zkstack.sh @@ -1652,7 +1652,7 @@ _zkstack() { return 0 ;; zkstack__chain__create) - opts="-v -h --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --l1-network --l1-wallets-path --verbose --chain --ignore-prerequisites --help" + opts="-v -h --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --l1-network --verbose --chain --ignore-prerequisites --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -1717,10 +1717,6 @@ _zkstack() { COMPREPLY=($(compgen -W "localhost sepolia holesky mainnet" -- "${cur}")) return 0 ;; - --l1-wallets-path) - COMPREPLY=($(compgen -f "${cur}")) - return 0 - ;; --chain) COMPREPLY=($(compgen -f "${cur}")) return 0 @@ -2559,7 +2555,7 @@ _zkstack() { return 0 ;; zkstack__chain__init) - opts="-a -d -v -h --verify --verifier --verifier-url --verifier-api-key --resume --additional-args --server-db-url --server-db-name --dont-drop --deploy-paymaster --l1-rpc-url --no-port-reallocation --ecosystem-contracts-path --dev --verbose --chain --ignore-prerequisites --help configs help" + opts="-a -d -v -h --verify --verifier --verifier-url --verifier-api-key --resume --additional-args --server-db-url --server-db-name --dont-drop --deploy-paymaster --l1-rpc-url --no-port-reallocation --ecosystem-contracts-path --wallets-path --dev --verbose --chain --ignore-prerequisites --help configs help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -2609,6 +2605,10 @@ _zkstack() { COMPREPLY=($(compgen -f "${cur}")) return 0 ;; + --wallets-path) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; --chain) COMPREPLY=($(compgen -f "${cur}")) return 0 @@ -5321,7 +5321,7 @@ _zkstack() { return 0 ;; zkstack__ecosystem__create) - opts="-v -h --ecosystem-name --l1-network --link-to-code --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --l1-network --l1-wallets-path --start-containers --verbose --chain --ignore-prerequisites --help" + opts="-v -h --ecosystem-name --l1-network --link-to-code --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --l1-network --start-containers --verbose --chain --ignore-prerequisites --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -5401,10 +5401,6 @@ _zkstack() { COMPREPLY=($(compgen -W "localhost sepolia holesky mainnet" -- "${cur}")) return 0 ;; - --l1-wallets-path) - COMPREPLY=($(compgen -f "${cur}")) - return 0 - ;; --start-containers) COMPREPLY=($(compgen -W "true false" -- "${cur}")) return 0