-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zk_toolbox): Implement default upgrader deployment
Signed-off-by: Danil <[email protected]>
- Loading branch information
1 parent
a12699a
commit 1812312
Showing
12 changed files
with
260 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
pub mod accept_ownership; | ||
pub mod deploy_ecosystem; | ||
pub mod initialize_bridges; | ||
pub mod deploy_l2_contracts; | ||
pub mod paymaster; | ||
pub mod register_chain; | ||
pub mod script_params; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 212 additions & 0 deletions
212
zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
use std::path::Path; | ||
|
||
use anyhow::Context; | ||
use common::{ | ||
cmd::Cmd, | ||
config::global_config, | ||
forge::{Forge, ForgeScriptArgs}, | ||
spinner::Spinner, | ||
}; | ||
use config::{ | ||
forge_interface::{ | ||
deploy_l2_contracts::{ | ||
input::DeployL2ContractsInput, | ||
output::{DefaultL2UpgradeOutput, InitializeBridgeOutput}, | ||
}, | ||
script_params::DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS, | ||
}, | ||
traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, | ||
ChainConfig, ContractsConfig, EcosystemConfig, | ||
}; | ||
use xshell::{cmd, Shell}; | ||
|
||
use crate::{ | ||
messages::{ | ||
MSG_CHAIN_NOT_INITIALIZED, MSG_DEPLOYING_L2_CONTRACT_SPINNER, | ||
MSG_L1_SECRETS_MUST_BE_PRESENTED, | ||
}, | ||
utils::forge::{check_the_balance, fill_forge_private_key}, | ||
}; | ||
|
||
pub enum Deploy2ContractsOption { | ||
All, | ||
Upgrader, | ||
IntiailizeBridges, | ||
} | ||
|
||
pub async fn run( | ||
args: ForgeScriptArgs, | ||
shell: &Shell, | ||
deploy_option: Deploy2ContractsOption, | ||
) -> anyhow::Result<()> { | ||
let chain_name = global_config().chain_name.clone(); | ||
let ecosystem_config = EcosystemConfig::from_file(shell)?; | ||
let chain_config = ecosystem_config | ||
.load_chain(chain_name) | ||
.context(MSG_CHAIN_NOT_INITIALIZED)?; | ||
|
||
let mut contracts = chain_config.get_contracts_config()?; | ||
|
||
let spinner = Spinner::new(MSG_DEPLOYING_L2_CONTRACT_SPINNER); | ||
|
||
match deploy_option { | ||
Deploy2ContractsOption::All => { | ||
deploy_l2_contracts( | ||
shell, | ||
&chain_config, | ||
&ecosystem_config, | ||
&mut contracts, | ||
args, | ||
) | ||
.await?; | ||
} | ||
Deploy2ContractsOption::Upgrader => { | ||
deploy_upgrader( | ||
shell, | ||
&chain_config, | ||
&ecosystem_config, | ||
&mut contracts, | ||
args, | ||
) | ||
.await?; | ||
} | ||
Deploy2ContractsOption::IntiailizeBridges => initialize_bridges( | ||
shell, | ||
&chain_config, | ||
&ecosystem_config, | ||
&mut contracts, | ||
args, | ||
), | ||
} | ||
|
||
contracts.save_with_base_path(shell, &chain_config.configs)?; | ||
spinner.finish(); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub async fn initialize_bridges( | ||
shell: &Shell, | ||
chain_config: &ChainConfig, | ||
ecosystem_config: &EcosystemConfig, | ||
contracts_config: &mut ContractsConfig, | ||
forge_args: ForgeScriptArgs, | ||
) -> anyhow::Result<()> { | ||
build_l2_contracts(shell, &ecosystem_config.link_to_code)?; | ||
call_forge( | ||
shell, | ||
chain_config, | ||
ecosystem_config, | ||
forge_args, | ||
Some("runDeploySharedBridge"), | ||
) | ||
.await?; | ||
let output = InitializeBridgeOutput::read( | ||
shell, | ||
DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code), | ||
)?; | ||
|
||
contracts_config.set_l2_shared_bridge(&output)?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn deploy_upgrader( | ||
shell: &Shell, | ||
chain_config: &ChainConfig, | ||
ecosystem_config: &EcosystemConfig, | ||
contracts_config: &mut ContractsConfig, | ||
forge_args: ForgeScriptArgs, | ||
) -> anyhow::Result<()> { | ||
build_l2_contracts(shell, &ecosystem_config.link_to_code)?; | ||
call_forge( | ||
shell, | ||
chain_config, | ||
ecosystem_config, | ||
forge_args, | ||
Some("runDefaultUpgrader"), | ||
) | ||
.await?; | ||
let output = DefaultL2UpgradeOutput::read( | ||
shell, | ||
DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code), | ||
)?; | ||
|
||
contracts_config.set_default_l2_upgrade(&output)?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn deploy_l2_contracts( | ||
shell: &Shell, | ||
chain_config: &ChainConfig, | ||
ecosystem_config: &EcosystemConfig, | ||
contracts_config: &mut ContractsConfig, | ||
forge_args: ForgeScriptArgs, | ||
) -> anyhow::Result<()> { | ||
build_l2_contracts(shell, &ecosystem_config.link_to_code)?; | ||
call_forge(shell, chain_config, ecosystem_config, forge_args, None).await?; | ||
let output = InitializeBridgeOutput::read( | ||
shell, | ||
DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code), | ||
)?; | ||
|
||
contracts_config.set_l2_shared_bridge(&output)?; | ||
|
||
let output = DefaultL2UpgradeOutput::read( | ||
shell, | ||
DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code), | ||
)?; | ||
|
||
contracts_config.set_default_l2_upgrade(&output)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn call_forge( | ||
shell: &Shell, | ||
chain_config: &ChainConfig, | ||
ecosystem_config: &EcosystemConfig, | ||
forge_args: ForgeScriptArgs, | ||
signature: Option<&str>, | ||
) -> anyhow::Result<()> { | ||
let input = DeployL2ContractsInput::new(chain_config, ecosystem_config.era_chain_id)?; | ||
let foundry_contracts_path = chain_config.path_to_foundry(); | ||
let secrets = chain_config.get_secrets_config()?; | ||
input.save( | ||
shell, | ||
DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.input(&chain_config.link_to_code), | ||
)?; | ||
|
||
let mut forge = Forge::new(&foundry_contracts_path) | ||
.script( | ||
&DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.script(), | ||
forge_args.clone(), | ||
) | ||
.with_ffi() | ||
.with_rpc_url( | ||
secrets | ||
.l1 | ||
.context(MSG_L1_SECRETS_MUST_BE_PRESENTED)? | ||
.l1_rpc_url | ||
.expose_str() | ||
.to_string(), | ||
) | ||
.with_broadcast(); | ||
|
||
if let Some(signature) = signature { | ||
forge = forge.with_signature(signature); | ||
} | ||
|
||
forge = fill_forge_private_key( | ||
forge, | ||
ecosystem_config.get_wallets()?.governor_private_key(), | ||
)?; | ||
|
||
check_the_balance(&forge).await?; | ||
forge.run(shell)?; | ||
Ok(()) | ||
} | ||
|
||
fn build_l2_contracts(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> { | ||
let _dir_guard = shell.push_dir(link_to_code.join("contracts")); | ||
Ok(Cmd::new(cmd!(shell, "yarn l2 build")).run()?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.