Skip to content

Commit

Permalink
refactor: removed cli params and taking input from json file
Browse files Browse the repository at this point in the history
  • Loading branch information
mohiiit committed Nov 4, 2024
1 parent c98c84a commit 40b8839
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 182 deletions.
31 changes: 23 additions & 8 deletions src/contract_clients/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use ethereum_instance::EthereumClient;
use starknet::providers::jsonrpc::{HttpTransport, JsonRpcClient};
use starknet::providers::Url;

use crate::CliArgs;
use crate::ConfigFile;

pub struct Config {
pub struct Clients {
eth_client: EthereumClient,
provider_l2: JsonRpcClient<HttpTransport>,
}

impl Config {
impl Clients {
pub fn provider_l2(&self) -> &JsonRpcClient<HttpTransport> {
&self.provider_l2
}
Expand All @@ -19,16 +19,31 @@ impl Config {
}

/// To deploy the instance of ethereum and starknet and returning the struct.
pub async fn init(config: &CliArgs) -> Self {
// pub async fn init(config: &CliArgs) -> Self {
// let client_instance = EthereumClient::attach(
// Option::from(config.eth_rpc.clone()),
// Option::from(config.eth_priv_key.clone()),
// Option::from(config.eth_chain_id),
// )
// .unwrap();
//
// let provider_l2 = JsonRpcClient::new(HttpTransport::new(
// Url::parse(&config.rollup_seq_url).expect("Failed to declare provider for app chain"),
// ));
//
// Self { eth_client: client_instance, provider_l2 }
// }

pub async fn init_from_config(config_file: &ConfigFile) -> Self {
let client_instance = EthereumClient::attach(
Option::from(config.eth_rpc.clone()),
Option::from(config.eth_priv_key.clone()),
Option::from(config.eth_chain_id),
Option::from(config_file.eth_rpc.clone()),
Option::from(config_file.eth_priv_key.clone()),
Option::from(config_file.eth_chain_id),
)
.unwrap();

let provider_l2 = JsonRpcClient::new(HttpTransport::new(
Url::parse(&config.rollup_seq_url).expect("Failed to declare provider for app chain"),
Url::parse(&config_file.rollup_seq_url).expect("Failed to declare provider for app chain"),
));

Self { eth_client: client_instance, provider_l2 }
Expand Down
4 changes: 2 additions & 2 deletions src/contract_clients/core_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use starknet::core::types::Felt;
use starknet_proxy_client::interfaces::proxy::{CoreContractInitData, CoreContractState};
use zaun_utils::LocalWalletSignerMiddleware;

use crate::contract_clients::config::Config;
use crate::contract_clients::config::Clients;
use crate::utils::convert_felt_to_u256;

#[async_trait]
Expand Down Expand Up @@ -68,7 +68,7 @@ pub trait CoreContract {
}

pub trait CoreContractDeploy<T> {
fn deploy(config: &Config) -> impl Future<Output = T> + Send;
fn deploy(clients: &Clients) -> impl Future<Output = T> + Send;
}

pub fn get_init_data_core_contract(
Expand Down
6 changes: 3 additions & 3 deletions src/contract_clients/starknet_sovereign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use starknet_core_contract_client::interfaces::{OperatorTrait, StarknetGovernanc
use starknet_proxy_client::interfaces::proxy::{CoreContractInitData, ProxyInitializeData, ProxySupport3_0_2Trait};
use zaun_utils::{LocalWalletSignerMiddleware, StarknetContractClient};

use crate::contract_clients::config::Config;
use crate::contract_clients::config::Clients;
use crate::contract_clients::core_contract::{
get_calldata_bytes, get_init_data_core_contract, CoreContract, CoreContractDeploy,
};
Expand All @@ -20,8 +20,8 @@ pub struct StarknetSovereignContract {
}

impl CoreContractDeploy<StarknetSovereignContract> for StarknetSovereignContract {
async fn deploy(config: &Config) -> Self {
let client = deploy_starknet_sovereign_behind_unsafe_proxy(config.eth_client().signer().clone())
async fn deploy(clients: &Clients) -> Self {
let client = deploy_starknet_sovereign_behind_unsafe_proxy(clients.eth_client().signer().clone())
.await
.expect("Failed to deploy the starknet contact");

Expand Down
6 changes: 3 additions & 3 deletions src/contract_clients/starknet_validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use starknet_core_contract_client::interfaces::{OperatorTrait, StarknetGovernanc
use starknet_proxy_client::interfaces::proxy::{CoreContractInitData, ProxyInitializeData, ProxySupport3_0_2Trait};
use zaun_utils::{LocalWalletSignerMiddleware, StarknetContractClient};

use crate::contract_clients::config::Config;
use crate::contract_clients::config::Clients;
use crate::contract_clients::core_contract::{
get_calldata_bytes, get_init_data_core_contract, CoreContract, CoreContractDeploy,
};
Expand All @@ -20,8 +20,8 @@ pub struct StarknetValidityContract {
}

impl CoreContractDeploy<StarknetValidityContract> for StarknetValidityContract {
async fn deploy(config: &Config) -> Self {
let client = deploy_starknet_validity_behind_safe_proxy(config.eth_client().signer().clone())
async fn deploy(clients: &Clients) -> Self {
let client = deploy_starknet_validity_behind_safe_proxy(clients.eth_client().signer().clone())
.await
.expect("Failed to deploy the starknet contact");

Expand Down
4 changes: 2 additions & 2 deletions src/contract_clients/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::contract_clients::legacy_class::CompressedLegacyContractClass;
use crate::contract_clients::utils::DeclarationInput::{DeclarationInputs, LegacyDeclarationInputs};
use crate::helpers::account_actions::{get_contract_address_from_deploy_tx, AccountActions};
use crate::utils::{invoke_contract, save_to_json, wait_for_transaction, JsonValueType};
use crate::CliArgs;
use crate::ConfigFile;

pub type RpcAccount<'a> = SingleOwnerAccount<&'a JsonRpcClient<HttpTransport>, LocalWallet>;
pub async fn build_single_owner_account<'a>(
Expand Down Expand Up @@ -75,7 +75,7 @@ pub fn generate_config_hash(
Pedersen::hash_array(&[config_hash_version, chain_id, fee_token_address, native_fee_token_address])
}

pub fn get_bridge_init_configs(config: &CliArgs) -> (Felt, Felt) {
pub fn get_bridge_init_configs(config: &ConfigFile) -> (Felt, Felt) {
let program_hash = Felt::from_hex(config.sn_os_program_hash.as_str()).unwrap();

let config_hash = generate_config_hash(
Expand Down
Loading

0 comments on commit 40b8839

Please sign in to comment.