diff --git a/Cargo.lock b/Cargo.lock index 20bd50d..b290d5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1398,7 +1398,7 @@ dependencies = [ [[package]] name = "ethereum-instance" version = "0.1.0" -source = "git+https://github.com/karnotxyz/zaun?branch=update/core-contract-v13.2.0#8b82a9230974b8b5824d9a4dec8711101051db52" +source = "git+https://github.com/karnotxyz/zaun?rev=782967e5#782967e5e488d447ae989406bf0e1bfc1371493f" dependencies = [ "dirs", "ethers", @@ -4220,7 +4220,7 @@ dependencies = [ [[package]] name = "starkgate-manager-client" version = "0.1.0" -source = "git+https://github.com/karnotxyz/zaun?branch=update/core-contract-v13.2.0#8b82a9230974b8b5824d9a4dec8711101051db52" +source = "git+https://github.com/karnotxyz/zaun?rev=782967e5#782967e5e488d447ae989406bf0e1bfc1371493f" dependencies = [ "async-trait", "ethers", @@ -4234,7 +4234,7 @@ dependencies = [ [[package]] name = "starkgate-registry-client" version = "0.1.0" -source = "git+https://github.com/karnotxyz/zaun?branch=update/core-contract-v13.2.0#8b82a9230974b8b5824d9a4dec8711101051db52" +source = "git+https://github.com/karnotxyz/zaun?rev=782967e5#782967e5e488d447ae989406bf0e1bfc1371493f" dependencies = [ "async-trait", "ethers", @@ -4346,7 +4346,7 @@ dependencies = [ [[package]] name = "starknet-core-contract-client" version = "0.1.0" -source = "git+https://github.com/karnotxyz/zaun?branch=update/core-contract-v13.2.0#8b82a9230974b8b5824d9a4dec8711101051db52" +source = "git+https://github.com/karnotxyz/zaun?rev=782967e5#782967e5e488d447ae989406bf0e1bfc1371493f" dependencies = [ "async-trait", "ethers", @@ -4457,7 +4457,7 @@ dependencies = [ [[package]] name = "starknet-erc20-client" version = "0.1.0" -source = "git+https://github.com/karnotxyz/zaun?branch=update/core-contract-v13.2.0#8b82a9230974b8b5824d9a4dec8711101051db52" +source = "git+https://github.com/karnotxyz/zaun?rev=782967e5#782967e5e488d447ae989406bf0e1bfc1371493f" dependencies = [ "async-trait", "ethereum-instance", @@ -4472,7 +4472,7 @@ dependencies = [ [[package]] name = "starknet-eth-bridge-client" version = "0.1.0" -source = "git+https://github.com/karnotxyz/zaun?branch=update/core-contract-v13.2.0#8b82a9230974b8b5824d9a4dec8711101051db52" +source = "git+https://github.com/karnotxyz/zaun?rev=782967e5#782967e5e488d447ae989406bf0e1bfc1371493f" dependencies = [ "async-trait", "ethers", @@ -4550,7 +4550,7 @@ dependencies = [ [[package]] name = "starknet-proxy-client" version = "0.1.0" -source = "git+https://github.com/karnotxyz/zaun?branch=update/core-contract-v13.2.0#8b82a9230974b8b5824d9a4dec8711101051db52" +source = "git+https://github.com/karnotxyz/zaun?rev=782967e5#782967e5e488d447ae989406bf0e1bfc1371493f" dependencies = [ "async-trait", "ethereum-instance", @@ -4599,7 +4599,7 @@ dependencies = [ [[package]] name = "starknet-token-bridge-client" version = "0.1.0" -source = "git+https://github.com/karnotxyz/zaun?branch=update/core-contract-v13.2.0#8b82a9230974b8b5824d9a4dec8711101051db52" +source = "git+https://github.com/karnotxyz/zaun?rev=782967e5#782967e5e488d447ae989406bf0e1bfc1371493f" dependencies = [ "async-trait", "ethers", @@ -5221,7 +5221,7 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "utils" version = "0.1.0" -source = "git+https://github.com/karnotxyz/zaun?branch=update/core-contract-v13.2.0#8b82a9230974b8b5824d9a4dec8711101051db52" +source = "git+https://github.com/karnotxyz/zaun?rev=782967e5#782967e5e488d447ae989406bf0e1bfc1371493f" dependencies = [ "async-trait", "ethers", diff --git a/Cargo.toml b/Cargo.toml index f821ac4..d180e5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,15 +16,15 @@ serde_with = { version = "2.3.3", default-features = false } url = "2.4.1" # Zaun Deps -ethereum-instance = { git = "https://github.com/karnotxyz/zaun", package = "ethereum-instance", branch = "update/core-contract-v13.2.0" } -starkgate-manager-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-manager-client", branch = "update/core-contract-v13.2.0" } -starkgate-registry-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-registry-client", branch = "update/core-contract-v13.2.0" } -starknet-core-contract-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-core-contract-client", branch = "update/core-contract-v13.2.0" } -starknet-erc20-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-erc20-client", branch = "update/core-contract-v13.2.0" } -starknet-eth-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-eth-bridge-client", branch = "update/core-contract-v13.2.0" } -starknet-proxy-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-proxy-client", branch = "update/core-contract-v13.2.0" } -starknet-token-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-token-bridge-client", branch = "update/core-contract-v13.2.0" } -zaun-utils = { git = "https://github.com/karnotxyz/zaun", package = "utils", branch = "update/core-contract-v13.2.0" } +ethereum-instance = { git = "https://github.com/karnotxyz/zaun", package = "ethereum-instance", rev = "782967e5" } +starkgate-manager-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-manager-client", rev = "782967e5" } +starkgate-registry-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-registry-client", rev = "782967e5" } +starknet-core-contract-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-core-contract-client", rev = "782967e5" } +starknet-erc20-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-erc20-client", rev = "782967e5" } +starknet-eth-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-eth-bridge-client", rev = "782967e5" } +starknet-proxy-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-proxy-client", rev = "782967e5" } +starknet-token-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-token-bridge-client", rev = "782967e5" } +zaun-utils = { git = "https://github.com/karnotxyz/zaun", package = "utils", rev = "782967e5" } # Starknet Deps starknet = "0.11.0" diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..aa3adbb Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/contract_clients/starknet_validity.rs b/src/contract_clients/starknet_validity.rs index ddf7f0b..14142b5 100644 --- a/src/contract_clients/starknet_validity.rs +++ b/src/contract_clients/starknet_validity.rs @@ -16,7 +16,7 @@ use crate::contract_clients::core_contract::{ use crate::utils::convert_felt_to_u256; pub struct StarknetValidityContract { - core_contract_client: StarknetValidityContractClient, + pub core_contract_client: StarknetValidityContractClient, } impl CoreContractDeploy for StarknetValidityContract { diff --git a/src/contract_clients/utils.rs b/src/contract_clients/utils.rs index 4311083..876a72d 100644 --- a/src/contract_clients/utils.rs +++ b/src/contract_clients/utils.rs @@ -115,7 +115,7 @@ pub(crate) enum DeclarationInput<'a> { // inputs : sierra_path, casm_path DeclarationInputs(String, String, RpcAccount<'a>), // input : artifact_path - LegacyDeclarationInputs(String, String), + LegacyDeclarationInputs(String, String, &'a JsonRpcClient), } #[allow(private_interfaces)] @@ -130,6 +130,10 @@ pub async fn declare_contract(input: DeclarationInput<'_>) -> Felt { let class_hash = contract_artifact_casm.class_hash().unwrap(); let sierra_class_hash = contract_artifact.class_hash().unwrap(); + if account.provider().get_class(BlockId::Tag(Pending), sierra_class_hash).await.is_ok() { + return sierra_class_hash; + } + let flattened_class = contract_artifact.flatten().unwrap(); account @@ -140,12 +144,17 @@ pub async fn declare_contract(input: DeclarationInput<'_>) -> Felt { .expect("Error in declaring the contract using Cairo 1 declaration using the provided account"); sierra_class_hash } - LegacyDeclarationInputs(artifact_path, url) => { + LegacyDeclarationInputs(artifact_path, url, provider) => { let contract_abi_artifact_temp: LegacyContractClass = serde_json::from_reader( std::fs::File::open(env!("CARGO_MANIFEST_DIR").to_owned() + "/" + &artifact_path).unwrap(), ) .unwrap(); + let class_hash = contract_abi_artifact_temp.class_hash().expect("Failed to get class hash"); + if provider.get_class(BlockId::Tag(Pending), class_hash).await.is_ok() { + return class_hash; + } + let contract_abi_artifact: CompressedLegacyContractClass = contract_abi_artifact_temp .clone() .compress() @@ -183,7 +192,7 @@ pub async fn declare_contract(input: DeclarationInput<'_>) -> Felt { } } - contract_abi_artifact_temp.class_hash().unwrap() + class_hash } } } @@ -203,9 +212,14 @@ pub(crate) async fn deploy_account_using_priv_key( let deploy_txn = oz_account_factory.deploy_v1(Felt::ZERO).max_fee(Felt::ZERO); let account_address = deploy_txn.address(); - log::trace!("OZ Account Deployed : {:?}", account_address); + log::trace!("OZ Account Deploy Address: {:?}", account_address); save_to_json("account_address", &JsonValueType::StringType(account_address.to_string())).unwrap(); + if provider.get_class_at(BlockId::Tag(Pending), account_address).await.is_ok() { + log::debug!("ℹ️ Account is already deployed. Skipping...."); + return account_address; + } + let sent_txn = deploy_txn.send().await.expect("Error in deploying the OZ account"); log::trace!("deploy account txn_hash : {:?}", sent_txn.transaction_hash); diff --git a/src/main.rs b/src/main.rs index 6d27597..1d8e85e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,19 +5,32 @@ mod setup_scripts; pub mod tests; pub mod utils; +use std::fs::File; use std::io::stdin; +use std::str::FromStr; use std::time::Duration; -use clap::{ArgAction, Parser}; +use clap::{ArgAction, Parser, ValueEnum}; +use contract_clients::utils::RpcAccount; use dotenv::dotenv; +use ethers::abi::Address; use inline_colorization::*; +use serde::{Deserialize, Serialize}; +use setup_scripts::argent::ArgentSetupOutput; +use setup_scripts::braavos::BraavosSetupOutput; +use setup_scripts::core_contract::CoreContractStarknetL1Output; +use setup_scripts::erc20_bridge::Erc20BridgeSetupOutput; +use setup_scripts::eth_bridge::EthBridgeSetupOutput; +use setup_scripts::udc::UdcSetupOutput; use starknet::accounts::Account; use starknet::core::types::Felt; +use starknet_core_contract_client::clients::StarknetValidityContractClient; use tokio::time::sleep; use crate::contract_clients::config::Config; use crate::contract_clients::core_contract::CoreContract; use crate::contract_clients::eth_bridge::StarknetLegacyEthBridge; +use crate::contract_clients::starknet_validity::StarknetValidityContract; use crate::contract_clients::token_bridge::StarknetTokenBridge; use crate::setup_scripts::account_setup::account_init; use crate::setup_scripts::argent::ArgentSetup; @@ -29,6 +42,17 @@ use crate::setup_scripts::udc::UdcSetup; use crate::utils::banner::BANNER; use crate::utils::{save_to_json, JsonValueType}; +#[derive(Debug, Clone, Copy, ValueEnum)] +enum BootstrapMode { + Full, + Core, + EthBridge, + Erc20Bridge, + Udc, + Argent, + Braavos, +} + #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct CliArgs { @@ -74,6 +98,14 @@ pub struct CliArgs { operator_address: String, #[clap(long, env, action=ArgAction::SetTrue)] dev: bool, + #[clap(long, env, value_enum, default_value_t = BootstrapMode::Full)] + mode: BootstrapMode, + #[clap(long, env)] + core_contract_address: Option, + #[clap(long, env)] + core_contract_implementation_address: Option, + #[clap(long, env)] + output_file: Option, } #[tokio::main] @@ -83,67 +115,201 @@ pub async fn main() { let args = CliArgs::parse(); - bootstrap(&args).await; + println!("{color_red}{}{color_reset}", BANNER); + + let config = Config::init(&args).await; + + let output = match args.mode { + BootstrapMode::Full => bootstrap(&args, &config).await, + BootstrapMode::Core => { + let output = setup_core_contract(&args, &config).await; + BootstrapperOutput { + starknet_contract_address: Some(output.core_contract_client.address()), + starknet_contract_implementation_address: Some(output.core_contract_client.implementation_address()), + ..Default::default() + } + } + BootstrapMode::EthBridge => { + let core_contract_client = get_core_contract_client(&args, &config); + let output = setup_eth_bridge(None, &core_contract_client, &args, &config).await; + BootstrapperOutput { eth_bridge_setup_outputs: Some(output), ..Default::default() } + } + BootstrapMode::Erc20Bridge => { + let core_contract_client = get_core_contract_client(&args, &config); + let output = setup_erc20_bridge(None, &core_contract_client, &args, &config).await; + BootstrapperOutput { erc20_bridge_setup_outputs: Some(output), ..Default::default() } + } + BootstrapMode::Udc => { + let output = setup_udc(None, &args, &config).await; + BootstrapperOutput { udc_setup_outputs: Some(output), ..Default::default() } + } + BootstrapMode::Argent => { + let output = setup_argent(None, &args, &config).await; + BootstrapperOutput { argent_setup_outputs: Some(output), ..Default::default() } + } + BootstrapMode::Braavos => { + let output = setup_braavos(None, &args, &config).await; + BootstrapperOutput { braavos_setup_outputs: Some(output), ..Default::default() } + } + }; + + if let Some(output_file) = args.output_file { + let file = File::create(&output_file).unwrap(); + serde_json::to_writer_pretty(file, &output).unwrap(); + println!("Output : {:#?}", output); + println!("✅ Bootstrap output saved to {}", output_file); + } } -pub struct DeployBridgeOutput { - pub starknet_contract: Box, - pub starknet_token_bridge: StarknetTokenBridge, - pub erc20_class_hash: Felt, - pub legacy_eth_bridge_class_hash: Felt, - pub account_address: Felt, - pub eth_proxy_address: Felt, - pub eth_bridge_proxy_address: Felt, - pub legacy_proxy_class_hash: Felt, - pub starkgate_proxy_class_hash: Felt, - pub erc20_legacy_class_hash: Felt, - pub erc20_l2_bridge_address: Felt, - pub l2_erc20_token_address: Felt, - pub eth_bridge: StarknetLegacyEthBridge, +fn get_core_contract_client(args: &CliArgs, config: &Config) -> CoreContractStarknetL1Output { + let Some(core_contract_address) = args.core_contract_address.clone() else { + panic!("Core contract address is required for ETH bridge setup"); + }; + let Some(core_contract_implementation_address) = args.core_contract_implementation_address.clone() else { + panic!("Core contract implementation address is required for ETH bridge setup"); + }; + let core_contract_client = StarknetValidityContractClient::new( + Address::from_str(&core_contract_address).unwrap(), + config.eth_client().signer().clone(), + Address::from_str(&core_contract_implementation_address).unwrap(), + ); + let core_contract_client = CoreContractStarknetL1Output { + core_contract_client: Box::new(StarknetValidityContract { core_contract_client }), + }; + + core_contract_client } -pub async fn bootstrap(config: &CliArgs) -> DeployBridgeOutput { - println!("{color_red}{}{color_reset}", BANNER); - let clients = Config::init(config).await; - let core_contract = CoreContractStarknetL1::new(config, &clients); +async fn get_account<'a>(config: &'a Config, args: &'a CliArgs) -> RpcAccount<'a> { + log::info!("⏳ L2 State and Initialisation Started"); + let account = account_init(config, &args).await; + log::info!("🔐 Account with given private key deployed on L2. [Account Address : {:?}]", account.address()); + account +} + +#[derive(Debug, Clone, Serialize, Default)] +pub struct BootstrapperOutput { + #[serde(skip_serializing_if = "Option::is_none")] + pub starknet_contract_address: Option
, + #[serde(skip_serializing_if = "Option::is_none")] + pub starknet_contract_implementation_address: Option
, + #[serde(skip_serializing_if = "Option::is_none")] + pub eth_bridge_setup_outputs: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub erc20_bridge_setup_outputs: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub udc_setup_outputs: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub argent_setup_outputs: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub braavos_setup_outputs: Option, +} + +pub async fn bootstrap(args: &CliArgs, config: &Config) -> BootstrapperOutput { + let account = get_account(config, args).await; + + // setup core contract + let core_contract_client = setup_core_contract(&args, config).await; + + // setup eth bridge + let eth_bridge_setup_outputs = setup_eth_bridge(Some(account.clone()), &core_contract_client, args, config).await; + + // setup erc20 bridge + let erc20_bridge_setup_outputs = + setup_erc20_bridge(Some(account.clone()), &core_contract_client, args, config).await; + + // setup udc + let udc_setup_outputs = setup_udc(Some(account.clone()), args, config).await; + + // setup argent account + let argent_setup_outputs = setup_argent(Some(account.clone()), args, config).await; + + // setup braavos account + let braavos_setup_outputs = setup_braavos(Some(account.clone()), args, config).await; + + BootstrapperOutput { + starknet_contract_address: Some(core_contract_client.core_contract_client.address()), + starknet_contract_implementation_address: Some( + core_contract_client.core_contract_client.implementation_address(), + ), + eth_bridge_setup_outputs: Some(eth_bridge_setup_outputs), + erc20_bridge_setup_outputs: Some(erc20_bridge_setup_outputs), + udc_setup_outputs: Some(udc_setup_outputs), + argent_setup_outputs: Some(argent_setup_outputs), + braavos_setup_outputs: Some(braavos_setup_outputs), + } +} + +async fn setup_core_contract(args: &CliArgs, config: &Config) -> CoreContractStarknetL1Output { + let core_contract = CoreContractStarknetL1::new(args, &config); let core_contract_client = core_contract.setup().await; log::info!("📦 Core address : {:?}", core_contract_client.core_contract_client.address()); + log::info!( + "📦 Core implementation address : {:?}", + core_contract_client.core_contract_client.implementation_address() + ); save_to_json( "l1_core_contract_address", &JsonValueType::EthAddress(core_contract_client.core_contract_client.address()), ) .unwrap(); log::info!("✅ Core setup init for L1 successful."); - // sleep(Duration::from_secs(60)).await; - - println!("Press Enter to continue erc20 bridge..."); - let _ = stdin().read_line(&mut String::new()).unwrap(); + core_contract_client +} - log::info!("⏳ L2 State and Initialisation Started"); - let account = account_init(&clients, config).await; - log::info!("🔐 Account with given private key deployed on L2. [Account Address : {:?}]", account.address()); +async fn setup_eth_bridge<'a>( + account: Option>, + core_contract_client: &CoreContractStarknetL1Output, + args: &CliArgs, + config: &Config, +) -> EthBridgeSetupOutput { + let account = match account { + Some(account) => account, + None => get_account(config, args).await, + }; log::info!("⏳ Starting ETH bridge deployment"); let eth_bridge = EthBridge::new( account.clone(), account.address(), - config, - &clients, + args, + &config, core_contract_client.core_contract_client.as_ref(), ); let eth_bridge_setup_outputs = eth_bridge.setup().await; log::info!("✅ ETH bridge deployment complete."); + eth_bridge_setup_outputs +} + +async fn setup_erc20_bridge<'a>( + account: Option>, + core_contract_client: &CoreContractStarknetL1Output, + args: &CliArgs, + config: &Config, +) -> Erc20BridgeSetupOutput { + let account = match account { + Some(account) => account, + None => get_account(config, args).await, + }; log::info!("⏳ Starting ERC20 token bridge deployment"); let erc20_bridge = Erc20Bridge::new( account.clone(), account.address(), - config, - &clients, + args, + &config, core_contract_client.core_contract_client.as_ref(), ); let erc20_bridge_setup_outputs = erc20_bridge.setup().await; log::info!("✅ ERC20 token bridge deployment complete."); + erc20_bridge_setup_outputs +} + +async fn setup_udc<'a>(account: Option>, args: &CliArgs, config: &Config) -> UdcSetupOutput { + let account = match account { + Some(account) => account, + None => get_account(config, args).await, + }; log::info!("⏳ Starting UDC (Universal Deployer Contract) deployment"); - let udc = UdcSetup::new(account.clone(), account.address(), config); + let udc = UdcSetup::new(account.clone(), account.address(), args, config); let udc_setup_outputs = udc.setup().await; log::info!( "*️⃣ UDC setup completed. [UDC Address : {:?}, UDC class hash : {:?}]", @@ -151,33 +317,34 @@ pub async fn bootstrap(config: &CliArgs) -> DeployBridgeOutput { udc_setup_outputs.udc_class_hash ); log::info!("✅ UDC (Universal Deployer Contract) deployment complete."); - log::info!("⏳ Starting Argent Account declaration"); + udc_setup_outputs +} + +async fn setup_argent<'a>(account: Option>, args: &CliArgs, config: &Config) -> ArgentSetupOutput { + let account = match account { + Some(account) => account, + None => get_account(config, args).await, + }; + log::info!("⏳ Starting Argent Account deployment"); let argent = ArgentSetup::new(account.clone()); let argent_setup_outputs = argent.setup().await; log::info!("*️⃣ Argent setup completed. [Argent account class hash : {:?}]", argent_setup_outputs.argent_class_hash); - log::info!("✅ Argent Account declaration complete."); - log::info!("⏳ Starting Braavos Account declaration"); - let braavos = BraavosSetup::new(account.clone(), config); + log::info!("✅ Argent Account deployment complete."); + argent_setup_outputs +} + +async fn setup_braavos<'a>(account: Option>, args: &CliArgs, config: &Config) -> BraavosSetupOutput { + let account = match account { + Some(account) => account, + None => get_account(config, args).await, + }; + log::info!("⏳ Starting Braavos Account deployment"); + let braavos = BraavosSetup::new(account.clone(), args, config); let braavos_setup_outputs = braavos.setup().await; log::info!( "*️⃣ Braavos setup completed. [Braavos account class hash : {:?}]", braavos_setup_outputs.braavos_class_hash ); - log::info!("✅ Braavos Account declaration complete."); - - DeployBridgeOutput { - starknet_contract: core_contract_client.core_contract_client, - starknet_token_bridge: erc20_bridge_setup_outputs.starknet_token_bridge, - erc20_class_hash: erc20_bridge_setup_outputs.erc20_cairo_one_class_hash, - legacy_eth_bridge_class_hash: eth_bridge_setup_outputs.legacy_eth_bridge_class_hash, - account_address: account.address(), - eth_proxy_address: eth_bridge_setup_outputs.eth_proxy_address, - eth_bridge_proxy_address: eth_bridge_setup_outputs.eth_bridge_proxy_address, - legacy_proxy_class_hash: eth_bridge_setup_outputs.legacy_proxy_class_hash, - starkgate_proxy_class_hash: eth_bridge_setup_outputs.starkgate_proxy_class_hash, - erc20_legacy_class_hash: eth_bridge_setup_outputs.erc20_legacy_class_hash, - erc20_l2_bridge_address: erc20_bridge_setup_outputs.erc20_l2_bridge_address, - l2_erc20_token_address: erc20_bridge_setup_outputs.l2_erc20_token_address, - eth_bridge: eth_bridge_setup_outputs.eth_bridge, - } + log::info!("✅ Braavos Account deployment complete."); + braavos_setup_outputs } diff --git a/src/setup_scripts/account_setup.rs b/src/setup_scripts/account_setup.rs index 1b70c09..3e938eb 100644 --- a/src/setup_scripts/account_setup.rs +++ b/src/setup_scripts/account_setup.rs @@ -17,6 +17,7 @@ pub async fn account_init<'a>(clients: &'a Config, arg_config: &'a CliArgs) -> R let oz_account_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(OZ_ACCOUNT_PATH), arg_config.rollup_seq_url.clone(), + clients.provider_l2() )) .await; log::debug!("OZ Account Class Hash Declared"); diff --git a/src/setup_scripts/argent.rs b/src/setup_scripts/argent.rs index dd04600..3045866 100644 --- a/src/setup_scripts/argent.rs +++ b/src/setup_scripts/argent.rs @@ -1,5 +1,6 @@ use std::time::Duration; +use serde::Serialize; use starknet::core::types::Felt; use tokio::time::sleep; @@ -11,6 +12,7 @@ pub struct ArgentSetup<'a> { account: RpcAccount<'a>, } +#[derive(Debug, Clone, Serialize)] pub struct ArgentSetupOutput { pub argent_class_hash: Felt, } diff --git a/src/setup_scripts/braavos.rs b/src/setup_scripts/braavos.rs index bca89ac..8a3c473 100644 --- a/src/setup_scripts/braavos.rs +++ b/src/setup_scripts/braavos.rs @@ -1,5 +1,6 @@ use std::time::Duration; +use serde::Serialize; use starknet::accounts::{Account, ConnectedAccount}; use starknet::core::types::Felt; use tokio::time::sleep; @@ -12,19 +13,22 @@ use crate::utils::constants::{ }; use crate::utils::{save_to_json, wait_for_transaction, JsonValueType}; use crate::CliArgs; +use crate::contract_clients::config::Config; pub struct BraavosSetup<'a> { account: RpcAccount<'a>, arg_config: &'a CliArgs, + config: &'a Config } +#[derive(Debug, Clone, Serialize)] pub struct BraavosSetupOutput { pub braavos_class_hash: Felt, } impl<'a> BraavosSetup<'a> { - pub fn new(account: RpcAccount<'a>, arg_config: &'a CliArgs) -> Self { - Self { account, arg_config } + pub fn new(account: RpcAccount<'a>, arg_config: &'a CliArgs, config: &'a Config) -> Self { + Self { account, arg_config, config } } pub async fn setup(&self) -> BraavosSetupOutput { @@ -55,6 +59,7 @@ impl<'a> BraavosSetup<'a> { let braavos_aggregator_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(BRAAVOS_AGGREGATOR_PATH), self.arg_config.rollup_seq_url.clone(), + self.config.provider_l2() )) .await; log::debug!("📣 Braavos Aggregator class hash declared."); diff --git a/src/setup_scripts/erc20_bridge.rs b/src/setup_scripts/erc20_bridge.rs index e0b511b..daa5311 100644 --- a/src/setup_scripts/erc20_bridge.rs +++ b/src/setup_scripts/erc20_bridge.rs @@ -3,6 +3,7 @@ use std::time::Duration; use ethers::abi::Address; use ethers::prelude::{H160, U256}; +use serde::Serialize; use starknet::core::types::Felt; use starknet_core::types::{BlockId, BlockTag, FunctionCall}; use starknet_core::utils::get_selector_from_name; @@ -27,11 +28,14 @@ pub struct Erc20Bridge<'a> { core_contract: &'a dyn CoreContract, } +#[derive(Debug, Clone, Serialize)] pub struct Erc20BridgeSetupOutput { pub erc20_cairo_one_class_hash: Felt, - pub starknet_token_bridge: StarknetTokenBridge, - pub erc20_l2_bridge_address: Felt, - pub l2_erc20_token_address: Felt, + pub l1_token_bridge_proxy: Address, + pub l1_manager_address: Address, + pub l1_registry_address: Address, + pub l2_token_bridge: Felt, + pub test_erc20_token_address: Felt, } impl<'a> Erc20Bridge<'a> { @@ -137,9 +141,11 @@ impl<'a> Erc20Bridge<'a> { Erc20BridgeSetupOutput { erc20_cairo_one_class_hash, - starknet_token_bridge: token_bridge, - erc20_l2_bridge_address: l2_bridge_address, - l2_erc20_token_address, + l1_token_bridge_proxy: token_bridge.bridge_address(), + l1_manager_address: token_bridge.manager_address(), + l1_registry_address: token_bridge.registry_address(), + l2_token_bridge: l2_bridge_address, + test_erc20_token_address: l2_erc20_token_address, } } } diff --git a/src/setup_scripts/eth_bridge.rs b/src/setup_scripts/eth_bridge.rs index 58e0fed..f10372b 100644 --- a/src/setup_scripts/eth_bridge.rs +++ b/src/setup_scripts/eth_bridge.rs @@ -2,6 +2,7 @@ use std::str::FromStr; use std::time::Duration; use ethers::abi::Address; +use serde::{Deserialize, Serialize}; use starknet::accounts::{Account, ConnectedAccount}; use starknet::core::types::Felt; use starknet_providers::jsonrpc::HttpTransport; @@ -28,14 +29,15 @@ pub struct EthBridge<'a> { core_contract: &'a dyn CoreContract, } +#[derive(Debug, Clone, Serialize)] pub struct EthBridgeSetupOutput { - pub legacy_proxy_class_hash: Felt, - pub starkgate_proxy_class_hash: Felt, - pub erc20_legacy_class_hash: Felt, - pub legacy_eth_bridge_class_hash: Felt, - pub eth_proxy_address: Felt, - pub eth_bridge_proxy_address: Felt, - pub eth_bridge: StarknetLegacyEthBridge, + pub l2_legacy_proxy_class_hash: Felt, + pub l2_erc20_legacy_class_hash: Felt, + pub l2_eth_proxy_address: Felt, + pub l2_starkgate_proxy_class_hash: Felt, + pub l2_legacy_eth_bridge_class_hash: Felt, + pub l2_eth_bridge_proxy_address: Felt, + pub l1_bridge_address: Address, } impl<'a> EthBridge<'a> { @@ -53,6 +55,7 @@ impl<'a> EthBridge<'a> { let legacy_proxy_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(PROXY_LEGACY_PATH), self.arg_config.rollup_seq_url.clone(), + self.clients.provider_l2() )) .await; log::debug!("🎡 Legacy proxy class hash declared."); @@ -63,6 +66,7 @@ impl<'a> EthBridge<'a> { let starkgate_proxy_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(STARKGATE_PROXY_PATH), self.arg_config.rollup_seq_url.clone(), + self.clients.provider_l2() )) .await; log::debug!("🎡 Starkgate proxy class hash declared."); @@ -73,6 +77,7 @@ impl<'a> EthBridge<'a> { let erc20_legacy_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(ERC20_LEGACY_PATH), self.arg_config.rollup_seq_url.clone(), + self.clients.provider_l2() )) .await; log::debug!("🎡 ERC20 legacy class hash declared."); @@ -83,6 +88,7 @@ impl<'a> EthBridge<'a> { let legacy_eth_bridge_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(LEGACY_BRIDGE_PATH), self.arg_config.rollup_seq_url.clone(), + self.clients.provider_l2() )) .await; log::debug!("🎡 Legacy ETH Bridge class hash declared"); @@ -199,13 +205,13 @@ impl<'a> EthBridge<'a> { log::info!("✴️ ETH Bridge setup on L1 completed"); EthBridgeSetupOutput { - legacy_proxy_class_hash, - starkgate_proxy_class_hash, - erc20_legacy_class_hash, - legacy_eth_bridge_class_hash, - eth_proxy_address, - eth_bridge_proxy_address, - eth_bridge, + l2_legacy_proxy_class_hash: legacy_proxy_class_hash, + l2_starkgate_proxy_class_hash: starkgate_proxy_class_hash, + l2_erc20_legacy_class_hash: erc20_legacy_class_hash, + l2_legacy_eth_bridge_class_hash: legacy_eth_bridge_class_hash, + l2_eth_proxy_address: eth_proxy_address, + l2_eth_bridge_proxy_address: eth_bridge_proxy_address, + l1_bridge_address: eth_bridge.address(), } } } diff --git a/src/setup_scripts/udc.rs b/src/setup_scripts/udc.rs index 369a9be..31a19b4 100644 --- a/src/setup_scripts/udc.rs +++ b/src/setup_scripts/udc.rs @@ -1,5 +1,6 @@ use std::time::Duration; +use serde::Serialize; use starknet::accounts::ConnectedAccount; use starknet::core::types::Felt; use tokio::time::sleep; @@ -9,27 +10,31 @@ use crate::helpers::account_actions::{get_contract_address_from_deploy_tx, Accou use crate::utils::constants::UDC_PATH; use crate::utils::{save_to_json, wait_for_transaction, JsonValueType}; use crate::CliArgs; +use crate::contract_clients::config::Config; pub struct UdcSetup<'a> { account: RpcAccount<'a>, account_address: Felt, arg_config: &'a CliArgs, + config: &'a Config } +#[derive(Debug, Clone, Serialize)] pub struct UdcSetupOutput { pub udc_class_hash: Felt, pub udc_address: Felt, } impl<'a> UdcSetup<'a> { - pub fn new(account: RpcAccount<'a>, account_address: Felt, arg_config: &'a CliArgs) -> Self { - Self { account, account_address, arg_config } + pub fn new(account: RpcAccount<'a>, account_address: Felt, arg_config: &'a CliArgs, config: &'a Config) -> Self { + Self { account, account_address, arg_config, config } } pub async fn setup(&self) -> UdcSetupOutput { let udc_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(UDC_PATH), self.arg_config.rollup_seq_url.clone(), + self.config.provider_l2() )) .await; log::debug!("📣 UDC Class Hash Declared."); diff --git a/src/tests/mod.rs b/src/tests/mod.rs index af68b5e..7446404 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -19,8 +19,8 @@ use crate::{bootstrap, CliArgs}; #[ignore] async fn deploy_bridge() -> Result<(), anyhow::Error> { env_logger::init(); - - bootstrap(&get_config()).await; + let clients = Config::init(&get_config()).await; + bootstrap(&get_config(), &clients).await; Ok(()) } @@ -31,7 +31,7 @@ async fn deploy_bridge() -> Result<(), anyhow::Error> { async fn deposit_and_withdraw_eth_bridge() -> Result<(), anyhow::Error> { env_logger::init(); let clients = Config::init(&get_config()).await; - let out = bootstrap(&get_config()).await; + let out = bootstrap(&get_config(), &clients).await; let _ = eth_bridge_test_helper( &clients, @@ -51,7 +51,7 @@ async fn deposit_and_withdraw_eth_bridge() -> Result<(), anyhow::Error> { async fn deposit_and_withdraw_erc20_bridge() -> Result<(), anyhow::Error> { env_logger::init(); let clients = Config::init(&get_config()).await; - let out = bootstrap(&get_config()).await; + let out = bootstrap(&get_config(), &clients).await; let _ = erc20_bridge_test_helper( &clients, @@ -70,7 +70,7 @@ async fn deposit_and_withdraw_erc20_bridge() -> Result<(), anyhow::Error> { async fn deposit_tests_both_bridges() -> Result<(), anyhow::Error> { env_logger::init(); let clients = Config::init(&get_config()).await; - let out = bootstrap(&get_config()).await; + let out = bootstrap(&get_config(), &clients).await; let _ = eth_bridge_test_helper( &clients, @@ -113,5 +113,8 @@ fn get_config() -> CliArgs { verifier_address: String::from(VERIFIER_ADDRESS), operator_address: String::from(OPERATOR_ADDRESS), dev: false, + mode: crate::BootstrapMode::Full, + core_contract_address: None, + core_contract_implementation_address: None, } }