From d305c834cfada5fe72d83028f515d424e689468c Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 29 Oct 2024 16:52:35 -0300 Subject: [PATCH 01/24] Update link to code in init_configs --- zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 31c5c681e7d3..98acd188a37d 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs @@ -46,7 +46,7 @@ pub async fn init_configs( ) -> anyhow::Result { // Port scanner should run before copying configs to avoid marking initial ports as assigned let mut ecosystem_ports = EcosystemPortsScanner::scan(shell)?; - copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?; + copy_configs(shell, &chain_config.link_to_code, &chain_config.configs)?; if !init_args.no_port_reallocation { ecosystem_ports.allocate_ports_in_yaml( From b4bf47a14b16011ce120ddf517a4b641a8167fdb Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 29 Oct 2024 16:55:33 -0300 Subject: [PATCH 02/24] Update l1_network in distribute_eth --- zkstack_cli/crates/zkstack/src/commands/chain/common.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs index 0c35b3ee4fe0..f28524466192 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs @@ -14,7 +14,7 @@ pub async fn distribute_eth( l1_rpc_url: String, ) -> anyhow::Result<()> { if chain_config.wallet_creation == WalletCreation::Localhost - && ecosystem_config.l1_network == L1Network::Localhost + && chain_config.l1_network == L1Network::Localhost { let spinner = Spinner::new(MSG_DISTRIBUTING_ETH_SPINNER); let wallets = ecosystem_config.get_wallets()?; @@ -34,7 +34,7 @@ pub async fn distribute_eth( wallets.operator, addresses, l1_rpc_url, - ecosystem_config.l1_network.chain_id(), + chain_config.l1_network.chain_id(), AMOUNT_FOR_DISTRIBUTION_TO_WALLETS, ) .await?; From 89e7eaab8f2f88a8792a6667b2f5243149d0460e Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 29 Oct 2024 16:56:17 -0300 Subject: [PATCH 03/24] Update l1_network in mint_base_token --- zkstack_cli/crates/zkstack/src/commands/chain/common.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs index f28524466192..c479ee3588e2 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs @@ -49,7 +49,7 @@ pub async fn mint_base_token( l1_rpc_url: String, ) -> anyhow::Result<()> { if chain_config.wallet_creation == WalletCreation::Localhost - && ecosystem_config.l1_network == L1Network::Localhost + && chain_config.l1_network == L1Network::Localhost && chain_config.base_token != BaseToken::eth() { let spinner = Spinner::new(MSG_MINT_BASE_TOKEN_SPINNER); @@ -64,7 +64,7 @@ pub async fn mint_base_token( base_token.address, addresses, l1_rpc_url, - ecosystem_config.l1_network.chain_id(), + chain_config.l1_network.chain_id(), amount, ) .await?; From 93970f31820ab75f7e52e8f6e488588ddba785e2 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 29 Oct 2024 16:57:48 -0300 Subject: [PATCH 04/24] Update link_to_code in register_chain --- zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs b/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs index 65ee05a1ea5f..ea962f8d3128 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs @@ -64,7 +64,7 @@ pub async fn register_chain( sender: Option, broadcast: bool, ) -> anyhow::Result<()> { - let deploy_config_path = REGISTER_CHAIN_SCRIPT_PARAMS.input(&config.link_to_code); + let deploy_config_path = REGISTER_CHAIN_SCRIPT_PARAMS.input(&chain_config.link_to_code); let deploy_config = RegisterChainL1Config::new(chain_config, contracts)?; deploy_config.save(shell, deploy_config_path)?; From 97a9e190a11fc0ab21c225fb01f900262da64464 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 29 Oct 2024 16:58:54 -0300 Subject: [PATCH 05/24] Update path_to_foundry in register_chain --- zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs b/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs index ea962f8d3128..fd5961934903 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs @@ -69,7 +69,7 @@ pub async fn register_chain( let deploy_config = RegisterChainL1Config::new(chain_config, contracts)?; deploy_config.save(shell, deploy_config_path)?; - let mut forge = Forge::new(&config.path_to_foundry()) + let mut forge = Forge::new(&chain_config.path_to_foundry()) .script(®ISTER_CHAIN_SCRIPT_PARAMS.script(), forge_args.clone()) .with_ffi() .with_rpc_url(l1_rpc_url); From 3f35ab9dec1b81a2b34178a18ddabb7bf6e52d0a Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 29 Oct 2024 17:03:31 -0300 Subject: [PATCH 06/24] Update path_to_foundry in accept_admin --- zkstack_cli/crates/zkstack/src/accept_ownership.rs | 5 +++-- .../zkstack/src/commands/chain/accept_chain_ownership.rs | 2 +- zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs | 2 +- zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/accept_ownership.rs b/zkstack_cli/crates/zkstack/src/accept_ownership.rs index 474e76e599a8..802e93fa69f8 100644 --- a/zkstack_cli/crates/zkstack/src/accept_ownership.rs +++ b/zkstack_cli/crates/zkstack/src/accept_ownership.rs @@ -1,3 +1,5 @@ +use std::path::Path; + use common::{ forge::{Forge, ForgeScript, ForgeScriptArgs}, spinner::Spinner, @@ -26,7 +28,7 @@ lazy_static! { pub async fn accept_admin( shell: &Shell, - ecosystem_config: &EcosystemConfig, + foundry_contracts_path: &Path, admin: Address, governor: &Wallet, target_address: Address, @@ -42,7 +44,6 @@ pub async fn accept_admin( let calldata = ACCEPT_ADMIN .encode("chainAdminAcceptAdmin", (admin, target_address)) .unwrap(); - let foundry_contracts_path = ecosystem_config.path_to_foundry(); let forge = Forge::new(&foundry_contracts_path) .script( &ACCEPT_GOVERNANCE_SCRIPT_PARAMS.script(), 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 cf3e2981b3c7..a745fab1e8c3 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 @@ -28,7 +28,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { let spinner = Spinner::new(MSG_ACCEPTING_ADMIN_SPINNER); accept_admin( shell, - &ecosystem_config, + &chain_config.path_to_foundry(), contracts.l1.chain_admin_addr, &chain_config.get_wallets_config()?.governor, contracts.l1.diamond_proxy_addr, 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 d92c56d2eb10..9435f2f7dc0a 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -105,7 +105,7 @@ pub async fn init( let spinner = Spinner::new(MSG_ACCEPTING_ADMIN_SPINNER); accept_admin( shell, - ecosystem_config, + &chain_config.path_to_foundry(), contracts_config.l1.chain_admin_addr, &chain_config.get_wallets_config()?.governor, contracts_config.l1.diamond_proxy_addr, diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs index 06b9b9161112..af9273ebf304 100644 --- a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs +++ b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs @@ -267,7 +267,7 @@ async fn deploy_ecosystem_inner( accept_admin( shell, - config, + &config.path_to_foundry(), contracts_config.l1.chain_admin_addr, &config.get_wallets()?.governor, contracts_config.ecosystem_contracts.bridgehub_proxy_addr, @@ -289,7 +289,7 @@ async fn deploy_ecosystem_inner( accept_admin( shell, - config, + &config.path_to_foundry(), contracts_config.l1.chain_admin_addr, &config.get_wallets()?.governor, contracts_config.bridges.shared.l1_address, @@ -313,7 +313,7 @@ async fn deploy_ecosystem_inner( accept_admin( shell, - config, + &config.path_to_foundry(), contracts_config.l1.chain_admin_addr, &config.get_wallets()?.governor, contracts_config From 187603e72adf12c307d5a26142eb6f5b3ab6860a Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 29 Oct 2024 17:05:17 -0300 Subject: [PATCH 07/24] Update path_to_foundry in set_token_multiplier_setter --- zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs | 2 +- .../src/commands/chain/set_token_multiplier_setter.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) 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 9435f2f7dc0a..e5d956138f3e 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -120,7 +120,7 @@ pub async fn init( let spinner = Spinner::new(MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER); set_token_multiplier_setter( shell, - ecosystem_config, + &chain_config.path_to_foundry(), &chain_config.get_wallets_config()?.governor, contracts_config.l1.chain_admin_addr, chain_config 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 4a6cd31b2c0a..e6856889c947 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 @@ -1,3 +1,5 @@ +use std::path::Path; + use anyhow::Context; use common::{ forge::{Forge, ForgeScript, ForgeScriptArgs}, @@ -52,7 +54,7 @@ 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, - &ecosystem_config, + &chain_config.path_to_foundry(), &chain_config.get_wallets_config()?.governor, contracts_config.l1.chain_admin_addr, token_multiplier_setter_address, @@ -72,7 +74,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { pub async fn set_token_multiplier_setter( shell: &Shell, - ecosystem_config: &EcosystemConfig, + foundry_contracts_path: &Path, governor: &Wallet, chain_admin_address: Address, target_address: Address, @@ -91,7 +93,6 @@ pub async fn set_token_multiplier_setter( (chain_admin_address, target_address), ) .unwrap(); - let foundry_contracts_path = ecosystem_config.path_to_foundry(); let forge = Forge::new(&foundry_contracts_path) .script( &ACCEPT_GOVERNANCE_SCRIPT_PARAMS.script(), From 452111411ff9e2722f34f2b7aacaee966a028601 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 29 Oct 2024 17:07:36 -0300 Subject: [PATCH 08/24] Update link_to_code in deploy_l2_contracts --- .../crates/zkstack/src/commands/chain/deploy_l2_contracts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 091bef86d26d..4ef43fdab61b 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 @@ -121,7 +121,7 @@ async fn build_and_deploy( signature: Option<&str>, mut update_config: impl FnMut(&Shell, &Path) -> anyhow::Result<()>, ) -> anyhow::Result<()> { - build_l2_contracts(shell.clone(), ecosystem_config.link_to_code.clone())?; + build_l2_contracts(shell.clone(), chain_config.link_to_code.clone())?; call_forge(shell, chain_config, ecosystem_config, forge_args, signature).await?; update_config( shell, From b5f4e8d5ac08049a7030d97f1e25b5c06ff37c67 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 5 Nov 2024 15:59:50 -0300 Subject: [PATCH 09/24] lint --- zkstack_cli/crates/zkstack/src/accept_ownership.rs | 2 +- .../zkstack/src/commands/chain/set_token_multiplier_setter.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/accept_ownership.rs b/zkstack_cli/crates/zkstack/src/accept_ownership.rs index 802e93fa69f8..d3c6d7699fda 100644 --- a/zkstack_cli/crates/zkstack/src/accept_ownership.rs +++ b/zkstack_cli/crates/zkstack/src/accept_ownership.rs @@ -44,7 +44,7 @@ pub async fn accept_admin( let calldata = ACCEPT_ADMIN .encode("chainAdminAcceptAdmin", (admin, target_address)) .unwrap(); - let forge = Forge::new(&foundry_contracts_path) + let forge = Forge::new(foundry_contracts_path) .script( &ACCEPT_GOVERNANCE_SCRIPT_PARAMS.script(), forge_args.clone(), 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 e6856889c947..d44c3ec37120 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 @@ -93,7 +93,7 @@ pub async fn set_token_multiplier_setter( (chain_admin_address, target_address), ) .unwrap(); - let forge = Forge::new(&foundry_contracts_path) + let forge = Forge::new(foundry_contracts_path) .script( &ACCEPT_GOVERNANCE_SCRIPT_PARAMS.script(), forge_args.clone(), From e21ec41ea8d7d15d04168884f737d55f6edfded2 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 6 Nov 2024 10:30:22 -0300 Subject: [PATCH 10/24] Add contracts path placeholder --- zkstack_cli/crates/config/src/ecosystem.rs | 6 +++++- .../src/commands/chain/args/init/configs.rs | 16 ++++++++++++++-- .../zkstack/src/commands/chain/init/configs.rs | 12 ++++++------ .../zkstack/src/commands/chain/init/mod.rs | 3 +-- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/zkstack_cli/crates/config/src/ecosystem.rs b/zkstack_cli/crates/config/src/ecosystem.rs index 9b9a15a80a39..2e1075018d59 100644 --- a/zkstack_cli/crates/config/src/ecosystem.rs +++ b/zkstack_cli/crates/config/src/ecosystem.rs @@ -211,7 +211,7 @@ impl EcosystemConfig { } pub fn get_contracts_config(&self) -> anyhow::Result { - ContractsConfig::read(self.get_shell(), self.config.join(CONTRACTS_FILE)) + ContractsConfig::read(self.get_shell(), self.get_contracts_path()) } pub fn path_to_foundry(&self) -> PathBuf { @@ -272,6 +272,10 @@ impl EcosystemConfig { wallet_creation: self.wallet_creation, } } + + pub fn get_contracts_path(&self) -> PathBuf { + self.config.join(CONTRACTS_FILE) + } } /// Result of checking if the ecosystem exists. diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs index b34809643cf5..e7695dd60bd5 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs @@ -1,6 +1,8 @@ +use std::path::PathBuf; + use clap::Parser; use common::Prompt; -use config::ChainConfig; +use config::{ChainConfig, EcosystemConfig}; use serde::{Deserialize, Serialize}; use types::L1Network; use url::Url; @@ -33,10 +35,15 @@ pub struct InitConfigsArgsFinal { pub genesis_args: GenesisArgsFinal, pub l1_rpc_url: String, pub no_port_reallocation: bool, + pub contracts_path: PathBuf, } impl InitConfigsArgs { - pub fn fill_values_with_prompt(self, config: &ChainConfig) -> InitConfigsArgsFinal { + pub fn fill_values_with_prompt( + self, + ecosystem: Option, + config: &ChainConfig, + ) -> InitConfigsArgsFinal { let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT); if config.l1_network == L1Network::Localhost { @@ -51,20 +58,25 @@ impl InitConfigsArgs { .ask() }); + let contracts_path = ecosystem.unwrap().get_contracts_path(); + InitConfigsArgsFinal { genesis_args: self.genesis_args.fill_values_with_prompt(config), l1_rpc_url, no_port_reallocation: self.no_port_reallocation, + contracts_path, } } } impl InitConfigsArgsFinal { pub fn from_chain_init_args(init_args: &InitArgsFinal) -> InitConfigsArgsFinal { + let contracts_path = PathBuf::new(); InitConfigsArgsFinal { genesis_args: init_args.genesis_args.clone(), l1_rpc_url: init_args.l1_rpc_url.clone(), no_port_reallocation: init_args.no_port_reallocation, + contracts_path, } } } 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 98acd188a37d..fd8d50ddc736 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs @@ -1,8 +1,9 @@ use anyhow::Context; use common::logger; use config::{ - copy_configs, set_l1_rpc_url, traits::SaveConfigWithBasePath, update_from_chain_config, - ChainConfig, ContractsConfig, EcosystemConfig, + copy_configs, set_l1_rpc_url, + traits::{ReadConfig, SaveConfigWithBasePath}, + update_from_chain_config, ChainConfig, ContractsConfig, EcosystemConfig, }; use ethers::types::Address; use xshell::Shell; @@ -30,9 +31,9 @@ pub async fn run(args: InitConfigsArgs, shell: &Shell) -> anyhow::Result<()> { let chain_config = ecosystem_config .load_current_chain() .context(MSG_CHAIN_NOT_FOUND_ERR)?; - let args = args.fill_values_with_prompt(&chain_config); + let args = args.fill_values_with_prompt(Some(ecosystem_config), &chain_config); - init_configs(&args, shell, &ecosystem_config, &chain_config).await?; + init_configs(&args, shell, &chain_config).await?; logger::outro(MSG_CHAIN_CONFIGS_INITIALIZED); Ok(()) @@ -41,7 +42,6 @@ pub async fn run(args: InitConfigsArgs, shell: &Shell) -> anyhow::Result<()> { pub async fn init_configs( init_args: &InitConfigsArgsFinal, shell: &Shell, - ecosystem_config: &EcosystemConfig, chain_config: &ChainConfig, ) -> anyhow::Result { // Port scanner should run before copying configs to avoid marking initial ports as assigned @@ -85,7 +85,7 @@ pub async fn init_configs( genesis_config.save_with_base_path(shell, &chain_config.configs)?; // Initialize contracts config - let mut contracts_config = ecosystem_config.get_contracts_config()?; + let mut contracts_config = ContractsConfig::read(shell, &init_args.contracts_path)?; contracts_config.l1.diamond_proxy_addr = Address::zero(); contracts_config.l1.governance_addr = Address::zero(); contracts_config.l1.chain_admin_addr = Address::zero(); 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 e5d956138f3e..ac5ff99f2a15 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -78,8 +78,7 @@ pub async fn init( ) -> anyhow::Result<()> { // Initialize configs let init_configs_args = InitConfigsArgsFinal::from_chain_init_args(init_args); - let mut contracts_config = - init_configs(&init_configs_args, shell, ecosystem_config, chain_config).await?; + let mut contracts_config = init_configs(&init_configs_args, shell, chain_config).await?; // Fund some wallet addresses with ETH or base token (only for Localhost) distribute_eth(ecosystem_config, chain_config, init_args.l1_rpc_url.clone()).await?; From 0a1a027f8190a135f4b5f9e4deec925f21cad1b6 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 30 Oct 2024 09:15:53 -0300 Subject: [PATCH 11/24] Add prompt_ecosystem_contracts_path --- zkstack_cli/crates/config/src/chain.rs | 6 ++- zkstack_cli/crates/config/src/ecosystem.rs | 12 ++--- zkstack_cli/crates/config/src/utils.rs | 12 +++++ .../src/commands/chain/args/init/configs.rs | 14 +++--- .../src/commands/chain/init/configs.rs | 10 ++--- .../zkstack/src/commands/ecosystem/init.rs | 45 +++++++++---------- zkstack_cli/crates/zkstack/src/messages.rs | 1 + 7 files changed, 58 insertions(+), 42 deletions(-) diff --git a/zkstack_cli/crates/config/src/chain.rs b/zkstack_cli/crates/config/src/chain.rs index 150745b4ce64..34f996ef091c 100644 --- a/zkstack_cli/crates/config/src/chain.rs +++ b/zkstack_cli/crates/config/src/chain.rs @@ -19,7 +19,7 @@ use crate::{ FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig, SaveConfigWithBasePath, ZkStackConfig, }, - utils::find_file, + utils::{find_file, get_preexisting_ecosystem_contracts_path}, ContractsConfig, EcosystemConfig, GeneralConfig, GenesisConfig, SecretsConfig, WalletsConfig, }; @@ -170,6 +170,10 @@ impl ChainConfig { evm_emulator: self.evm_emulator, } } + + pub fn get_preexisting_ecosystem_contracts_path(&self) -> PathBuf { + get_preexisting_ecosystem_contracts_path(&self.link_to_code, self.l1_network) + } } impl ChainConfigInternal { diff --git a/zkstack_cli/crates/config/src/ecosystem.rs b/zkstack_cli/crates/config/src/ecosystem.rs index 2e1075018d59..f8330d5286a2 100644 --- a/zkstack_cli/crates/config/src/ecosystem.rs +++ b/zkstack_cli/crates/config/src/ecosystem.rs @@ -12,9 +12,9 @@ use zksync_basic_types::L2ChainId; use crate::{ consts::{ - CONFIGS_PATH, CONFIG_NAME, CONTRACTS_FILE, ECOSYSTEM_PATH, ERA_CHAIN_ID, - ERC20_CONFIGS_FILE, ERC20_DEPLOYMENT_FILE, INITIAL_DEPLOYMENT_FILE, L1_CONTRACTS_FOUNDRY, - LOCAL_ARTIFACTS_PATH, LOCAL_DB_PATH, WALLETS_FILE, + CONFIGS_PATH, CONFIG_NAME, CONTRACTS_FILE, ERA_CHAIN_ID, ERC20_CONFIGS_FILE, + ERC20_DEPLOYMENT_FILE, INITIAL_DEPLOYMENT_FILE, L1_CONTRACTS_FOUNDRY, LOCAL_ARTIFACTS_PATH, + LOCAL_DB_PATH, WALLETS_FILE, }, create_localhost_wallets, forge_interface::deploy_ecosystem::{ @@ -22,7 +22,7 @@ use crate::{ output::{ERC20Tokens, Erc20Token}, }, traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkStackConfig}, - utils::find_file, + utils::{find_file, get_preexisting_ecosystem_contracts_path}, ChainConfig, ChainConfigInternal, ContractsConfig, WalletsConfig, }; @@ -242,8 +242,8 @@ impl EcosystemConfig { } /// Path to the predefined ecosystem configs - pub fn get_preexisting_configs_path(&self) -> PathBuf { - self.link_to_code.join(ECOSYSTEM_PATH) + pub fn get_preexisting_ecosystem_contracts_path(&self) -> PathBuf { + get_preexisting_ecosystem_contracts_path(&self.link_to_code, self.l1_network) } pub fn get_chain_rocks_db_path(&self, chain_name: &str) -> PathBuf { diff --git a/zkstack_cli/crates/config/src/utils.rs b/zkstack_cli/crates/config/src/utils.rs index 63cf2cf601f5..8a5712eb2bc5 100644 --- a/zkstack_cli/crates/config/src/utils.rs +++ b/zkstack_cli/crates/config/src/utils.rs @@ -1,7 +1,10 @@ use std::path::PathBuf; +use types::L1Network; use xshell::Shell; +use crate::ECOSYSTEM_PATH; + // Find file in all parents repository and return necessary path or an empty error if nothing has been found pub fn find_file(shell: &Shell, path_buf: PathBuf, file_name: &str) -> Result { let _dir = shell.push_dir(path_buf); @@ -15,3 +18,12 @@ pub fn find_file(shell: &Shell, path_buf: PathBuf, file_name: &str) -> Result PathBuf { + link_to_code + .join(ECOSYSTEM_PATH) + .join(format!("{}.yaml", l1_network.to_string().to_lowercase())) +} diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs index e7695dd60bd5..1fec9aa801bc 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs @@ -14,8 +14,8 @@ use crate::{ }, defaults::LOCAL_RPC_URL, messages::{ - MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, - MSG_L1_RPC_URL_PROMPT, MSG_NO_PORT_REALLOCATION_HELP, + MSG_ECOSYSTEM_CONTRACTS_PATH_HELP, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, + MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, MSG_NO_PORT_REALLOCATION_HELP, }, }; @@ -28,6 +28,8 @@ pub struct InitConfigsArgs { pub l1_rpc_url: Option, #[clap(long, help = MSG_NO_PORT_REALLOCATION_HELP)] pub no_port_reallocation: bool, + #[clap(long, help = MSG_ECOSYSTEM_CONTRACTS_PATH_HELP)] + pub _ecosystem_contracts_path: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -41,12 +43,12 @@ pub struct InitConfigsArgsFinal { impl InitConfigsArgs { pub fn fill_values_with_prompt( self, - ecosystem: Option, - config: &ChainConfig, + ecosystem: Option<&EcosystemConfig>, + chain: &ChainConfig, ) -> InitConfigsArgsFinal { let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT); - if config.l1_network == L1Network::Localhost { + if chain.l1_network == L1Network::Localhost { prompt = prompt.default(LOCAL_RPC_URL); } prompt @@ -61,7 +63,7 @@ impl InitConfigsArgs { let contracts_path = ecosystem.unwrap().get_contracts_path(); InitConfigsArgsFinal { - genesis_args: self.genesis_args.fill_values_with_prompt(config), + genesis_args: self.genesis_args.fill_values_with_prompt(chain), l1_rpc_url, no_port_reallocation: self.no_port_reallocation, contracts_path, 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 fd8d50ddc736..f376a0464d6d 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs @@ -3,7 +3,9 @@ use common::logger; use config::{ copy_configs, set_l1_rpc_url, traits::{ReadConfig, SaveConfigWithBasePath}, - update_from_chain_config, ChainConfig, ContractsConfig, EcosystemConfig, + update_from_chain_config, + zkstack_config::ZkStackConfig, + ChainConfig, ContractsConfig, EcosystemConfig, }; use ethers::types::Address; use xshell::Shell; @@ -28,10 +30,8 @@ use crate::{ pub async fn run(args: InitConfigsArgs, shell: &Shell) -> anyhow::Result<()> { let ecosystem_config = EcosystemConfig::from_file(shell)?; - let chain_config = ecosystem_config - .load_current_chain() - .context(MSG_CHAIN_NOT_FOUND_ERR)?; - let args = args.fill_values_with_prompt(Some(ecosystem_config), &chain_config); + let chain_config = ZkStackConfig::load_current_chain(shell).context(MSG_CHAIN_NOT_FOUND_ERR)?; + let args = args.fill_values_with_prompt(Some(&ecosystem_config), &chain_config); init_configs(&args, shell, &chain_config).await?; logger::outro(MSG_CHAIN_CONFIGS_INITIALIZED); diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs index af9273ebf304..ea44c54d2984 100644 --- a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs +++ b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs @@ -185,33 +185,11 @@ async fn deploy_ecosystem( let ecosystem_contracts_path = match &ecosystem.ecosystem_contracts_path { Some(path) => Some(path.clone()), - None => { - let input_path: String = Prompt::new(MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT) - .allow_empty() - .validate_with(|val: &String| { - if val.is_empty() { - return Ok(()); - } - PathBuf::from_str(val) - .map(|_| ()) - .map_err(|_| MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR.to_string()) - }) - .ask(); - if input_path.is_empty() { - None - } else { - Some(input_path.into()) - } - } + None => prompt_ecosystem_contracts_path(), }; let ecosystem_preexisting_configs_path = - ecosystem_config - .get_preexisting_configs_path() - .join(format!( - "{}.yaml", - ecosystem_config.l1_network.to_string().to_lowercase() - )); + ecosystem_config.get_preexisting_ecosystem_contracts_path(); // currently there are not some preexisting ecosystem contracts in // chains, so we need check if this file exists. @@ -234,6 +212,25 @@ async fn deploy_ecosystem( ContractsConfig::read(shell, ecosystem_contracts_path) } +pub fn prompt_ecosystem_contracts_path() -> Option { + let input_path: String = Prompt::new(MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT) + .allow_empty() + .validate_with(|val: &String| { + if val.is_empty() { + return Ok(()); + } + PathBuf::from_str(val) + .map(|_| ()) + .map_err(|_| MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR.to_string()) + }) + .ask(); + if input_path.is_empty() { + None + } else { + Some(input_path.into()) + } +} + async fn deploy_ecosystem_inner( shell: &Shell, forge_args: ForgeScriptArgs, diff --git a/zkstack_cli/crates/zkstack/src/messages.rs b/zkstack_cli/crates/zkstack/src/messages.rs index aec7c864bc58..dbcad8dda477 100644 --- a/zkstack_cli/crates/zkstack/src/messages.rs +++ b/zkstack_cli/crates/zkstack/src/messages.rs @@ -60,6 +60,7 @@ pub(super) fn msg_path_to_zksync_does_not_exist_err(path: &str) -> String { } /// Ecosystem and chain init related messages +pub(super) const MSG_ECOSYSTEM_CONTRACTS_PATH_HELP: &str = "Ecosystem contracts path"; pub(super) const MSG_L1_RPC_URL_HELP: &str = "L1 RPC URL"; pub(super) const MSG_NO_PORT_REALLOCATION_HELP: &str = "Do not reallocate ports"; pub(super) const MSG_GENESIS_ARGS_HELP: &str = "Genesis options"; From dcb38362b952d57071699ce82b2a534815785abf Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 6 Nov 2024 10:55:16 -0300 Subject: [PATCH 12/24] Add ecosystem_contracts_path arg --- .../src/commands/chain/args/init/configs.rs | 58 ++++++++++++++----- .../src/commands/chain/args/init/mod.rs | 38 +++++++++--- .../src/commands/chain/init/configs.rs | 4 +- .../zkstack/src/commands/chain/init/mod.rs | 16 ++--- .../zkstack/src/commands/ecosystem/init.rs | 6 +- 5 files changed, 87 insertions(+), 35 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs index 1fec9aa801bc..9eca4cdaa840 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs @@ -8,14 +8,18 @@ use types::L1Network; use url::Url; use crate::{ - commands::chain::args::{ - genesis::{GenesisArgs, GenesisArgsFinal}, - init::InitArgsFinal, + commands::{ + chain::args::{ + genesis::{GenesisArgs, GenesisArgsFinal}, + init::InitArgsFinal, + }, + ecosystem::init::prompt_ecosystem_contracts_path, }, defaults::LOCAL_RPC_URL, messages::{ - MSG_ECOSYSTEM_CONTRACTS_PATH_HELP, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, - MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, MSG_NO_PORT_REALLOCATION_HELP, + msg_ecosystem_no_found_preexisting_contract, MSG_ECOSYSTEM_CONTRACTS_PATH_HELP, + MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, + MSG_L1_RPC_URL_PROMPT, MSG_NO_PORT_REALLOCATION_HELP, }, }; @@ -29,7 +33,7 @@ pub struct InitConfigsArgs { #[clap(long, help = MSG_NO_PORT_REALLOCATION_HELP)] pub no_port_reallocation: bool, #[clap(long, help = MSG_ECOSYSTEM_CONTRACTS_PATH_HELP)] - pub _ecosystem_contracts_path: Option, + pub ecosystem_contracts_path: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -37,15 +41,15 @@ pub struct InitConfigsArgsFinal { pub genesis_args: GenesisArgsFinal, pub l1_rpc_url: String, pub no_port_reallocation: bool, - pub contracts_path: PathBuf, + pub ecosystem_contracts_path: PathBuf, } impl InitConfigsArgs { pub fn fill_values_with_prompt( self, - ecosystem: Option<&EcosystemConfig>, + ecosystem: Option, chain: &ChainConfig, - ) -> InitConfigsArgsFinal { + ) -> anyhow::Result { let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT); if chain.l1_network == L1Network::Localhost { @@ -60,25 +64,49 @@ impl InitConfigsArgs { .ask() }); - let contracts_path = ecosystem.unwrap().get_contracts_path(); + let ecosystem_contracts_path = + get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem, chain)?; - InitConfigsArgsFinal { + Ok(InitConfigsArgsFinal { genesis_args: self.genesis_args.fill_values_with_prompt(chain), l1_rpc_url, no_port_reallocation: self.no_port_reallocation, - contracts_path, - } + ecosystem_contracts_path, + }) + } +} + +pub fn get_ecosystem_contracts_path( + ecosystem_contracts_path: Option, + ecosystem: Option, + chain: &ChainConfig, +) -> anyhow::Result { + let ecosystem_contracts_path = ecosystem_contracts_path.map_or_else( + || prompt_ecosystem_contracts_path(), + |path| Some(PathBuf::from(path)), + ); + + let ecosystem_preexisting_configs_path = ecosystem.map_or_else( + || chain.get_preexisting_ecosystem_contracts_path(), + |e| e.get_preexisting_ecosystem_contracts_path(), + ); + + if ecosystem_contracts_path.is_none() && !ecosystem_preexisting_configs_path.exists() { + anyhow::bail!(msg_ecosystem_no_found_preexisting_contract( + &chain.l1_network.to_string() + )) } + + Ok(ecosystem_contracts_path.unwrap_or_else(|| ecosystem_preexisting_configs_path)) } impl InitConfigsArgsFinal { pub fn from_chain_init_args(init_args: &InitArgsFinal) -> InitConfigsArgsFinal { - let contracts_path = PathBuf::new(); InitConfigsArgsFinal { genesis_args: init_args.genesis_args.clone(), l1_rpc_url: init_args.l1_rpc_url.clone(), no_port_reallocation: init_args.no_port_reallocation, - contracts_path, + ecosystem_contracts_path: init_args.ecosystem_contracts_path.clone(), } } } 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 a5c7a6890ca1..a483f89e3995 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 @@ -1,6 +1,9 @@ +use std::path::PathBuf; + use clap::Parser; use common::{forge::ForgeScriptArgs, Prompt}; -use config::ChainConfig; +use config::{ChainConfig, EcosystemConfig}; +use configs::get_ecosystem_contracts_path; use serde::{Deserialize, Serialize}; use types::L1Network; use url::Url; @@ -9,9 +12,9 @@ use crate::{ commands::chain::args::genesis::{GenesisArgs, GenesisArgsFinal}, defaults::LOCAL_RPC_URL, messages::{ - MSG_DEPLOY_PAYMASTER_PROMPT, MSG_DEV_ARG_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_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, }, }; @@ -35,6 +38,8 @@ pub struct InitArgs { pub l1_rpc_url: Option, #[clap(long, help = MSG_NO_PORT_REALLOCATION_HELP)] pub no_port_reallocation: bool, + #[clap(long, help = MSG_ECOSYSTEM_CONTRACTS_PATH_HELP)] + pub ecosystem_contracts_path: Option, #[clap(long, help = MSG_DEV_ARG_HELP)] pub dev: bool, } @@ -49,7 +54,11 @@ impl InitArgs { } } - pub fn fill_values_with_prompt(self, config: &ChainConfig) -> InitArgsFinal { + pub fn fill_values_with_prompt( + self, + ecosystem: Option, + chain: &ChainConfig, + ) -> anyhow::Result { let genesis = self.get_genesis_args(); let deploy_paymaster = if self.dev { @@ -67,7 +76,7 @@ impl InitArgs { } else { self.l1_rpc_url.unwrap_or_else(|| { let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT); - if config.l1_network == L1Network::Localhost { + if chain.l1_network == L1Network::Localhost { prompt = prompt.default(LOCAL_RPC_URL); } prompt @@ -80,14 +89,24 @@ impl InitArgs { }) }; - InitArgsFinal { + let ecosystem_contracts_path = if self.dev { + ecosystem.map_or_else( + || chain.get_preexisting_ecosystem_contracts_path(), + |e| e.get_preexisting_ecosystem_contracts_path(), + ) + } else { + get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem, chain)? + }; + + Ok(InitArgsFinal { forge_args: self.forge_args, - genesis_args: genesis.fill_values_with_prompt(config), + genesis_args: genesis.fill_values_with_prompt(chain), deploy_paymaster, l1_rpc_url, no_port_reallocation: self.no_port_reallocation, + ecosystem_contracts_path, dev: self.dev, - } + }) } } @@ -98,5 +117,6 @@ pub struct InitArgsFinal { pub deploy_paymaster: bool, pub l1_rpc_url: String, pub no_port_reallocation: bool, + pub ecosystem_contracts_path: PathBuf, pub dev: bool, } 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 f376a0464d6d..54ee638b5205 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs @@ -31,7 +31,7 @@ use crate::{ pub async fn run(args: InitConfigsArgs, shell: &Shell) -> anyhow::Result<()> { let ecosystem_config = EcosystemConfig::from_file(shell)?; let chain_config = ZkStackConfig::load_current_chain(shell).context(MSG_CHAIN_NOT_FOUND_ERR)?; - let args = args.fill_values_with_prompt(Some(&ecosystem_config), &chain_config); + let args = args.fill_values_with_prompt(Some(ecosystem_config), &chain_config)?; init_configs(&args, shell, &chain_config).await?; logger::outro(MSG_CHAIN_CONFIGS_INITIALIZED); @@ -85,7 +85,7 @@ pub async fn init_configs( genesis_config.save_with_base_path(shell, &chain_config.configs)?; // Initialize contracts config - let mut contracts_config = ContractsConfig::read(shell, &init_args.contracts_path)?; + let mut contracts_config = ContractsConfig::read(shell, &init_args.ecosystem_contracts_path)?; contracts_config.l1.diamond_proxy_addr = Address::zero(); contracts_config.l1.governance_addr = Address::zero(); contracts_config.l1.chain_admin_addr = Address::zero(); 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 ac5ff99f2a15..0e7f6d4b2676 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -1,7 +1,9 @@ use anyhow::Context; use clap::{command, Parser, Subcommand}; use common::{git, logger, spinner::Spinner}; -use config::{traits::SaveConfigWithBasePath, ChainConfig, EcosystemConfig}; +use config::{ + traits::SaveConfigWithBasePath, zkstack_config::ZkStackConfig, ChainConfig, EcosystemConfig, +}; use types::BaseToken; use xshell::Shell; @@ -54,17 +56,15 @@ pub(crate) async fn run(args: ChainInitCommand, shell: &Shell) -> anyhow::Result } async fn run_init(args: InitArgs, shell: &Shell) -> anyhow::Result<()> { - let config = EcosystemConfig::from_file(shell)?; - let chain_config = config - .load_current_chain() - .context(MSG_CHAIN_NOT_FOUND_ERR)?; - let args = args.fill_values_with_prompt(&chain_config); + let ecosystem = EcosystemConfig::from_file(shell).ok(); + let chain_config = ZkStackConfig::load_current_chain(shell).context(MSG_CHAIN_NOT_FOUND_ERR)?; + let args = args.fill_values_with_prompt(ecosystem.clone(), &chain_config)?; logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); logger::info(msg_initializing_chain("")); - git::submodule_update(shell, config.link_to_code.clone())?; + git::submodule_update(shell, chain_config.link_to_code.clone())?; - init(&args, shell, &config, &chain_config).await?; + init(&args, shell, &ecosystem.unwrap(), &chain_config).await?; logger::success(MSG_CHAIN_INITIALIZED); Ok(()) diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs index ea44c54d2984..0a6e5d3cb895 100644 --- a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs +++ b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs @@ -347,6 +347,8 @@ async fn init_chains( if list_of_chains.len() > 1 { genesis_args.reset_db_names(); } + let ecosystem_contracts_path = + Some(ecosystem_config.get_contracts_path().display().to_string()); // Initialize chains for chain_name in &list_of_chains { logger::info(msg_initializing_chain(chain_name)); @@ -363,8 +365,10 @@ async fn init_chains( l1_rpc_url: Some(final_init_args.ecosystem.l1_rpc_url.clone()), no_port_reallocation: final_init_args.no_port_reallocation, dev: final_init_args.dev, + ecosystem_contracts_path: ecosystem_contracts_path.clone(), }; - let final_chain_init_args = chain_init_args.fill_values_with_prompt(&chain_config); + let final_chain_init_args = chain_init_args + .fill_values_with_prompt(Some(ecosystem_config.clone()), &chain_config)?; chain::init::init( &final_chain_init_args, From 72fd9414ca2d8cb8758ea1b507bd86902b77f8c8 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Thu, 7 Nov 2024 16:19:30 -0300 Subject: [PATCH 13/24] Reorder functions --- zkstack_cli/crates/config/src/chain.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zkstack_cli/crates/config/src/chain.rs b/zkstack_cli/crates/config/src/chain.rs index ef05d4a6c960..15a6128b8bc7 100644 --- a/zkstack_cli/crates/config/src/chain.rs +++ b/zkstack_cli/crates/config/src/chain.rs @@ -151,6 +151,10 @@ impl ChainConfig { config.save_with_base_path(shell, path) } + pub fn get_preexisting_ecosystem_contracts_path(&self) -> PathBuf { + get_preexisting_ecosystem_contracts_path(&self.link_to_code, self.l1_network) + } + fn get_internal(&self) -> ChainConfigInternal { ChainConfigInternal { id: self.id, @@ -171,10 +175,6 @@ impl ChainConfig { } } - pub fn get_preexisting_ecosystem_contracts_path(&self) -> PathBuf { - get_preexisting_ecosystem_contracts_path(&self.link_to_code, self.l1_network) - } - pub fn from_internal( chain_internal: ChainConfigInternal, shell: Shell, From c1793f9b4eec362e16bb28e213ef23053ee65255 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 8 Nov 2024 13:57:16 -0300 Subject: [PATCH 14/24] Fix CI --- .github/workflows/ci-core-reusable.yml | 3 +++ .../zkstack/src/commands/chain/args/init/configs.rs | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index b907cac927ed..93e06aa67761 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -271,6 +271,7 @@ jobs: --l1-rpc-url=http://localhost:8545 \ --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --server-db-name=zksync_server_localhost_validium \ + --ecosystem-contracts-path="" \ --chain validium - name: Create and initialize chain with Custom Token @@ -293,6 +294,7 @@ jobs: --l1-rpc-url=http://localhost:8545 \ --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --server-db-name=zksync_server_localhost_custom_token \ + --ecosystem-contracts-path="" \ --chain custom_token - name: Create and register chain with transactions signed "offline" @@ -351,6 +353,7 @@ jobs: --l1-rpc-url=http://localhost:8545 \ --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --server-db-name=zksync_server_localhost_consensus \ + --ecosystem-contracts-path="" \ --chain consensus - name: Export chain list to environment variable diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs index 9eca4cdaa840..1bd7f9e72af3 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs @@ -81,16 +81,16 @@ pub fn get_ecosystem_contracts_path( ecosystem: Option, chain: &ChainConfig, ) -> anyhow::Result { - let ecosystem_contracts_path = ecosystem_contracts_path.map_or_else( - || prompt_ecosystem_contracts_path(), - |path| Some(PathBuf::from(path)), - ); - let ecosystem_preexisting_configs_path = ecosystem.map_or_else( || chain.get_preexisting_ecosystem_contracts_path(), |e| e.get_preexisting_ecosystem_contracts_path(), ); + let ecosystem_contracts_path = ecosystem_contracts_path.map_or_else( + || prompt_ecosystem_contracts_path(), + |path| Some(PathBuf::from(path)), + ); + if ecosystem_contracts_path.is_none() && !ecosystem_preexisting_configs_path.exists() { anyhow::bail!(msg_ecosystem_no_found_preexisting_contract( &chain.l1_network.to_string() From b55dd6f4b2dd93936146dbe83878864bdfb82459 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 11 Nov 2024 11:49:45 -0300 Subject: [PATCH 15/24] fmt --- .../crates/zkstack/src/commands/chain/init/configs.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 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 695403102f32..7d69c884ec22 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs @@ -1,8 +1,11 @@ use anyhow::Context; use common::logger; use config::{ - copy_configs, set_l1_rpc_url, traits::ReadConfig, traits::SaveConfigWithBasePath, - update_from_chain_config, zkstack_config::ZkStackConfig, ChainConfig, ContractsConfig, + copy_configs, set_l1_rpc_url, + traits::{ReadConfig, SaveConfigWithBasePath}, + update_from_chain_config, + zkstack_config::ZkStackConfig, + ChainConfig, ContractsConfig, }; use ethers::types::Address; use xshell::Shell; From 3a65f21393fb5f674eb754079595dfd513a287a0 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 15 Nov 2024 08:42:08 -0300 Subject: [PATCH 16/24] Fix ecosystem_contracts_path --- .../zkstack/src/commands/chain/args/init/configs.rs | 7 ++++++- .../zkstack/src/commands/chain/args/init/mod.rs | 11 ++++++++--- .../crates/zkstack/src/commands/ecosystem/init.rs | 4 ++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs index 1bd7f9e72af3..6265a537173b 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs @@ -88,7 +88,12 @@ pub fn get_ecosystem_contracts_path( let ecosystem_contracts_path = ecosystem_contracts_path.map_or_else( || prompt_ecosystem_contracts_path(), - |path| Some(PathBuf::from(path)), + |path| { + if path.is_empty() { + return None; + } + Some(PathBuf::from(path)) + }, ); if ecosystem_contracts_path.is_none() && !ecosystem_preexisting_configs_path.exists() { 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 a483f89e3995..d1f24e78a972 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 @@ -90,9 +90,14 @@ impl InitArgs { }; let ecosystem_contracts_path = if self.dev { - ecosystem.map_or_else( - || chain.get_preexisting_ecosystem_contracts_path(), - |e| e.get_preexisting_ecosystem_contracts_path(), + self.ecosystem_contracts_path.map_or_else( + || { + ecosystem.map_or_else( + || chain.get_preexisting_ecosystem_contracts_path(), + |e| e.get_contracts_path(), + ) + }, + |path| PathBuf::from(path), ) } else { get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem, chain)? diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs index b09e967d31ce..98f35bd4d247 100644 --- a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs +++ b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs @@ -350,6 +350,10 @@ async fn init_chains( } let ecosystem_contracts_path = Some(ecosystem_config.get_contracts_path().display().to_string()); + logger::debug(format!( + "Ecosystem contracts path: {:?}", + ecosystem_contracts_path + )); // Initialize chains for chain_name in &list_of_chains { logger::info(msg_initializing_chain(chain_name)); From 464bdfac2151e67ea10f7881f617e31da9e7e9b8 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 15 Nov 2024 08:58:41 -0300 Subject: [PATCH 17/24] Remove ecosystem contracts path from ci --- .github/workflows/ci-core-reusable.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 64a4cc8e1585..aeaa292f0dde 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -271,7 +271,6 @@ jobs: --l1-rpc-url=http://localhost:8545 \ --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --server-db-name=zksync_server_localhost_validium \ - --ecosystem-contracts-path="" \ --chain validium - name: Create and initialize chain with Custom Token @@ -294,7 +293,6 @@ jobs: --l1-rpc-url=http://localhost:8545 \ --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --server-db-name=zksync_server_localhost_custom_token \ - --ecosystem-contracts-path="" \ --chain custom_token - name: Create and register chain with transactions signed "offline" @@ -353,7 +351,6 @@ jobs: --l1-rpc-url=http://localhost:8545 \ --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --server-db-name=zksync_server_localhost_consensus \ - --ecosystem-contracts-path="" \ --chain consensus - name: Export chain list to environment variable From 34409c54e98c4b3b48b85f232bd220c138769c6a Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 15 Nov 2024 09:17:13 -0300 Subject: [PATCH 18/24] Fix prompt when ecosystem exists --- .../crates/zkstack/src/commands/chain/args/init/mod.rs | 6 +++++- 1 file changed, 5 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 d1f24e78a972..c1bd4780c36d 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 @@ -100,7 +100,11 @@ impl InitArgs { |path| PathBuf::from(path), ) } else { - get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem, chain)? + if let Some(ecosystem) = ecosystem { + ecosystem.get_contracts_path() + } else { + get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem, chain)? + } }; Ok(InitArgsFinal { From 3cea484df55171a341201fc6ee151135118afafa Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 15 Nov 2024 09:54:49 -0300 Subject: [PATCH 19/24] lint --- zkstack_cli/crates/config/src/utils.rs | 4 ++-- zkstack_cli/crates/zkstack/completion/_zkstack.zsh | 2 ++ zkstack_cli/crates/zkstack/completion/zkstack.fish | 1 + zkstack_cli/crates/zkstack/completion/zkstack.sh | 12 ++++++++++-- .../zkstack/src/commands/chain/args/init/configs.rs | 10 ++++------ .../zkstack/src/commands/chain/args/init/mod.rs | 10 ++++------ 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/zkstack_cli/crates/config/src/utils.rs b/zkstack_cli/crates/config/src/utils.rs index 8a5712eb2bc5..e24c1570e2c9 100644 --- a/zkstack_cli/crates/config/src/utils.rs +++ b/zkstack_cli/crates/config/src/utils.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use types::L1Network; use xshell::Shell; @@ -20,7 +20,7 @@ pub fn find_file(shell: &Shell, path_buf: PathBuf, file_name: &str) -> Result PathBuf { link_to_code diff --git a/zkstack_cli/crates/zkstack/completion/_zkstack.zsh b/zkstack_cli/crates/zkstack/completion/_zkstack.zsh index 050b28b2de6a..f098717f0d02 100644 --- a/zkstack_cli/crates/zkstack/completion/_zkstack.zsh +++ b/zkstack_cli/crates/zkstack/completion/_zkstack.zsh @@ -286,6 +286,7 @@ _arguments "${_arguments_options[@]}" : \ '--server-db-name=[Server database name]:SERVER_DB_NAME:_default' \ '--deploy-paymaster=[]' \ '--l1-rpc-url=[L1 RPC URL]:L1_RPC_URL:_default' \ +'--ecosystem-contracts-path=[Ecosystem contracts path]:ECOSYSTEM_CONTRACTS_PATH:_default' \ '--chain=[Chain to use]:CHAIN:_default' \ '--resume[]' \ '-d[]' \ @@ -312,6 +313,7 @@ _arguments "${_arguments_options[@]}" : \ '--server-db-url=[Server database url without database name]:SERVER_DB_URL:_default' \ '--server-db-name=[Server database name]:SERVER_DB_NAME:_default' \ '--l1-rpc-url=[L1 RPC URL]:L1_RPC_URL:_default' \ +'--ecosystem-contracts-path=[Ecosystem contracts path]:ECOSYSTEM_CONTRACTS_PATH:_default' \ '--chain=[Chain to use]:CHAIN:_default' \ '-d[Use default database urls and names]' \ '--dev[Use default database urls and names]' \ diff --git a/zkstack_cli/crates/zkstack/completion/zkstack.fish b/zkstack_cli/crates/zkstack/completion/zkstack.fish index 665b166800f5..830a6442c9f0 100644 --- a/zkstack_cli/crates/zkstack/completion/zkstack.fish +++ b/zkstack_cli/crates/zkstack/completion/zkstack.fish @@ -187,6 +187,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 server-db-name -d 'Server database name' -r 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 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 a056c8e06ed5..12368e8f8f21 100644 --- a/zkstack_cli/crates/zkstack/completion/zkstack.sh +++ b/zkstack_cli/crates/zkstack/completion/zkstack.sh @@ -2555,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 --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 @@ -2601,6 +2601,10 @@ _zkstack() { COMPREPLY=($(compgen -f "${cur}")) return 0 ;; + --ecosystem-contracts-path) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; --chain) COMPREPLY=($(compgen -f "${cur}")) return 0 @@ -2613,7 +2617,7 @@ _zkstack() { return 0 ;; zkstack__chain__init__configs) - opts="-d -d -v -h --server-db-url --server-db-name --dev --dont-drop --l1-rpc-url --no-port-reallocation --verbose --chain --ignore-prerequisites --help" + opts="-d -d -v -h --server-db-url --server-db-name --dev --dont-drop --l1-rpc-url --no-port-reallocation --ecosystem-contracts-path --verbose --chain --ignore-prerequisites --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -2631,6 +2635,10 @@ _zkstack() { COMPREPLY=($(compgen -f "${cur}")) return 0 ;; + --ecosystem-contracts-path) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; --chain) COMPREPLY=($(compgen -f "${cur}")) return 0 diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs index 6265a537173b..d3209605ba9b 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs @@ -86,15 +86,13 @@ pub fn get_ecosystem_contracts_path( |e| e.get_preexisting_ecosystem_contracts_path(), ); - let ecosystem_contracts_path = ecosystem_contracts_path.map_or_else( - || prompt_ecosystem_contracts_path(), - |path| { + let ecosystem_contracts_path = + ecosystem_contracts_path.map_or_else(prompt_ecosystem_contracts_path, |path| { if path.is_empty() { return None; } Some(PathBuf::from(path)) - }, - ); + }); if ecosystem_contracts_path.is_none() && !ecosystem_preexisting_configs_path.exists() { anyhow::bail!(msg_ecosystem_no_found_preexisting_contract( @@ -102,7 +100,7 @@ pub fn get_ecosystem_contracts_path( )) } - Ok(ecosystem_contracts_path.unwrap_or_else(|| ecosystem_preexisting_configs_path)) + Ok(ecosystem_contracts_path.unwrap_or(ecosystem_preexisting_configs_path)) } impl InitConfigsArgsFinal { 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 c1bd4780c36d..f72899900651 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 @@ -97,14 +97,12 @@ impl InitArgs { |e| e.get_contracts_path(), ) }, - |path| PathBuf::from(path), + PathBuf::from, ) + } else if let Some(ecosystem) = ecosystem { + ecosystem.get_contracts_path() } else { - if let Some(ecosystem) = ecosystem { - ecosystem.get_contracts_path() - } else { - get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem, chain)? - } + get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem, chain)? }; Ok(InitArgsFinal { From 48490c15773e5e8da57ddabc1366dacb5a1da696 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 15 Nov 2024 13:03:31 -0300 Subject: [PATCH 20/24] Refactor distribute_eth and mint_base_token --- .../zkstack/src/commands/chain/common.rs | 96 ++++++++++--------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs index c479ee3588e2..92a2d6f2674b 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs @@ -13,33 +13,36 @@ pub async fn distribute_eth( chain_config: &ChainConfig, l1_rpc_url: String, ) -> anyhow::Result<()> { - if chain_config.wallet_creation == WalletCreation::Localhost - && chain_config.l1_network == L1Network::Localhost + if chain_config.wallet_creation != WalletCreation::Localhost + || chain_config.l1_network != L1Network::Localhost { - let spinner = Spinner::new(MSG_DISTRIBUTING_ETH_SPINNER); - let wallets = ecosystem_config.get_wallets()?; - let chain_wallets = chain_config.get_wallets_config()?; - let mut addresses = vec![ - chain_wallets.operator.address, - chain_wallets.blob_operator.address, - chain_wallets.governor.address, - ]; - if let Some(deployer) = chain_wallets.deployer { - addresses.push(deployer.address) - } - if let Some(setter) = chain_wallets.token_multiplier_setter { - addresses.push(setter.address) - } - common::ethereum::distribute_eth( - wallets.operator, - addresses, - l1_rpc_url, - chain_config.l1_network.chain_id(), - AMOUNT_FOR_DISTRIBUTION_TO_WALLETS, - ) - .await?; - spinner.finish(); + return Ok(()); } + + let spinner = Spinner::new(MSG_DISTRIBUTING_ETH_SPINNER); + let wallets = ecosystem_config.get_wallets()?; + let chain_wallets = chain_config.get_wallets_config()?; + let mut addresses = vec![ + chain_wallets.operator.address, + chain_wallets.blob_operator.address, + chain_wallets.governor.address, + ]; + if let Some(deployer) = chain_wallets.deployer { + addresses.push(deployer.address); + } + if let Some(setter) = chain_wallets.token_multiplier_setter { + addresses.push(setter.address); + } + common::ethereum::distribute_eth( + wallets.operator, + addresses, + l1_rpc_url, + chain_config.l1_network.chain_id(), + AMOUNT_FOR_DISTRIBUTION_TO_WALLETS, + ) + .await?; + spinner.finish(); + Ok(()) } @@ -48,27 +51,30 @@ pub async fn mint_base_token( chain_config: &ChainConfig, l1_rpc_url: String, ) -> anyhow::Result<()> { - if chain_config.wallet_creation == WalletCreation::Localhost - && chain_config.l1_network == L1Network::Localhost - && chain_config.base_token != BaseToken::eth() + if chain_config.wallet_creation != WalletCreation::Localhost + || chain_config.l1_network != L1Network::Localhost + || chain_config.base_token == BaseToken::eth() { - let spinner = Spinner::new(MSG_MINT_BASE_TOKEN_SPINNER); - let wallets = ecosystem_config.get_wallets()?; - let chain_wallets = chain_config.get_wallets_config()?; - let base_token = &chain_config.base_token; - let addresses = vec![wallets.governor.address, chain_wallets.governor.address]; - let amount = AMOUNT_FOR_DISTRIBUTION_TO_WALLETS * base_token.nominator as u128 - / base_token.denominator as u128; - common::ethereum::mint_token( - wallets.governor, - base_token.address, - addresses, - l1_rpc_url, - chain_config.l1_network.chain_id(), - amount, - ) - .await?; - spinner.finish(); + return Ok(()); } + + let spinner = Spinner::new(MSG_MINT_BASE_TOKEN_SPINNER); + let wallets = ecosystem_config.get_wallets()?; + let chain_wallets = chain_config.get_wallets_config()?; + let base_token = &chain_config.base_token; + let addresses = vec![wallets.governor.address, chain_wallets.governor.address]; + let amount = AMOUNT_FOR_DISTRIBUTION_TO_WALLETS * base_token.nominator as u128 + / base_token.denominator as u128; + common::ethereum::mint_token( + wallets.governor, + base_token.address, + addresses, + l1_rpc_url, + chain_config.l1_network.chain_id(), + amount, + ) + .await?; + spinner.finish(); + Ok(()) } From 4b83c2a8c3e41b038b8c9270214c21babb7d58e6 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 15 Nov 2024 13:58:38 -0300 Subject: [PATCH 21/24] Add wallets_path to InitArgs --- zkstack_cli/crates/config/src/ecosystem.rs | 6 +++++- .../src/commands/chain/args/init/mod.rs | 21 ++++++++++++++++--- .../zkstack/src/commands/chain/common.rs | 15 +++++++------ .../zkstack/src/commands/chain/init/mod.rs | 9 +++++--- .../zkstack/src/commands/ecosystem/init.rs | 2 ++ zkstack_cli/crates/zkstack/src/messages.rs | 3 +++ 6 files changed, 43 insertions(+), 13 deletions(-) diff --git a/zkstack_cli/crates/config/src/ecosystem.rs b/zkstack_cli/crates/config/src/ecosystem.rs index 5bd11d9d683f..3bc05ac4e0bf 100644 --- a/zkstack_cli/crates/config/src/ecosystem.rs +++ b/zkstack_cli/crates/config/src/ecosystem.rs @@ -197,7 +197,7 @@ impl EcosystemConfig { } pub fn get_wallets(&self) -> anyhow::Result { - let path = self.config.join(WALLETS_FILE); + let path = self.get_wallets_path(); if self.get_shell().path_exists(&path) { return WalletsConfig::read(self.get_shell(), &path); } @@ -276,6 +276,10 @@ impl EcosystemConfig { pub fn get_contracts_path(&self) -> PathBuf { self.config.join(CONTRACTS_FILE) } + + pub fn get_wallets_path(&self) -> PathBuf { + self.config.join(WALLETS_FILE) + } } /// Result of checking if the ecosystem exists. 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 f72899900651..f2c8444fd292 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, } @@ -92,19 +95,29 @@ impl InitArgs { let ecosystem_contracts_path = if self.dev { self.ecosystem_contracts_path.map_or_else( || { - ecosystem.map_or_else( + ecosystem.as_ref().map_or_else( || chain.get_preexisting_ecosystem_contracts_path(), |e| e.get_contracts_path(), ) }, PathBuf::from, ) - } else if let Some(ecosystem) = ecosystem { + } else if let Some(ecosystem) = &ecosystem { ecosystem.get_contracts_path() } else { - get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem, chain)? + 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).allow_empty().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 +125,7 @@ impl InitArgs { l1_rpc_url, no_port_reallocation: self.no_port_reallocation, ecosystem_contracts_path, + wallets_path, dev: self.dev, }) } @@ -125,5 +139,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/common.rs b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs index 92a2d6f2674b..0b41ab5b5529 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs @@ -1,17 +1,20 @@ +use anyhow::Context; use common::spinner::Spinner; -use config::{ChainConfig, EcosystemConfig}; +use config::{ChainConfig, WalletsConfig}; use types::{BaseToken, L1Network, WalletCreation}; use crate::{ consts::AMOUNT_FOR_DISTRIBUTION_TO_WALLETS, - messages::{MSG_DISTRIBUTING_ETH_SPINNER, MSG_MINT_BASE_TOKEN_SPINNER}, + messages::{ + MSG_DISTRIBUTING_ETH_SPINNER, MSG_MINT_BASE_TOKEN_SPINNER, MSG_MISSING_WALLETS_CONFIG, + }, }; // Distribute eth to the chain wallets for localhost environment pub async fn distribute_eth( - ecosystem_config: &EcosystemConfig, chain_config: &ChainConfig, l1_rpc_url: String, + wallets: Option, ) -> anyhow::Result<()> { if chain_config.wallet_creation != WalletCreation::Localhost || chain_config.l1_network != L1Network::Localhost @@ -20,7 +23,7 @@ pub async fn distribute_eth( } let spinner = Spinner::new(MSG_DISTRIBUTING_ETH_SPINNER); - let wallets = ecosystem_config.get_wallets()?; + let wallets = wallets.context(MSG_MISSING_WALLETS_CONFIG)?; let chain_wallets = chain_config.get_wallets_config()?; let mut addresses = vec![ chain_wallets.operator.address, @@ -47,9 +50,9 @@ pub async fn distribute_eth( } pub async fn mint_base_token( - ecosystem_config: &EcosystemConfig, chain_config: &ChainConfig, l1_rpc_url: String, + wallets: Option, ) -> anyhow::Result<()> { if chain_config.wallet_creation != WalletCreation::Localhost || chain_config.l1_network != L1Network::Localhost @@ -59,7 +62,7 @@ pub async fn mint_base_token( } let spinner = Spinner::new(MSG_MINT_BASE_TOKEN_SPINNER); - let wallets = ecosystem_config.get_wallets()?; + let wallets = wallets.context(MSG_MISSING_WALLETS_CONFIG)?; let chain_wallets = chain_config.get_wallets_config()?; let base_token = &chain_config.base_token; let addresses = vec![wallets.governor.address, chain_wallets.governor.address]; 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 3e804a673068..145c442aa8b0 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -2,7 +2,9 @@ use anyhow::Context; use clap::{command, Parser, Subcommand}; use common::{git, logger, spinner::Spinner}; use config::{ - traits::SaveConfigWithBasePath, zkstack_config::ZkStackConfig, ChainConfig, EcosystemConfig, + traits::{ReadConfig, SaveConfigWithBasePath}, + zkstack_config::ZkStackConfig, + ChainConfig, EcosystemConfig, WalletsConfig, }; use types::BaseToken; use xshell::Shell; @@ -81,8 +83,9 @@ pub async fn init( let mut contracts_config = init_configs(&init_configs_args, shell, chain_config).await?; // Fund some wallet addresses with ETH or base token (only for Localhost) - distribute_eth(ecosystem_config, chain_config, init_args.l1_rpc_url.clone()).await?; - mint_base_token(ecosystem_config, chain_config, init_args.l1_rpc_url.clone()).await?; + let wallets = WalletsConfig::read(shell, init_args.wallets_path.clone()).ok(); + distribute_eth(chain_config, init_args.l1_rpc_url.clone(), wallets.clone()).await?; + mint_base_token(chain_config, init_args.l1_rpc_url.clone(), wallets).await?; // Register chain on BridgeHub (run by L1 Governor) let spinner = Spinner::new(MSG_REGISTERING_CHAIN_SPINNER); diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs index 98f35bd4d247..2f107d9547ba 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)?; diff --git a/zkstack_cli/crates/zkstack/src/messages.rs b/zkstack_cli/crates/zkstack/src/messages.rs index 1a6fdb5939a4..29f1b9e193f8 100644 --- a/zkstack_cli/crates/zkstack/src/messages.rs +++ b/zkstack_cli/crates/zkstack/src/messages.rs @@ -62,6 +62,7 @@ pub(super) fn msg_path_to_zksync_does_not_exist_err(path: &str) -> String { /// Ecosystem and chain init related messages pub(super) const MSG_ECOSYSTEM_CONTRACTS_PATH_HELP: &str = "Ecosystem contracts path"; +pub(super) const MSG_WALLETS_PATH_HELP: &str = "Wallets path"; pub(super) const MSG_L1_RPC_URL_HELP: &str = "L1 RPC URL"; pub(super) const MSG_NO_PORT_REALLOCATION_HELP: &str = "Do not reallocate ports"; pub(super) const MSG_GENESIS_ARGS_HELP: &str = "Genesis options"; @@ -103,6 +104,8 @@ pub(super) const MSG_RECREATE_ROCKS_DB_ERRROR: &str = "Failed to create rocks db pub(super) const MSG_ERA_OBSERVABILITY_ALREADY_SETUP: &str = "Era observability already setup"; pub(super) const MSG_DOWNLOADING_ERA_OBSERVABILITY_SPINNER: &str = "Downloading era observability..."; +pub(super) const MSG_MISSING_WALLETS_CONFIG: &str = "Missing wallets config"; +pub(super) const MSG_WALLETS_PATH_PROMPT: &str = "Provide the path to the wallets"; pub(super) fn msg_ecosystem_no_found_preexisting_contract(chains: &str) -> String { format!("Not found preexisting ecosystem Contracts with chains {chains}") From a42517c6df0c77e22142a2ed2b9743ca3aa7a57e Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 15 Nov 2024 13:58:46 -0300 Subject: [PATCH 22/24] lint --- zkstack_cli/crates/zkstack/completion/_zkstack.zsh | 1 + zkstack_cli/crates/zkstack/completion/zkstack.fish | 1 + zkstack_cli/crates/zkstack/completion/zkstack.sh | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/zkstack_cli/crates/zkstack/completion/_zkstack.zsh b/zkstack_cli/crates/zkstack/completion/_zkstack.zsh index f098717f0d02..70696214a9bf 100644 --- a/zkstack_cli/crates/zkstack/completion/_zkstack.zsh +++ b/zkstack_cli/crates/zkstack/completion/_zkstack.zsh @@ -287,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 830a6442c9f0..407ab8d9c248 100644 --- a/zkstack_cli/crates/zkstack/completion/zkstack.fish +++ b/zkstack_cli/crates/zkstack/completion/zkstack.fish @@ -188,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 12368e8f8f21..005269444d7f 100644 --- a/zkstack_cli/crates/zkstack/completion/zkstack.sh +++ b/zkstack_cli/crates/zkstack/completion/zkstack.sh @@ -2555,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 @@ -2605,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 From a43532f46870f0af058c12a77e1f66c13b9d27db Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 15 Nov 2024 14:02:46 -0300 Subject: [PATCH 23/24] Make wallets_path non optional --- .../zkstack/src/commands/chain/args/init/mod.rs | 6 ++---- .../crates/zkstack/src/commands/chain/common.rs | 15 +++++---------- .../crates/zkstack/src/commands/chain/init/mod.rs | 6 +++--- zkstack_cli/crates/zkstack/src/messages.rs | 1 - 4 files changed, 10 insertions(+), 18 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 f2c8444fd292..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 @@ -110,10 +110,8 @@ impl InitArgs { let wallets_path = ecosystem.map_or_else( || { - self.wallets_path.map_or_else( - || Prompt::new(MSG_WALLETS_PATH_PROMPT).allow_empty().ask(), - PathBuf::from, - ) + self.wallets_path + .map_or_else(|| Prompt::new(MSG_WALLETS_PATH_PROMPT).ask(), PathBuf::from) }, |e| e.get_wallets_path(), ); diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs index 0b41ab5b5529..c14e140679c5 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs @@ -1,20 +1,17 @@ -use anyhow::Context; use common::spinner::Spinner; use config::{ChainConfig, WalletsConfig}; use types::{BaseToken, L1Network, WalletCreation}; use crate::{ consts::AMOUNT_FOR_DISTRIBUTION_TO_WALLETS, - messages::{ - MSG_DISTRIBUTING_ETH_SPINNER, MSG_MINT_BASE_TOKEN_SPINNER, MSG_MISSING_WALLETS_CONFIG, - }, + messages::{MSG_DISTRIBUTING_ETH_SPINNER, MSG_MINT_BASE_TOKEN_SPINNER}, }; // Distribute eth to the chain wallets for localhost environment pub async fn distribute_eth( chain_config: &ChainConfig, l1_rpc_url: String, - wallets: Option, + wallets: &WalletsConfig, ) -> anyhow::Result<()> { if chain_config.wallet_creation != WalletCreation::Localhost || chain_config.l1_network != L1Network::Localhost @@ -23,7 +20,6 @@ pub async fn distribute_eth( } let spinner = Spinner::new(MSG_DISTRIBUTING_ETH_SPINNER); - let wallets = wallets.context(MSG_MISSING_WALLETS_CONFIG)?; let chain_wallets = chain_config.get_wallets_config()?; let mut addresses = vec![ chain_wallets.operator.address, @@ -37,7 +33,7 @@ pub async fn distribute_eth( addresses.push(setter.address); } common::ethereum::distribute_eth( - wallets.operator, + wallets.operator.clone(), addresses, l1_rpc_url, chain_config.l1_network.chain_id(), @@ -52,7 +48,7 @@ pub async fn distribute_eth( pub async fn mint_base_token( chain_config: &ChainConfig, l1_rpc_url: String, - wallets: Option, + wallets: &WalletsConfig, ) -> anyhow::Result<()> { if chain_config.wallet_creation != WalletCreation::Localhost || chain_config.l1_network != L1Network::Localhost @@ -62,14 +58,13 @@ pub async fn mint_base_token( } let spinner = Spinner::new(MSG_MINT_BASE_TOKEN_SPINNER); - let wallets = wallets.context(MSG_MISSING_WALLETS_CONFIG)?; let chain_wallets = chain_config.get_wallets_config()?; let base_token = &chain_config.base_token; let addresses = vec![wallets.governor.address, chain_wallets.governor.address]; let amount = AMOUNT_FOR_DISTRIBUTION_TO_WALLETS * base_token.nominator as u128 / base_token.denominator as u128; common::ethereum::mint_token( - wallets.governor, + wallets.governor.clone(), base_token.address, addresses, l1_rpc_url, 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 145c442aa8b0..10e4a40de330 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -83,9 +83,9 @@ pub async fn init( let mut contracts_config = init_configs(&init_configs_args, shell, chain_config).await?; // Fund some wallet addresses with ETH or base token (only for Localhost) - let wallets = WalletsConfig::read(shell, init_args.wallets_path.clone()).ok(); - distribute_eth(chain_config, init_args.l1_rpc_url.clone(), wallets.clone()).await?; - mint_base_token(chain_config, init_args.l1_rpc_url.clone(), wallets).await?; + let wallets = WalletsConfig::read(shell, init_args.wallets_path.clone())?; + distribute_eth(chain_config, init_args.l1_rpc_url.clone(), &wallets).await?; + mint_base_token(chain_config, init_args.l1_rpc_url.clone(), &wallets).await?; // Register chain on BridgeHub (run by L1 Governor) let spinner = Spinner::new(MSG_REGISTERING_CHAIN_SPINNER); diff --git a/zkstack_cli/crates/zkstack/src/messages.rs b/zkstack_cli/crates/zkstack/src/messages.rs index 29f1b9e193f8..59ac3b0970da 100644 --- a/zkstack_cli/crates/zkstack/src/messages.rs +++ b/zkstack_cli/crates/zkstack/src/messages.rs @@ -104,7 +104,6 @@ pub(super) const MSG_RECREATE_ROCKS_DB_ERRROR: &str = "Failed to create rocks db pub(super) const MSG_ERA_OBSERVABILITY_ALREADY_SETUP: &str = "Era observability already setup"; pub(super) const MSG_DOWNLOADING_ERA_OBSERVABILITY_SPINNER: &str = "Downloading era observability..."; -pub(super) const MSG_MISSING_WALLETS_CONFIG: &str = "Missing wallets config"; pub(super) const MSG_WALLETS_PATH_PROMPT: &str = "Provide the path to the wallets"; pub(super) fn msg_ecosystem_no_found_preexisting_contract(chains: &str) -> String { From 542df9117f85ffb0180839c52796dc64b40e869b Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 15 Nov 2024 14:06:59 -0300 Subject: [PATCH 24/24] Add wallets to register_chain --- .../zkstack/src/commands/chain/build_transactions.rs | 5 +++-- .../crates/zkstack/src/commands/chain/init/mod.rs | 4 ++-- .../crates/zkstack/src/commands/chain/register_chain.rs | 9 +++++---- 3 files changed, 10 insertions(+), 8 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 5af70ec176e9..98954b56197e 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/build_transactions.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/build_transactions.rs @@ -53,14 +53,15 @@ pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::R spinner.finish(); let spinner = Spinner::new(MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER); - let governor: String = config.get_wallets()?.governor.address.encode_hex_upper(); + let wallets = chain_config.get_wallets_config()?; + let governor: String = wallets.governor.address.encode_hex_upper(); register_chain( shell, args.forge_args.clone(), - &config, &chain_config, &mut contracts_config, + &wallets, args.l1_rpc_url.clone(), Some(governor), false, 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 10e4a40de330..d7f087ea1e94 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -81,9 +81,9 @@ pub async fn init( // Initialize configs let init_configs_args = InitConfigsArgsFinal::from_chain_init_args(init_args); let mut contracts_config = init_configs(&init_configs_args, shell, chain_config).await?; + let wallets = WalletsConfig::read(shell, init_args.wallets_path.clone())?; // Fund some wallet addresses with ETH or base token (only for Localhost) - let wallets = WalletsConfig::read(shell, init_args.wallets_path.clone())?; distribute_eth(chain_config, init_args.l1_rpc_url.clone(), &wallets).await?; mint_base_token(chain_config, init_args.l1_rpc_url.clone(), &wallets).await?; @@ -92,9 +92,9 @@ pub async fn init( register_chain( shell, init_args.forge_args.clone(), - ecosystem_config, chain_config, &mut contracts_config, + &wallets, init_args.l1_rpc_url.clone(), None, true, diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs b/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs index 02e3f76d1aa9..5158d8e882ed 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs @@ -11,7 +11,7 @@ use config::{ }, traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, zkstack_config::ZkStackConfig, - ChainConfig, ContractsConfig, EcosystemConfig, + ChainConfig, ContractsConfig, WalletsConfig, }; use xshell::Shell; @@ -29,6 +29,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { .load_current_chain() .context(MSG_CHAIN_NOT_INITIALIZED)?; let mut contracts = chain_config.get_contracts_config()?; + let wallets = chain_config.get_wallets_config()?; let secrets = chain_config.get_secrets_config()?; let l1_rpc_url = secrets .l1 @@ -40,9 +41,9 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { register_chain( shell, args, - &ecosystem_config, &chain_config, &mut contracts, + &wallets, l1_rpc_url, None, true, @@ -58,9 +59,9 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { pub async fn register_chain( shell: &Shell, forge_args: ForgeScriptArgs, - config: &EcosystemConfig, chain_config: &ChainConfig, contracts: &mut ContractsConfig, + wallets: &WalletsConfig, l1_rpc_url: String, sender: Option, broadcast: bool, @@ -82,7 +83,7 @@ pub async fn register_chain( if let Some(address) = sender { forge = forge.with_sender(address); } else { - forge = fill_forge_private_key(forge, Some(&config.get_wallets()?.governor))?; + forge = fill_forge_private_key(forge, Some(&wallets.governor))?; check_the_balance(&forge).await?; }