diff --git a/zkstack_cli/crates/zkstack/src/accept_ownership.rs b/zkstack_cli/crates/zkstack/src/accept_ownership.rs index 474e76e599a8..73dfd8082708 100644 --- a/zkstack_cli/crates/zkstack/src/accept_ownership.rs +++ b/zkstack_cli/crates/zkstack/src/accept_ownership.rs @@ -10,7 +10,7 @@ use xshell::Shell; use crate::{ messages::MSG_ACCEPTING_GOVERNANCE_SPINNER, - utils::forge::{check_the_balance, fill_forge_private_key}, + utils::forge::{check_the_balance, fill_forge_private_key, WalletOwner}, }; lazy_static! { @@ -89,7 +89,7 @@ async fn accept_ownership( governor: &Wallet, mut forge: ForgeScript, ) -> anyhow::Result<()> { - forge = fill_forge_private_key(forge, Some(governor))?; + forge = fill_forge_private_key(forge, Some(governor), WalletOwner::Governor)?; check_the_balance(&forge).await?; let spinner = Spinner::new(MSG_ACCEPTING_GOVERNANCE_SPINNER); forge.run(shell)?; 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 31cfc7f83977..4164f9a05a2a 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 @@ -27,7 +27,7 @@ use crate::{ MSG_CHAIN_NOT_INITIALIZED, MSG_DEPLOYING_L2_CONTRACT_SPINNER, MSG_L1_SECRETS_MUST_BE_PRESENTED, }, - utils::forge::{check_the_balance, fill_forge_private_key}, + utils::forge::{check_the_balance, fill_forge_private_key, WalletOwner}, }; pub enum Deploy2ContractsOption { @@ -311,7 +311,11 @@ async fn call_forge( forge = forge.with_signature(signature); } - forge = fill_forge_private_key(forge, Some(&ecosystem_config.get_wallets()?.governor))?; + forge = fill_forge_private_key( + forge, + Some(&ecosystem_config.get_wallets()?.governor), + WalletOwner::Governor, + )?; check_the_balance(&forge).await?; forge.run(shell)?; diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/deploy_paymaster.rs b/zkstack_cli/crates/zkstack/src/commands/chain/deploy_paymaster.rs index 4a93fcc089f8..4bcfd6c08099 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/deploy_paymaster.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/deploy_paymaster.rs @@ -12,7 +12,7 @@ use xshell::Shell; use crate::{ messages::{MSG_CHAIN_NOT_INITIALIZED, MSG_L1_SECRETS_MUST_BE_PRESENTED}, - utils::forge::{check_the_balance, fill_forge_private_key}, + utils::forge::{check_the_balance, fill_forge_private_key, WalletOwner}, }; pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { @@ -56,7 +56,11 @@ pub async fn deploy_paymaster( if let Some(address) = sender { forge = forge.with_sender(address); } else { - forge = fill_forge_private_key(forge, Some(&chain_config.get_wallets_config()?.governor))?; + forge = fill_forge_private_key( + forge, + Some(&chain_config.get_wallets_config()?.governor), + WalletOwner::Governor, + )?; } if broadcast { 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..42b3bbd59c71 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs @@ -19,7 +19,7 @@ use crate::{ MSG_CHAIN_NOT_INITIALIZED, MSG_CHAIN_REGISTERED, MSG_L1_SECRETS_MUST_BE_PRESENTED, MSG_REGISTERING_CHAIN_SPINNER, }, - utils::forge::{check_the_balance, fill_forge_private_key}, + utils::forge::{check_the_balance, fill_forge_private_key, WalletOwner}, }; pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { @@ -81,7 +81,11 @@ 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(&config.get_wallets()?.governor), + WalletOwner::Governor, + )?; check_the_balance(&forge).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 4a6cd31b2c0a..326aa393f8f2 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 @@ -17,7 +17,7 @@ use crate::{ 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}, + utils::forge::{check_the_balance, fill_forge_private_key, WalletOwner}, }; lazy_static! { @@ -109,7 +109,7 @@ async fn update_token_multiplier_setter( governor: &Wallet, mut forge: ForgeScript, ) -> anyhow::Result<()> { - forge = fill_forge_private_key(forge, Some(governor))?; + forge = fill_forge_private_key(forge, Some(governor), WalletOwner::Governor)?; check_the_balance(&forge).await?; forge.run(shell)?; Ok(()) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/setup_legacy_bridge.rs b/zkstack_cli/crates/zkstack/src/commands/chain/setup_legacy_bridge.rs index f61c640ffb6b..a05ef04eee3e 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/setup_legacy_bridge.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/setup_legacy_bridge.rs @@ -14,7 +14,7 @@ use xshell::Shell; use crate::{ messages::{MSG_DEPLOYING_PAYMASTER, MSG_L1_SECRETS_MUST_BE_PRESENTED}, - utils::forge::{check_the_balance, fill_forge_private_key}, + utils::forge::{check_the_balance, fill_forge_private_key, WalletOwner}, }; pub async fn setup_legacy_bridge( @@ -59,7 +59,11 @@ pub async fn setup_legacy_bridge( ) .with_broadcast(); - forge = fill_forge_private_key(forge, Some(&ecosystem_config.get_wallets()?.governor))?; + forge = fill_forge_private_key( + forge, + Some(&ecosystem_config.get_wallets()?.governor), + WalletOwner::Governor, + )?; let spinner = Spinner::new(MSG_DEPLOYING_PAYMASTER); check_the_balance(&forge).await?; diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/common.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/common.rs index 00d937bba294..074913d79fa2 100644 --- a/zkstack_cli/crates/zkstack/src/commands/ecosystem/common.rs +++ b/zkstack_cli/crates/zkstack/src/commands/ecosystem/common.rs @@ -14,7 +14,7 @@ use config::{ use types::{L1Network, ProverMode}; use xshell::Shell; -use crate::utils::forge::{check_the_balance, fill_forge_private_key}; +use crate::utils::forge::{check_the_balance, fill_forge_private_key, WalletOwner}; pub async fn deploy_l1( shell: &Shell, @@ -54,7 +54,11 @@ pub async fn deploy_l1( if let Some(address) = sender { forge = forge.with_sender(address); } else { - forge = fill_forge_private_key(forge, wallets_config.deployer.as_ref())?; + forge = fill_forge_private_key( + forge, + wallets_config.deployer.as_ref(), + WalletOwner::Deployer, + )?; } if broadcast { diff --git a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs index 06b9b9161112..7b01abf03b9a 100644 --- a/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs +++ b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs @@ -43,7 +43,7 @@ use crate::{ MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, MSG_INITIALIZING_ECOSYSTEM, MSG_INTALLING_DEPS_SPINNER, }, - utils::forge::{check_the_balance, fill_forge_private_key}, + utils::forge::{check_the_balance, fill_forge_private_key, WalletOwner}, }; pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> { @@ -150,7 +150,11 @@ async fn deploy_erc20( .with_rpc_url(l1_rpc_url) .with_broadcast(); - forge = fill_forge_private_key(forge, ecosystem_config.get_wallets()?.deployer.as_ref())?; + forge = fill_forge_private_key( + forge, + ecosystem_config.get_wallets()?.deployer.as_ref(), + WalletOwner::Deployer, + )?; let spinner = Spinner::new(MSG_DEPLOYING_ERC20_SPINNER); check_the_balance(&forge).await?; diff --git a/zkstack_cli/crates/zkstack/src/messages.rs b/zkstack_cli/crates/zkstack/src/messages.rs index bedcb233b19f..14b89be773f1 100644 --- a/zkstack_cli/crates/zkstack/src/messages.rs +++ b/zkstack_cli/crates/zkstack/src/messages.rs @@ -7,6 +7,8 @@ use ethers::{ use url::Url; use zksync_consensus_roles::attester; +use crate::utils::forge::WalletOwner; + pub(super) const MSG_SETUP_KEYS_DOWNLOAD_SELECTION_PROMPT: &str = "Do you want to download the setup keys or generate them?"; pub(super) const MSG_SETUP_KEYS_REGION_PROMPT: &str = @@ -334,7 +336,15 @@ pub(super) fn msg_explorer_chain_not_initialized(chain: &str) -> String { } /// Forge utils related messages -pub(super) const MSG_DEPLOYER_PK_NOT_SET_ERR: &str = "Deployer private key is not set"; +pub(super) fn msg_wallet_private_key_not_set(wallet_owner: WalletOwner) -> String { + format!( + "{} private key is not set", + match wallet_owner { + WalletOwner::Governor => "Governor", + WalletOwner::Deployer => "Deployer", + } + ) +} pub(super) fn msg_address_doesnt_have_enough_money_prompt( address: &H160, diff --git a/zkstack_cli/crates/zkstack/src/utils/forge.rs b/zkstack_cli/crates/zkstack/src/utils/forge.rs index 355cf7b5f930..76f045f82b9e 100644 --- a/zkstack_cli/crates/zkstack/src/utils/forge.rs +++ b/zkstack_cli/crates/zkstack/src/utils/forge.rs @@ -4,18 +4,24 @@ use ethers::types::U256; use crate::{ consts::MINIMUM_BALANCE_FOR_WALLET, - messages::{msg_address_doesnt_have_enough_money_prompt, MSG_DEPLOYER_PK_NOT_SET_ERR}, + messages::{msg_address_doesnt_have_enough_money_prompt, msg_wallet_private_key_not_set}, }; +pub enum WalletOwner { + Governor, + Deployer, +} + pub fn fill_forge_private_key( mut forge: ForgeScript, wallet: Option<&Wallet>, + wallet_owner: WalletOwner, ) -> anyhow::Result { if !forge.wallet_args_passed() { forge = forge.with_private_key( wallet .and_then(|w| w.private_key_h256()) - .context(MSG_DEPLOYER_PK_NOT_SET_ERR)?, + .context(msg_wallet_private_key_not_set(wallet_owner))?, ); } Ok(forge)