Skip to content

Commit

Permalink
fix(zk-toolbox): Make token multiplier optional (matter-labs#2843)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.

Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo authored Sep 11, 2024
1 parent 3506731 commit 89fcb3a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
6 changes: 5 additions & 1 deletion zk_toolbox/crates/config/src/wallet_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ pub fn create_localhost_wallets(
blob_operator: Wallet::from_mnemonic(&eth_mnemonic.test_mnemonic, &base_path, 2)?,
fee_account: Wallet::from_mnemonic(&eth_mnemonic.test_mnemonic, &base_path, 3)?,
governor: Wallet::from_mnemonic(&eth_mnemonic.test_mnemonic, &base_path, 4)?,
token_multiplier_setter: Wallet::from_mnemonic(&eth_mnemonic.test_mnemonic, &base_path, 5)?,
token_multiplier_setter: Some(Wallet::from_mnemonic(
&eth_mnemonic.test_mnemonic,
&base_path,
5,
)?),
})
}
6 changes: 3 additions & 3 deletions zk_toolbox/crates/config/src/wallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct WalletsConfig {
pub blob_operator: Wallet,
pub fee_account: Wallet,
pub governor: Wallet,
pub token_multiplier_setter: Wallet,
pub token_multiplier_setter: Option<Wallet>,
}

impl WalletsConfig {
Expand All @@ -27,7 +27,7 @@ impl WalletsConfig {
blob_operator: Wallet::random(rng),
fee_account: Wallet::random(rng),
governor: Wallet::random(rng),
token_multiplier_setter: Wallet::random(rng),
token_multiplier_setter: Some(Wallet::random(rng)),
}
}

Expand All @@ -39,7 +39,7 @@ impl WalletsConfig {
blob_operator: Wallet::empty(),
fee_account: Wallet::empty(),
governor: Wallet::empty(),
token_multiplier_setter: Wallet::empty(),
token_multiplier_setter: Some(Wallet::empty()),
}
}
pub fn deployer_private_key(&self) -> Option<H256> {
Expand Down
37 changes: 20 additions & 17 deletions zk_toolbox/crates/zk_inception/src/commands/chain/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
MSG_CHAIN_NOT_FOUND_ERR, MSG_DISTRIBUTING_ETH_SPINNER, MSG_GENESIS_DATABASE_ERR,
MSG_MINT_BASE_TOKEN_SPINNER, MSG_PORTAL_FAILED_TO_CREATE_CONFIG_ERR,
MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG,
MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER,
MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER, MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND,
},
utils::forge::{check_the_balance, fill_forge_private_key},
};
Expand Down Expand Up @@ -112,22 +112,25 @@ pub async fn init(
.await?;
spinner.finish();

let spinner = Spinner::new(MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER);
set_token_multiplier_setter(
shell,
ecosystem_config,
chain_config.get_wallets_config()?.governor_private_key(),
contracts_config.l1.chain_admin_addr,
ecosystem_config
.get_wallets()
.unwrap()
.token_multiplier_setter
.address,
&init_args.forge_args.clone(),
init_args.l1_rpc_url.clone(),
)
.await?;
spinner.finish();
if chain_config.base_token != BaseToken::eth() {
let spinner = Spinner::new(MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER);
set_token_multiplier_setter(
shell,
ecosystem_config,
chain_config.get_wallets_config()?.governor_private_key(),
contracts_config.l1.chain_admin_addr,
chain_config
.get_wallets_config()
.unwrap()
.token_multiplier_setter
.context(MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND)?
.address,
&init_args.forge_args.clone(),
init_args.l1_rpc_url.clone(),
)
.await?;
spinner.finish();
}

deploy_l2_contracts::deploy_l2_contracts(
shell,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
messages::{
MSG_CHAIN_NOT_INITIALIZED, MSG_L1_SECRETS_MUST_BE_PRESENTED,
MSG_TOKEN_MULTIPLIER_SETTER_UPDATED_TO, MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER,
MSG_WALLETS_CONFIG_MUST_BE_PRESENT,
MSG_WALLETS_CONFIG_MUST_BE_PRESENT, MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND,
},
utils::forge::{check_the_balance, fill_forge_private_key},
};
Expand Down Expand Up @@ -47,6 +47,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
.get_wallets()
.context(MSG_WALLETS_CONFIG_MUST_BE_PRESENT)?
.token_multiplier_setter
.context(MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND)?
.address;

let spinner = Spinner::new(MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER);
Expand Down
2 changes: 2 additions & 0 deletions zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ pub(super) const MSG_CHAIN_ID_VALIDATOR_ERR: &str = "Invalid chain id";
pub(super) const MSG_BASE_TOKEN_ADDRESS_VALIDATOR_ERR: &str = "Invalid base token address";
pub(super) const MSG_WALLET_CREATION_VALIDATOR_ERR: &str =
"Localhost wallet is not supported for external networks";
pub(super) const MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND: &str =
"Token Multiplier Setter not found. Specify it in a wallet config";

/// Chain genesis related messages
pub(super) const MSG_L1_SECRETS_MUST_BE_PRESENTED: &str = "L1 secret must be presented";
Expand Down

0 comments on commit 89fcb3a

Please sign in to comment.