Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ewoolsey/fix tomls #10

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions config.stage.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
[canonical_network]
type = "evm"
name = "Sepolia Mainnet"
address = "0xb2ead588f14e69266d1b87936b75325181377076"
world_id_addr = "0xb2ead588f14e69266d1b87936b75325181377076"
provider = { rpc_endpoint = "https://eth.llamarpc.com" }
wallet = { type = "mnemonic", mnemonic = "your mnemonic here" }

[[bridged_networks]]
type = "evm"
name = "World Chain Sepolia"
address = "0xb2ead588f14e69266d1b87936b75325181377076"
state_bridge_address = "0x2F418Aa7D500B525EE8B80BB5F643A877ef82e09"
world_id_address = "0xE177F37AF0A862A02edFEa4F59C02668E9d0aAA4"
state_bridge_addr = "0x2F418Aa7D500B525EE8B80BB5F643A877ef82e09"
world_id_addr = "0xE177F37AF0A862A02edFEa4F59C02668E9d0aAA4"
provider = { rpc_endpoint = "https://eth.llamarpc.com" }
wallet = { type = "mnemonic", mnemonic = "your mnemonic here" }

[[bridged_networks]]
type = "evm"
name = "Optimism Sepolia"
address = "0xb2ead588f14e69266d1b87936b75325181377076"
state_bridge_address = "0x158379286D7083dDA05930CD3C6374954Fb511aA"
world_id_address = "0xf07d3efadD82A1F0b4C5Cc3476806d9a170147Ba"
state_bridge_addr = "0x158379286D7083dDA05930CD3C6374954Fb511aA"
world_id_addr = "0xf07d3efadD82A1F0b4C5Cc3476806d9a170147Ba"
provider = { rpc_endpoint = "https://eth.llamarpc.com" }
wallet = { type = "mnemonic", mnemonic = "your mnemonic here" }

[[bridged_networks]]
type = "evm"
name = "Base Sepolia"
address = "0xb2ead588f14e69266d1b87936b75325181377076"
state_bridge_address = "0x5fFe37995158528d97A819bA390C1F81d74eB2b9"
world_id_address = "0x163b09b4fE21177c455D850BD815B6D583732432"
state_bridge_addr = "0x5fFe37995158528d97A819bA390C1F81d74eB2b9"
world_id_addr = "0x163b09b4fE21177c455D850BD815B6D583732432"
provider = { rpc_endpoint = "https://eth.llamarpc.com" }
wallet = { type = "mnemonic", mnemonic = "your mnemonic here" }
wallet = { type = "mnemonic", mnemonic = "your mnemonic here" }

14 changes: 7 additions & 7 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
[canonical_network]
type = "evm"
name = "Ethereum Mainnet"
address = "0xf7134CE138832c1456F2a91D64621eE90c2bddEa"
world_id_addr = "0xf7134CE138832c1456F2a91D64621eE90c2bddEa"
provider = { rpc_endpoint = "https://eth.llamarpc.com" }
wallet = { type = "mnemonic", mnemonic = "your mnemonic here" }

[[bridged_networks]]
type = "evm"
name = "World Chain Mainnet"
address = "0xf7134CE138832c146F2a91D64621eE90c2bddEa"
state_bridge_address = "0x4c175eE61C3c1da847E339e1158D61BBd2537046"
world_id_address = "0x047eE5313F98E26Cc8177fA38877cB36292D2364"
state_bridge_addr = "0x4c175eE61C3c1da847E339e1158D61BBd2537046"
world_id_addr = "0x047eE5313F98E26Cc8177fA38877cB36292D2364"
provider = { rpc_endpoint = "https://eth.llamarpc.com" }
wallet = { type = "mnemonic", mnemonic = "your mnemonic here" }

[[bridged_networks]]
type = "evm"
name = "Optimism Mainnet"
address = "0xf7134CE138832c1456F2a91D64621eE90c2bddEa"
state_bridge_address = "0xa6d85F3b3bE6Ff6DC52C3aaBe9A35d0ce252b79F"
world_id_address = "0xB3E7771a6e2d7DD8C0666042B7a07C39b938eb7d"
state_bridge_addr = "0xa6d85F3b3bE6Ff6DC52C3aaBe9A35d0ce252b79F"
world_id_addr = "0xB3E7771a6e2d7DD8C0666042B7a07C39b938eb7d"
provider = { rpc_endpoint = "https://eth.llamarpc.com" }
wallet = { type = "mnemonic", mnemonic = "your mnemonic here" }

[[bridged_networks]]
type = "evm"
name = "Polygon Mainnet"
address = "0xf7134CE138832c1456F2a91D64621eE90c2bddEa"
state_bridge_address = "0x76Db75dc752305E2deBd44c479680352F3Bb766f"
world_id_address = "0xa6d85F3b3bE6Ff6DC52C3aaBe9A35d0ce252b79F"
state_bridge_addr = "0x76Db75dc752305E2deBd44c479680352F3Bb766f"
world_id_addr = "0xa6d85F3b3bE6Ff6DC52C3aaBe9A35d0ce252b79F"
provider = { rpc_endpoint = "https://eth.llamarpc.com" }
wallet = { type = "mnemonic", mnemonic = "your mnemonic here" }
10 changes: 5 additions & 5 deletions src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ sol! {
function deleteIdentities(uint256[8] calldata deletionProof, bytes calldata packedDeletionIndices, uint256 preRoot, uint256 postRoot) external;
}

#[sol(rpc)]
interface IStateBridge {
function propogateRoot() external;
}

#[sol(rpc)]
interface IBridgedWorldID {
#[derive(Serialize, Deserialize)]
Expand All @@ -24,6 +19,11 @@ sol! {
function receiveRoot(uint256 newRoot) external;
}

#[sol(rpc)]
interface IStateBridge {
function propogateRoot() external;
}

#[sol(rpc)]
contract IOptimismStateBridge {
function opWorldIDaddress() external returns (address);
Expand Down
44 changes: 24 additions & 20 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ use url::Url;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
/// The global wallet configuration
pub wallet: Option<WalletConfig>,
/// The network from which roots will be propagated
pub canonical_network: NetworkConfig,
pub canonical_network: CanonicalNetworkConfig,
/// The networks to which roots will be propagated
#[serde(default)]
pub bridged_networks: Vec<NetworkConfig>,
/// The number of blocks in the past to start scanning for new root events
#[serde(default = "default::start_scan")]
pub start_scan: u64,
pub bridged_networks: Vec<BridgedNetworkConfig>,
#[serde(default)]
pub telemetry: Option<TelemetryConfig>,
}
Expand Down Expand Up @@ -47,17 +46,28 @@ impl Config {
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct NetworkConfig {
pub struct BridgedNetworkConfig {
/// The wallet configuration for the network
/// overrides the global wallet configuration
pub wallet: Option<WalletConfig>,
pub state_bridge_addr: Address,
pub world_id_addr: Address,
#[serde(rename = "type")]
pub ty: NetworkType,
pub name: String,
pub provider: ProviderConfig,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CanonicalNetworkConfig {
pub world_id_addr: Address,
/// The number of blocks in the past to start scanning for new root events
#[serde(default = "default::start_scan")]
pub start_scan: u64,
#[serde(rename = "type")]
pub ty: NetworkType,
pub name: String,
pub address: Address,
#[serde(default)]
pub state_bridge_address: Address,
#[serde(default)]
pub world_id_address: Address,
pub provider: ProviderConfig,
pub wallet: WalletConfig,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand All @@ -71,14 +81,8 @@ pub enum NetworkType {
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum WalletConfig {
Mnemonic {
mnemonic: String,
},
TxSitter {
url: String,
address: Address,
gas_limit: Option<u64>,
},
Mnemonic { mnemonic: String },
TxSitter { url: String, gas_limit: Option<u64> },
}

#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down
116 changes: 61 additions & 55 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use alloy::sol_types::SolEvent;
use alloy_signer_local::coins_bip39::English;
use clap::Parser;
use config::{NetworkType, WalletConfig};
use eyre::eyre::{eyre, Result};
use eyre::eyre::{eyre, OptionExt, Result};
use futures::StreamExt;
use relay::signer::{AlloySigner, Signer, TxSitterSigner};
use relay::{EVMRelay, Relay, Relayer};
Expand Down Expand Up @@ -102,11 +102,11 @@ pub async fn run(config: Config) -> Result<()> {

// Start in the past by approximately 2 hours
let start_block_number = latest_block_number
.checked_sub(config.start_scan)
.checked_sub(config.canonical_network.start_scan)
.unwrap_or_default();

let filter = Filter::new()
.address(config.canonical_network.address)
.address(config.canonical_network.world_id_addr)
.event_signature(TreeChanged::SIGNATURE_HASH);

let scanner = BlockScanner::new(
Expand Down Expand Up @@ -160,58 +160,64 @@ pub async fn run(config: Config) -> Result<()> {
}

fn init_relays(cfg: Config) -> Result<Vec<Relayer>> {
let mut relayers = Vec::new();
cfg.bridged_networks.iter().for_each(|n| match n.ty {
NetworkType::Evm => {
match &cfg.canonical_network.wallet {
WalletConfig::Mnemonic { mnemonic } => {
let signer = MnemonicBuilder::<English>::default()
.phrase(mnemonic)
.index(0)
.unwrap()
.build()
.expect("Failed to build wallet");
let wallet = EthereumWallet::new(signer);
let l1_provider = ProviderBuilder::default()
.with_recommended_fillers()
.wallet(wallet)
.on_http(
cfg.canonical_network.provider.rpc_endpoint.clone(),
cfg.bridged_networks
.iter()
.map(|bridged| {
let wallet_config = bridged
.wallet
.as_ref()
.or(cfg.wallet.as_ref())
.ok_or_eyre("No wallet configuration found")?;

match bridged.ty {
NetworkType::Evm => match wallet_config {
WalletConfig::Mnemonic { mnemonic } => {
let signer = MnemonicBuilder::<English>::default()
.phrase(mnemonic)
.index(0)
.unwrap()
.build()
.expect("Failed to build wallet");
let wallet = EthereumWallet::new(signer);
let l1_provider = ProviderBuilder::default()
.with_recommended_fillers()
.wallet(wallet)
.on_http(
cfg.canonical_network
.provider
.rpc_endpoint
.clone(),
);
let state_bridge = IStateBridgeInstance::new(
bridged.state_bridge_addr,
l1_provider,
);
let state_bridge = IStateBridgeInstance::new(
n.state_bridge_address,
l1_provider,
);

let signer = AlloySigner::new(state_bridge);

relayers.push(Relayer::Evm(EVMRelay::new(
Signer::AlloySigner(signer),
n.world_id_address,
n.provider.rpc_endpoint.clone(),
)));
}
WalletConfig::TxSitter {
url,
address: _,
gas_limit,
} => {
let signer = TxSitterSigner::new(
url.as_str(),
n.state_bridge_address,
*gas_limit,
);

relayers.push(Relayer::Evm(EVMRelay::new(
Signer::TxSitterSigner(signer),
n.world_id_address,
n.provider.rpc_endpoint.clone(),
)));
}
};
}
_ => {}
});

Ok(relayers)
let signer = AlloySigner::new(state_bridge);

Ok(Relayer::Evm(EVMRelay::new(
Signer::AlloySigner(signer),
bridged.world_id_addr,
bridged.provider.rpc_endpoint.clone(),
)))
}
WalletConfig::TxSitter { url, gas_limit } => {
let signer = TxSitterSigner::new(
url.as_str(),
bridged.state_bridge_addr,
*gas_limit,
);

Ok(Relayer::Evm(EVMRelay::new(
Signer::TxSitterSigner(signer),
bridged.world_id_addr,
bridged.provider.rpc_endpoint.clone(),
)))
}
},
NetworkType::Svm => unimplemented!(),
NetworkType::Scroll => unimplemented!(),
}
})
.collect()
}
3 changes: 3 additions & 0 deletions src/relay/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ impl TxSitterSigner {
}

impl RelaySigner for TxSitterSigner {
/// Propogate a new Root to the given network.
///
/// This is a long running operation and should probably be awaited in a background task.
async fn propagate_root(&self) -> Result<()> {
let ethers_selector = ethers_core::types::Bytes::from_static(
PROPOGATE_ROOT_SELECTOR.as_ref(),
Expand Down
Loading