From ef30de3e57ecb6f846fe94b36634b4d2aa378561 Mon Sep 17 00:00:00 2001 From: Mateo Date: Wed, 30 Oct 2024 15:15:53 +0100 Subject: [PATCH] rename --- Cargo.lock | 28 ++++---- crates/autopilot/Cargo.toml | 2 +- crates/autopilot/src/domain/settlement/mod.rs | 10 +-- .../src/domain/settlement/observer.rs | 2 +- .../src/infra/blockchain/authenticator.rs | 6 +- .../src/infra/blockchain/contracts.rs | 14 ++-- crates/autopilot/src/infra/blockchain/mod.rs | 28 ++++---- crates/autopilot/src/run.rs | 16 ++--- crates/{network => chain}/Cargo.toml | 2 +- crates/{network => chain}/LICENSE-APACHE | 0 crates/{network => chain}/LICENSE-MIT | 0 crates/{network => chain}/src/lib.rs | 66 +++++++++---------- crates/driver/example.toml | 2 +- .../src/domain/competition/solution/mod.rs | 2 +- .../driver/src/infra/blockchain/contracts.rs | 4 +- crates/driver/src/infra/config/file/load.rs | 10 +-- crates/driver/src/infra/config/file/mod.rs | 8 +-- crates/driver/src/infra/simulator/enso/mod.rs | 2 +- crates/driver/src/infra/solver/mod.rs | 2 +- crates/driver/src/tests/cases/jit_orders.rs | 8 +-- .../driver/src/tests/cases/protocol_fees.rs | 14 ++-- crates/driver/src/tests/setup/fee.rs | 4 +- crates/e2e/src/nodes/forked_node.rs | 2 +- crates/e2e/src/setup/deploy.rs | 8 +-- crates/orderbook/Cargo.toml | 2 +- crates/orderbook/src/run.rs | 10 +-- crates/shared/Cargo.toml | 2 +- .../src/bad_token/token_owner_finder.rs | 22 +++---- .../token_owner_finder/blockscout.rs | 24 +++---- .../bad_token/token_owner_finder/ethplorer.rs | 10 +-- crates/shared/src/bad_token/trace_call.rs | 4 +- crates/shared/src/price_estimation.rs | 2 +- crates/shared/src/price_estimation/factory.rs | 10 +-- .../src/price_estimation/native/coingecko.rs | 40 +++++------ crates/shared/src/sources.rs | 18 ++--- crates/solvers/Cargo.toml | 2 +- crates/solvers/src/infra/config/baseline.rs | 4 +- crates/solvers/src/infra/contracts.rs | 6 +- 38 files changed, 197 insertions(+), 199 deletions(-) rename crates/{network => chain}/Cargo.toml (94%) rename crates/{network => chain}/LICENSE-APACHE (100%) rename crates/{network => chain}/LICENSE-MIT (100%) rename crates/{network => chain}/src/lib.rs (73%) diff --git a/Cargo.lock b/Cargo.lock index d602b65c36..140edab451 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -277,6 +277,7 @@ dependencies = [ "async-trait", "bigdecimal", "bytes-hex", + "chain", "chrono", "clap", "contracts", @@ -297,7 +298,6 @@ dependencies = [ "mimalloc", "mockall 0.12.1", "model", - "network", "num", "number", "observe", @@ -1274,6 +1274,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chain" +version = "0.1.0" +dependencies = [ + "ethcontract", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "chrono" version = "0.4.38" @@ -3138,16 +3148,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "network" -version = "0.1.0" -dependencies = [ - "ethcontract", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "nom" version = "7.1.3" @@ -3400,6 +3400,7 @@ dependencies = [ "async-trait", "bigdecimal", "cached", + "chain", "chrono", "clap", "contracts", @@ -3416,7 +3417,6 @@ dependencies = [ "mockall 0.12.1", "model", "multibase", - "network", "num", "number", "observe", @@ -4466,6 +4466,7 @@ dependencies = [ "bigdecimal", "bytes-hex", "cached", + "chain", "chrono", "clap", "contracts", @@ -4487,7 +4488,6 @@ dependencies = [ "maplit", "mockall 0.12.1", "model", - "network", "num", "number", "observe", @@ -4626,6 +4626,7 @@ dependencies = [ "anyhow", "axum", "bigdecimal", + "chain", "chrono", "clap", "contracts", @@ -4640,7 +4641,6 @@ dependencies = [ "itertools 0.12.1", "mimalloc", "model", - "network", "num", "observe", "prometheus", diff --git a/crates/autopilot/Cargo.toml b/crates/autopilot/Cargo.toml index ad758711c5..8a28b46688 100644 --- a/crates/autopilot/Cargo.toml +++ b/crates/autopilot/Cargo.toml @@ -20,6 +20,7 @@ bytes-hex = { path = "../bytes-hex" } anyhow = { workspace = true } async-trait = { workspace = true } bigdecimal = { workspace = true } +chain = { path = "../chain" } chrono = { workspace = true } clap = { workspace = true } contracts = { path = "../contracts" } @@ -40,7 +41,6 @@ itertools = { workspace = true } maplit = { workspace = true } mimalloc = { workspace = true } model = { path = "../model" } -network = { path = "../network" } num = { workspace = true } number = { path = "../number" } order-validation = { path = "../order-validation" } diff --git a/crates/autopilot/src/domain/settlement/mod.rs b/crates/autopilot/src/domain/settlement/mod.rs index 436f84276c..b910a9ceb5 100644 --- a/crates/autopilot/src/domain/settlement/mod.rs +++ b/crates/autopilot/src/domain/settlement/mod.rs @@ -15,7 +15,7 @@ mod auction; mod observer; mod trade; mod transaction; -use network::Network; +use chain::Chain; pub use {auction::Auction, observer::Observer, trade::Trade, transaction::Transaction}; /// A settled transaction together with the `Auction`, for which it was executed @@ -107,11 +107,11 @@ impl Settlement { pub async fn new( settled: Transaction, persistence: &infra::Persistence, - network: &Network, + chain: &Chain, ) -> Result { let auction = persistence.get_auction(settled.auction_id).await?; - if settled.block > auction.block + max_settlement_age(network) { + if settled.block > auction.block + max_settlement_age(chain) { // A settled transaction references a VERY old auction. // // A hacky way to detect processing of production settlements in the staging @@ -143,9 +143,9 @@ impl Settlement { /// settlement from another environment. /// /// Currently set to ~6h -fn max_settlement_age(network: &Network) -> u64 { +fn max_settlement_age(chain: &Chain) -> u64 { const TARGET_AGE: u64 = 6 * 60 * 60 * 1000; // 6h in ms - network.blocks_in(TARGET_AGE).round() as u64 + chain.blocks_in(TARGET_AGE).round() as u64 } #[derive(Debug, thiserror::Error)] diff --git a/crates/autopilot/src/domain/settlement/observer.rs b/crates/autopilot/src/domain/settlement/observer.rs index 87bc46807f..631539f9ef 100644 --- a/crates/autopilot/src/domain/settlement/observer.rs +++ b/crates/autopilot/src/domain/settlement/observer.rs @@ -81,7 +81,7 @@ impl Observer { let settlement = match settlement::Settlement::new( transaction, &self.persistence, - self.eth.network(), + self.eth.chain(), ) .await { diff --git a/crates/autopilot/src/infra/blockchain/authenticator.rs b/crates/autopilot/src/infra/blockchain/authenticator.rs index 58d070dbff..bf0d72faa1 100644 --- a/crates/autopilot/src/infra/blockchain/authenticator.rs +++ b/crates/autopilot/src/infra/blockchain/authenticator.rs @@ -3,8 +3,8 @@ use { domain::{self, eth}, infra::blockchain::contracts::{deployment_address, Contracts}, }, + chain::Chain, ethcontract::{dyns::DynWeb3, GasPrice}, - network::Network, }; #[allow(dead_code)] @@ -23,13 +23,13 @@ impl Manager { /// Creates an authenticator which can remove solvers from the allow-list pub async fn new( web3: DynWeb3, - network: &Network, + chain: &Chain, contracts: Contracts, authenticator_pk: eth::H256, ) -> Self { let authenticator_role = contracts::Roles::at( &web3, - deployment_address(contracts::Roles::raw_contract(), network).expect("roles address"), + deployment_address(contracts::Roles::raw_contract(), chain).expect("roles address"), ); Self { diff --git a/crates/autopilot/src/infra/blockchain/contracts.rs b/crates/autopilot/src/infra/blockchain/contracts.rs index d864f1d73d..d5cccbe0db 100644 --- a/crates/autopilot/src/infra/blockchain/contracts.rs +++ b/crates/autopilot/src/infra/blockchain/contracts.rs @@ -1,4 +1,4 @@ -use {crate::domain, ethcontract::dyns::DynWeb3, network::Network, primitive_types::H160}; +use {crate::domain, chain::Chain, ethcontract::dyns::DynWeb3, primitive_types::H160}; #[derive(Debug, Clone)] pub struct Contracts { @@ -20,10 +20,10 @@ pub struct Addresses { } impl Contracts { - pub async fn new(web3: &DynWeb3, network: &Network, addresses: Addresses) -> Self { + pub async fn new(web3: &DynWeb3, chain: &Chain, addresses: Addresses) -> Self { let address_for = |contract: ðcontract::Contract, address: Option| { address - .or_else(|| deployment_address(contract, network)) + .or_else(|| deployment_address(contract, chain)) .unwrap() }; @@ -96,11 +96,11 @@ impl Contracts { } } -/// Returns the address of a contract for the specified network, or `None` if -/// there is no known deployment for the contract on that network. -pub fn deployment_address(contract: ðcontract::Contract, network: &Network) -> Option { +/// Returns the address of a contract for the specified chain, or `None` if +/// there is no known deployment for the contract on that chain. +pub fn deployment_address(contract: ðcontract::Contract, chain: &Chain) -> Option { contract .networks - .get(&network.chain_id().to_string()) + .get(&chain.id().to_string()) .map(|network| network.address) } diff --git a/crates/autopilot/src/infra/blockchain/mod.rs b/crates/autopilot/src/infra/blockchain/mod.rs index 226ee38780..f030cdf7eb 100644 --- a/crates/autopilot/src/infra/blockchain/mod.rs +++ b/crates/autopilot/src/infra/blockchain/mod.rs @@ -1,9 +1,9 @@ use { self::contracts::Contracts, crate::{boundary, domain::eth}, + chain::Chain, ethcontract::dyns::DynWeb3, ethrpc::block_stream::CurrentBlockWatcher, - network::Network, primitive_types::U256, std::time::Duration, thiserror::Error, @@ -16,7 +16,7 @@ pub mod contracts; /// An Ethereum RPC connection. pub struct Rpc { web3: DynWeb3, - network: Network, + chain: Chain, url: Url, } @@ -28,19 +28,19 @@ impl Rpc { ethrpc_args: &shared::ethrpc::Arguments, ) -> Result { let web3 = boundary::web3_client(url, ethrpc_args); - let network = - Network::try_from(web3.eth().chain_id().await?).map_err(|_| Error::UnsupportedChain)?; + let chain = + Chain::try_from(web3.eth().chain_id().await?).map_err(|_| Error::UnsupportedChain)?; Ok(Self { web3, - network, + chain, url: url.clone(), }) } - /// Returns the chain id for the RPC connection. - pub fn network(&self) -> Network { - self.network + /// Returns the chain for the RPC connection. + pub fn chain(&self) -> Chain { + self.chain } /// Returns a reference to the underlying web3 client. @@ -58,7 +58,7 @@ impl Rpc { #[derive(Clone)] pub struct Ethereum { web3: DynWeb3, - network: Network, + chain: Chain, current_block: CurrentBlockWatcher, contracts: Contracts, } @@ -72,25 +72,25 @@ impl Ethereum { /// any initialization error. pub async fn new( web3: DynWeb3, - network: &Network, + chain: &Chain, url: Url, addresses: contracts::Addresses, poll_interval: Duration, ) -> Self { - let contracts = Contracts::new(&web3, network, addresses).await; + let contracts = Contracts::new(&web3, chain, addresses).await; Self { current_block: ethrpc::block_stream::current_block_stream(url, poll_interval) .await .expect("couldn't initialize current block stream"), web3, - network: *network, + chain: *chain, contracts, } } - pub fn network(&self) -> &Network { - &self.network + pub fn chain(&self) -> &Chain { + &self.chain } /// Returns a stream that monitors the block chain to inform about the diff --git a/crates/autopilot/src/run.rs b/crates/autopilot/src/run.rs index db39e41734..47ee310714 100644 --- a/crates/autopilot/src/run.rs +++ b/crates/autopilot/src/run.rs @@ -23,13 +23,13 @@ use { shadow, solvable_orders::SolvableOrdersCache, }, + chain::Chain, clap::Parser, contracts::{BalancerV2Vault, IUniswapV3Factory}, ethcontract::{dyns::DynWeb3, errors::DeployError, BlockNumber}, ethrpc::block_stream::block_number_to_block_number_hash, futures::StreamExt, model::DomainSeparator, - network::Network, shared::{ account_balances, bad_token::{ @@ -94,12 +94,12 @@ async fn ethrpc(url: &Url, ethrpc_args: &shared::ethrpc::Arguments) -> infra::bl async fn ethereum( web3: DynWeb3, - network: &Network, + chain: &Chain, url: Url, contracts: infra::blockchain::contracts::Addresses, poll_interval: Duration, ) -> infra::Ethereum { - infra::Ethereum::new(web3, network, url, contracts, poll_interval).await + infra::Ethereum::new(web3, chain, url, contracts, poll_interval).await } pub async fn start(args: impl Iterator) { @@ -157,7 +157,7 @@ pub async fn run(args: Arguments) { } let ethrpc = ethrpc(&args.shared.node_url, &args.shared.ethrpc).await; - let chain = ethrpc.network(); + let chain = ethrpc.chain(); let web3 = ethrpc.web3().clone(); let url = ethrpc.url().clone(); let contracts = infra::blockchain::contracts::Addresses { @@ -198,7 +198,7 @@ pub async fn run(args: Arguments) { other => Some(other.unwrap()), }; - let network = Network::try_from(chain_id).unwrap(); + let chain = Chain::try_from(chain_id).unwrap(); let signature_validator = signature_validator::validator( &web3, @@ -233,7 +233,7 @@ pub async fn run(args: Arguments) { .shared .baseline_sources .clone() - .unwrap_or_else(|| shared::sources::defaults_for_network(&network)); + .unwrap_or_else(|| shared::sources::defaults_for_network(&chain)); tracing::info!(?baseline_sources, "using baseline sources"); let univ2_sources = baseline_sources .iter() @@ -261,7 +261,7 @@ pub async fn run(args: Arguments) { let finder = token_owner_finder::init( &args.token_owner_finder, web3.clone(), - &network, + &chain, &http_factory, &pair_providers, vault.as_ref(), @@ -312,7 +312,7 @@ pub async fn run(args: Arguments) { factory::Network { web3: web3.clone(), simulation_web3, - network, + chain, native_token: eth.contracts().weth().address(), settlement: eth.contracts().settlement().address(), authenticator: eth diff --git a/crates/network/Cargo.toml b/crates/chain/Cargo.toml similarity index 94% rename from crates/network/Cargo.toml rename to crates/chain/Cargo.toml index e7a6c4d25a..34e6d08df9 100644 --- a/crates/network/Cargo.toml +++ b/crates/chain/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "network" +name = "chain" version = "0.1.0" authors = ["Cow Protocol Developers "] edition = "2021" diff --git a/crates/network/LICENSE-APACHE b/crates/chain/LICENSE-APACHE similarity index 100% rename from crates/network/LICENSE-APACHE rename to crates/chain/LICENSE-APACHE diff --git a/crates/network/LICENSE-MIT b/crates/chain/LICENSE-MIT similarity index 100% rename from crates/network/LICENSE-MIT rename to crates/chain/LICENSE-MIT diff --git a/crates/network/src/lib.rs b/crates/chain/src/lib.rs similarity index 73% rename from crates/network/src/lib.rs rename to crates/chain/src/lib.rs index 5b232d50f9..f3dae36b98 100644 --- a/crates/network/src/lib.rs +++ b/crates/chain/src/lib.rs @@ -7,10 +7,10 @@ use { thiserror::Error, }; -/// Represents each available network +/// Represents each available chain #[derive(Clone, Copy, Debug, PartialEq)] #[repr(u64)] -pub enum Network { +pub enum Chain { Mainnet = 1, Goerli = 5, Gnosis = 100, @@ -19,15 +19,15 @@ pub enum Network { Base = 8453, } -impl Network { - /// Returns the network's chain ID - pub fn chain_id(&self) -> u64 { +impl Chain { + /// Returns the chain's chain ID + pub fn id(&self) -> u64 { *self as u64 } - /// Returns the canonical name of the network on CoW Protocol. + /// Returns the canonical name of the chain on CoW Protocol. pub fn name(&self) -> &'static str { - // You can find a list of available networks by network and chain id here: + // You can find a list of available networks by chain and chain id here: // https://chainid.network/chains.json match &self { Self::Mainnet => "Ethereum / Mainnet", @@ -68,7 +68,7 @@ impl Network { } } -impl TryFrom for Network { +impl TryFrom for Chain { type Error = Error; /// Initializes `Network` from a chain ID, returns error if the chain id is @@ -87,7 +87,7 @@ impl TryFrom for Network { } } -impl TryFrom for Network { +impl TryFrom for Chain { type Error = Error; /// Initializes `Network` from a chain ID, returns error if the chain id is @@ -103,7 +103,7 @@ impl TryFrom for Network { } } -impl<'de> Deserialize<'de> for Network { +impl<'de> Deserialize<'de> for Chain { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, @@ -111,7 +111,7 @@ impl<'de> Deserialize<'de> for Network { struct NetworkVisitor; impl<'de> de::Visitor<'de> for NetworkVisitor { - type Value = Network; + type Value = Chain; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("a u64 or a string") @@ -121,14 +121,14 @@ impl<'de> Deserialize<'de> for Network { where E: de::Error, { - Network::try_from(value).map_err(de::Error::custom) + Chain::try_from(value).map_err(de::Error::custom) } fn visit_str(self, value: &str) -> Result where E: de::Error, { - Network::try_from(value.parse::().map_err(de::Error::custom)?) + Chain::try_from(value.parse::().map_err(de::Error::custom)?) .map_err(de::Error::custom) } } @@ -151,32 +151,32 @@ mod test { fn test_blocks_in() { const TARGET_AGE: u64 = 6 * 60 * 60 * 1000; // 6h in ms - assert_eq!(Network::Mainnet.blocks_in(TARGET_AGE).round(), 1800.0); - assert_eq!(Network::Sepolia.blocks_in(TARGET_AGE).round(), 1800.0); - assert_eq!(Network::Goerli.blocks_in(TARGET_AGE).round(), 1800.0); - assert_eq!(Network::Gnosis.blocks_in(TARGET_AGE).round(), 4320.0); - assert_eq!(Network::Base.blocks_in(TARGET_AGE).round(), 10800.0); - assert_eq!(Network::ArbitrumOne.blocks_in(TARGET_AGE).round(), 86400.0); + assert_eq!(Chain::Mainnet.blocks_in(TARGET_AGE).round(), 1800.0); + assert_eq!(Chain::Sepolia.blocks_in(TARGET_AGE).round(), 1800.0); + assert_eq!(Chain::Goerli.blocks_in(TARGET_AGE).round(), 1800.0); + assert_eq!(Chain::Gnosis.blocks_in(TARGET_AGE).round(), 4320.0); + assert_eq!(Chain::Base.blocks_in(TARGET_AGE).round(), 10800.0); + assert_eq!(Chain::ArbitrumOne.blocks_in(TARGET_AGE).round(), 86400.0); } #[test] fn test_deserialize_from_u64() { // Test valid u64 deserialization let json_data = "1"; // Should deserialize to Network::Mainnet - let network: Network = serde_json::from_str(json_data).unwrap(); - assert_eq!(network, Network::Mainnet); + let network: Chain = serde_json::from_str(json_data).unwrap(); + assert_eq!(network, Chain::Mainnet); let json_data = "5"; // Should deserialize to Network::Goerli - let network: Network = serde_json::from_str(json_data).unwrap(); - assert_eq!(network, Network::Goerli); + let network: Chain = serde_json::from_str(json_data).unwrap(); + assert_eq!(network, Chain::Goerli); let json_data = "100"; // Should deserialize to Network::Gnosis - let network: Network = serde_json::from_str(json_data).unwrap(); - assert_eq!(network, Network::Gnosis); + let network: Chain = serde_json::from_str(json_data).unwrap(); + assert_eq!(network, Chain::Gnosis); // Test invalid u64 deserialization (should return an error) let json_data = "9999999"; // Not a valid Network variant - let result: Result = serde_json::from_str(json_data); + let result: Result = serde_json::from_str(json_data); assert!(result.is_err()); } @@ -184,20 +184,20 @@ mod test { fn test_deserialize_from_str() { // Test valid string deserialization let json_data = "\"1\""; // Should parse to u64 1 and then to Network::Mainnet - let network: Network = serde_json::from_str(json_data).unwrap(); - assert_eq!(network, Network::Mainnet); + let network: Chain = serde_json::from_str(json_data).unwrap(); + assert_eq!(network, Chain::Mainnet); let json_data = "\"5\""; // Should parse to u64 5 and then to Network::Goerli - let network: Network = serde_json::from_str(json_data).unwrap(); - assert_eq!(network, Network::Goerli); + let network: Chain = serde_json::from_str(json_data).unwrap(); + assert_eq!(network, Chain::Goerli); let json_data = "\"100\""; // Should parse to u64 100 and then to Network::Gnosis - let network: Network = serde_json::from_str(json_data).unwrap(); - assert_eq!(network, Network::Gnosis); + let network: Chain = serde_json::from_str(json_data).unwrap(); + assert_eq!(network, Chain::Gnosis); // Test invalid string deserialization (should return an error) let json_data = "\"invalid\""; // Cannot be parsed as u64 - let result: Result = serde_json::from_str(json_data); + let result: Result = serde_json::from_str(json_data); assert!(result.is_err()); } } diff --git a/crates/driver/example.toml b/crates/driver/example.toml index 926c84ae08..c4e4a3d49f 100644 --- a/crates/driver/example.toml +++ b/crates/driver/example.toml @@ -102,4 +102,4 @@ max-order-age = "1m" # [enso] # url = "http://localhost:8454" -# network-block-interval = "12s" +# chain-block-interval = "12s" diff --git a/crates/driver/src/domain/competition/solution/mod.rs b/crates/driver/src/domain/competition/solution/mod.rs index 531568f19f..5b4d739e1e 100644 --- a/crates/driver/src/domain/competition/solution/mod.rs +++ b/crates/driver/src/domain/competition/solution/mod.rs @@ -72,7 +72,7 @@ impl Solution { surplus_capturing_jit_order_owners: &HashSet, ) -> Result { // Surplus capturing JIT orders behave like Fulfillment orders. They capture - // surplus, pay network fees and contribute to score of a solution. + // surplus, pay chain fees and contribute to score of a solution. // To make sure that all the same logic and checks get applied we convert them // right away. for trade in &mut trades { diff --git a/crates/driver/src/infra/blockchain/contracts.rs b/crates/driver/src/infra/blockchain/contracts.rs index 8575cd58df..acc9b020bf 100644 --- a/crates/driver/src/infra/blockchain/contracts.rs +++ b/crates/driver/src/infra/blockchain/contracts.rs @@ -126,8 +126,8 @@ pub struct CowAmmConfig { pub index_start: u64, } -/// Returns the address of a contract for the specified network, or `None` if -/// there is no known deployment for the contract on that network. +/// Returns the address of a contract for the specified chain, or `None` if +/// there is no known deployment for the contract on that chain. pub fn deployment_address( contract: ðcontract::Contract, network_id: eth::ChainId, diff --git a/crates/driver/src/infra/config/file/load.rs b/crates/driver/src/infra/config/file/load.rs index ef338d14f4..33c129c9a0 100644 --- a/crates/driver/src/infra/config/file/load.rs +++ b/crates/driver/src/infra/config/file/load.rs @@ -18,7 +18,7 @@ use { }; /// Load the driver configuration from a TOML file for the specifed Ethereum -/// network. +/// chain. /// /// # Panics /// @@ -131,7 +131,7 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config { liquidity::config::UniswapV2::testnet_uniswapv2(chain) } } - .expect("no Uniswap V2 preset for current network"), + .expect("no Uniswap V2 preset for current chain"), file::UniswapV2Config::Manual { router, pool_code, @@ -152,7 +152,7 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config { file::SwaprConfig::Preset { preset } => match preset { file::SwaprPreset::Swapr => liquidity::config::Swapr::swapr(chain), } - .expect("no Swapr preset for current network"), + .expect("no Swapr preset for current chain"), file::SwaprConfig::Manual { router, pool_code, @@ -181,7 +181,7 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config { liquidity::config::UniswapV3::uniswap_v3(&graph_url, chain) } } - .expect("no Uniswap V3 preset for current network") + .expect("no Uniswap V3 preset for current chain") }, file::UniswapV3Config::Manual { router, @@ -211,7 +211,7 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config { liquidity::config::BalancerV2::balancer_v2(&graph_url, chain) } } - .expect("no Balancer V2 preset for current network") + .expect("no Balancer V2 preset for current chain") }, file::BalancerV2Config::Manual { vault, diff --git a/crates/driver/src/infra/config/file/mod.rs b/crates/driver/src/infra/config/file/mod.rs index b461883636..d8f0caebc5 100644 --- a/crates/driver/src/infra/config/file/mod.rs +++ b/crates/driver/src/infra/config/file/mod.rs @@ -89,7 +89,7 @@ struct SubmissionConfig { target_confirm_time: Duration, /// Amount of time to wait before retrying to submit the tx to - /// the ethereum network. + /// the ethereum chain. #[serde(with = "humantime_serde", default = "default_retry_interval")] retry_interval: Duration, @@ -306,7 +306,7 @@ struct Timeouts { http_time_buffer: Duration, /// Maximum time allocated for solver engines to return the solutions back - /// to the driver, in percentage of total driver deadline (after network + /// to the driver, in percentage of total driver deadline (after chain /// buffer). Remaining time is spent on encoding and postprocessing the /// returned solutions. Expected value [0, 1] #[serde(default = "default_solving_share_of_deadline")] @@ -382,8 +382,8 @@ struct TenderlyConfig { struct EnsoConfig { /// URL at which the trade simulator is hosted url: Url, - /// How often the network produces a new block. If this is not set the - /// system assumes an unpredictable network like proof-of-work. + /// How often the chain produces a new block. If this is not set the + /// system assumes an unpredictable chain like proof-of-work. #[serde(default, with = "humantime_serde")] network_block_interval: Option, } diff --git a/crates/driver/src/infra/simulator/enso/mod.rs b/crates/driver/src/infra/simulator/enso/mod.rs index 15a9460884..65f071e36e 100644 --- a/crates/driver/src/infra/simulator/enso/mod.rs +++ b/crates/driver/src/infra/simulator/enso/mod.rs @@ -22,7 +22,7 @@ pub(super) struct Enso { pub struct Config { /// The URL of the Transaction Simulator API. pub url: reqwest::Url, - /// The time between new blocks in the network. + /// The time between new blocks in the chain. pub network_block_interval: Option, } diff --git a/crates/driver/src/infra/solver/mod.rs b/crates/driver/src/infra/solver/mod.rs index ba7332dd65..e17482befc 100644 --- a/crates/driver/src/infra/solver/mod.rs +++ b/crates/driver/src/infra/solver/mod.rs @@ -68,7 +68,7 @@ pub enum Liquidity { #[derive(Clone, Copy, Debug)] pub struct Timeouts { /// Maximum time allocated for http request/reponse to propagate through - /// network. + /// chain. pub http_delay: chrono::Duration, /// Maximum time allocated for solver engines to return the solutions back /// to the driver, in percentage of total driver deadline. diff --git a/crates/driver/src/tests/cases/jit_orders.rs b/crates/driver/src/tests/cases/jit_orders.rs index 243b709b83..e03a50f5fb 100644 --- a/crates/driver/src/tests/cases/jit_orders.rs +++ b/crates/driver/src/tests/cases/jit_orders.rs @@ -25,9 +25,9 @@ struct Amounts { } struct Execution { - // The executed net-amounts (including network fee) reported by the solver + // The executed net-amounts (including chain fee) reported by the solver solver: Amounts, - // The executed net-amounts (including network and protocol) reported by the driver + // The executed net-amounts (including chain and protocol) reported by the driver driver: Amounts, } @@ -132,7 +132,7 @@ async fn surplus_protocol_fee_jit_order_from_surplus_capturing_owner_not_capped( side: Side::Buy, }, execution: Execution { - // 20 ETH surplus in sell token (after network fee), half of which is kept by the + // 20 ETH surplus in sell token (after chain fee), half of which is kept by the // protocol solver: Amounts { sell: 30.ether().into_wei(), @@ -170,7 +170,7 @@ async fn surplus_protocol_fee_jit_order_not_capped() { side: Side::Buy, }, execution: Execution { - // 20 ETH surplus in sell token (after network fee), half of which is kept by the + // 20 ETH surplus in sell token (after chain fee), half of which is kept by the // protocol solver: Amounts { sell: 30.ether().into_wei(), diff --git a/crates/driver/src/tests/cases/protocol_fees.rs b/crates/driver/src/tests/cases/protocol_fees.rs index 0b928c54bf..36d0536f13 100644 --- a/crates/driver/src/tests/cases/protocol_fees.rs +++ b/crates/driver/src/tests/cases/protocol_fees.rs @@ -23,9 +23,9 @@ struct Amounts { } struct Execution { - // The executed net-amounts (including network fee) reported by the solver + // The executed net-amounts (including chain fee) reported by the solver solver: Amounts, - // The executed net-amounts (including network and protocol) reported by the driver + // The executed net-amounts (including chain and protocol) reported by the driver driver: Amounts, } @@ -72,7 +72,7 @@ async fn protocol_fee_test_case(test_case: TestCase) { .kind(order::Kind::Limit) .sell_amount(test_case.order.sell_amount) .buy_amount(test_case.order.buy_amount) - // Expected amounts already account for network fee, so it doesn't matter for the math. + // Expected amounts already account for chain fee, so it doesn't matter for the math. // However, it cannot be zero, otherwise the order would be perceived as a StaticFee orders (which cannot have Protocol Fees) // todo: can be cleaned up after https://github.com/cowprotocol/services/issues/2507 .solver_fee(Some(solver_fee)) @@ -121,7 +121,7 @@ async fn triple_surplus_protocol_fee_buy_order_not_capped() { side: order::Side::Buy, }, execution: Execution { - // 20 ETH surplus in sell token (after network fee) + // 20 ETH surplus in sell token (after chain fee) // The protocol fees are applied one by one to the orders, altering the order pricing // For this example: // -> First fee policy: @@ -166,7 +166,7 @@ async fn triple_surplus_protocol_fee_sell_order_not_capped() { side: order::Side::Sell, }, execution: Execution { - // 20 ETH surplus in sell token (after network fee) + // 20 ETH surplus in sell token (after chain fee) // The protocol fees are applied one by one to the orders, altering the order pricing // For this example: // -> First fee policy: @@ -354,7 +354,7 @@ async fn surplus_protocol_fee_buy_order_not_capped() { side: order::Side::Buy, }, execution: Execution { - // 20 ETH surplus in sell token (after network fee), half of which is kept by the + // 20 ETH surplus in sell token (after chain fee), half of which is kept by the // protocol solver: Amounts { sell: 30.ether().into_wei(), @@ -451,7 +451,7 @@ async fn surplus_protocol_fee_partial_buy_order_not_capped() { side: order::Side::Buy, }, execution: Execution { - // 10 ETH surplus in sell token (after network fee), half of which is kept by the + // 10 ETH surplus in sell token (after chain fee), half of which is kept by the // protocol solver: Amounts { sell: 10.ether().into_wei(), diff --git a/crates/driver/src/tests/setup/fee.rs b/crates/driver/src/tests/setup/fee.rs index 384f2240f1..a9d0e54f4a 100644 --- a/crates/driver/src/tests/setup/fee.rs +++ b/crates/driver/src/tests/setup/fee.rs @@ -12,10 +12,10 @@ pub struct Quote { /// How much tokens the trader is expected to buy #[serde_as(as = "HexOrDecimalU256")] pub buy: eth::U256, - /// How much tokens the user is expected to sell (excluding network fee) + /// How much tokens the user is expected to sell (excluding chain fee) #[serde_as(as = "HexOrDecimalU256")] pub sell: eth::U256, - /// The expected network fee, which is expected to be taken as + /// The expected chain fee, which is expected to be taken as /// additional sell amount. #[serde_as(as = "HexOrDecimalU256")] pub network_fee: eth::U256, diff --git a/crates/e2e/src/nodes/forked_node.rs b/crates/e2e/src/nodes/forked_node.rs index 066e847a76..68acdb86c1 100644 --- a/crates/e2e/src/nodes/forked_node.rs +++ b/crates/e2e/src/nodes/forked_node.rs @@ -26,7 +26,7 @@ impl Namespace for ForkedNodeApi { /// Implements functions that are only available in a forked node. /// -/// Relevant RPC calls for the Anvil network can be found at: +/// Relevant RPC calls for the Anvil chain can be found at: /// https://book.getfoundry.sh/reference/anvil/ impl ForkedNodeApi { pub fn fork(&self, fork_url: &Url) -> CallFuture<(), T::Out> { diff --git a/crates/e2e/src/setup/deploy.rs b/crates/e2e/src/setup/deploy.rs index 3cf797dba1..8952101ac4 100644 --- a/crates/e2e/src/setup/deploy.rs +++ b/crates/e2e/src/setup/deploy.rs @@ -37,9 +37,9 @@ impl Contracts { .eth() .chain_id() .await - .expect("get network ID failed") + .expect("get chain ID failed") .to_string(); - tracing::info!("connected to forked test network {}", network_id); + tracing::info!("connected to forked test chain {}", network_id); let gp_settlement = GPv2Settlement::deployed(web3).await.unwrap(); let cow_amm_helper = match contracts::CowAmmLegacyHelper::deployed(web3).await { @@ -82,9 +82,9 @@ impl Contracts { .eth() .chain_id() .await - .expect("get network ID failed") + .expect("get chain ID failed") .to_string(); - tracing::info!("connected to test network {}", network_id); + tracing::info!("connected to test chain {}", network_id); let accounts: Vec
= web3.eth().accounts().await.expect("get accounts failed"); let admin = accounts[0]; diff --git a/crates/orderbook/Cargo.toml b/crates/orderbook/Cargo.toml index 660912ec46..ddb3b05a7c 100644 --- a/crates/orderbook/Cargo.toml +++ b/crates/orderbook/Cargo.toml @@ -22,6 +22,7 @@ app-data-hash = { path = "../app-data-hash" } async-trait = { workspace = true } bigdecimal = { workspace = true } cached = { workspace = true } +chain = { path = "../chain" } chrono = { workspace = true, features = ["clock"] } clap = { workspace = true } contracts = { path = "../contracts" } @@ -37,7 +38,6 @@ maplit = { workspace = true } mimalloc = { workspace = true } model = { path = "../model" } multibase = "0.9" -network = { path = "../network" } num = { workspace = true } number = { path = "../number" } order-validation = { path = "../order-validation" } diff --git a/crates/orderbook/src/run.rs b/crates/orderbook/src/run.rs index ff346ab6be..6d29719637 100644 --- a/crates/orderbook/src/run.rs +++ b/crates/orderbook/src/run.rs @@ -10,12 +10,12 @@ use { }, anyhow::{anyhow, Context, Result}, app_data::Validator, + chain::Chain, clap::Parser, contracts::{BalancerV2Vault, GPv2Settlement, HooksTrampoline, IUniswapV3Factory, WETH9}, ethcontract::errors::DeployError, futures::{FutureExt, StreamExt}, model::{order::BUY_ETH_ADDRESS, DomainSeparator}, - network::Network, order_validation, shared::{ account_balances, @@ -104,7 +104,7 @@ pub async fn run(args: Arguments) { .expect("load native token contract"), }; - let network = Network::try_from(chain_id).unwrap(); + let chain = Chain::try_from(chain_id).unwrap(); let signature_validator = signature_validator::validator( &web3, @@ -165,7 +165,7 @@ pub async fn run(args: Arguments) { .shared .baseline_sources .clone() - .unwrap_or_else(|| sources::defaults_for_network(&network)); + .unwrap_or_else(|| sources::defaults_for_network(&chain)); tracing::info!(?baseline_sources, "using baseline sources"); let univ2_sources = baseline_sources .iter() @@ -198,7 +198,7 @@ pub async fn run(args: Arguments) { let finder = token_owner_finder::init( &args.token_owner_finder, web3.clone(), - &network, + &chain, &http_factory, &pair_providers, vault.as_ref(), @@ -255,7 +255,7 @@ pub async fn run(args: Arguments) { factory::Network { web3: web3.clone(), simulation_web3, - network, + chain, native_token: native_token.address(), settlement: settlement_contract.address(), authenticator: settlement_contract diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index ab2696dc7e..01dce3e1d9 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -16,6 +16,7 @@ bytes-hex = { path = "../bytes-hex" } async-trait = { workspace = true } bigdecimal = { workspace = true } cached = { workspace = true } +chain = { path = "../chain" } chrono = { workspace = true, features = ["clock"] } clap = { workspace = true } contracts = { path = "../contracts" } @@ -38,7 +39,6 @@ lazy_static = { workspace = true } maplit = { workspace = true } mockall = { workspace = true } model = { path = "../model" } -network = { path = "../network" } num = { workspace = true } number = { path = "../number" } order-validation = { path = "../order-validation" } diff --git a/crates/shared/src/bad_token/token_owner_finder.rs b/crates/shared/src/bad_token/token_owner_finder.rs index b733c3e919..7438959cb0 100644 --- a/crates/shared/src/bad_token/token_owner_finder.rs +++ b/crates/shared/src/bad_token/token_owner_finder.rs @@ -31,10 +31,10 @@ use { sources::uniswap_v2::pair_provider::PairProvider, }, anyhow::{Context, Result}, + chain::Chain, contracts::{BalancerV2Vault, IUniswapV3Factory, ERC20}, ethcontract::U256, futures::{Stream, StreamExt as _}, - network::Network, primitive_types::H160, rate_limit::Strategy, reqwest::Url, @@ -191,13 +191,11 @@ pub enum TokenOwnerFindingStrategy { impl TokenOwnerFindingStrategy { /// Returns the default set of token owner finding strategies. - pub fn defaults_for_network(network: &Network) -> &'static [Self] { - match network { - Network::Mainnet => &[Self::Liquidity, Self::Blockscout, Self::Ethplorer], - Network::Gnosis => &[Self::Liquidity, Self::Blockscout], - Network::Sepolia | Network::Goerli | Network::ArbitrumOne | Network::Base => { - &[Self::Liquidity] - } + pub fn defaults_for_network(chain: &Chain) -> &'static [Self] { + match chain { + Chain::Mainnet => &[Self::Liquidity, Self::Blockscout, Self::Ethplorer], + Chain::Gnosis => &[Self::Liquidity, Self::Blockscout], + Chain::Sepolia | Chain::Goerli | Chain::ArbitrumOne | Chain::Base => &[Self::Liquidity], } } } @@ -273,7 +271,7 @@ impl Display for Arguments { pub async fn init( args: &Arguments, web3: Web3, - network: &Network, + chain: &Chain, http_factory: &HttpClientFactory, pair_providers: &[PairProvider], vault: Option<&BalancerV2Vault>, @@ -285,7 +283,7 @@ pub async fn init( let finders = args .token_owner_finders .as_deref() - .unwrap_or_else(|| TokenOwnerFindingStrategy::defaults_for_network(network)); + .unwrap_or_else(|| TokenOwnerFindingStrategy::defaults_for_network(chain)); tracing::debug!(?finders, "initializing token owner finders"); let mut proposers = Vec::>::new(); @@ -318,7 +316,7 @@ pub async fn init( if finders.contains(&TokenOwnerFindingStrategy::Blockscout) { let mut blockscout = - BlockscoutTokenOwnerFinder::with_network(http_factory.create(), network)?; + BlockscoutTokenOwnerFinder::with_network(http_factory.create(), chain)?; if let Some(blockscout_config) = &args.blockscout { blockscout.with_base_url(blockscout_config.blockscout_api_url.clone()); blockscout.with_api_key(blockscout_config.blockscout_api_key.clone()); @@ -335,7 +333,7 @@ pub async fn init( args.ethplorer .as_ref() .map(|ethplorer| ethplorer.ethplorer_api_key.clone()), - network, + chain, )?; if let Some(ethplorer_config) = &args.ethplorer { ethplorer.with_base_url(ethplorer_config.ethplorer_api_url.clone()); diff --git a/crates/shared/src/bad_token/token_owner_finder/blockscout.rs b/crates/shared/src/bad_token/token_owner_finder/blockscout.rs index d63ec18d16..d8fdf4ddd7 100644 --- a/crates/shared/src/bad_token/token_owner_finder/blockscout.rs +++ b/crates/shared/src/bad_token/token_owner_finder/blockscout.rs @@ -1,8 +1,8 @@ use { super::TokenOwnerProposing, anyhow::Result, + chain::Chain, ethcontract::H160, - network::Network, prometheus::IntCounterVec, prometheus_metric_storage::MetricStorage, rate_limit::{back_off, RateLimiter, Strategy}, @@ -18,14 +18,14 @@ pub struct BlockscoutTokenOwnerFinder { } impl BlockscoutTokenOwnerFinder { - pub fn with_network(client: Client, network: &Network) -> Result { - let base_url = match network { - Network::Mainnet => "https://eth.blockscout.com/api", - Network::Goerli => "https://eth-goerli.blockscout.com/api", - Network::Gnosis => "https://blockscout.com/xdai/mainnet/api", - Network::Sepolia => "https://eth-sepolia.blockscout.com/api", - Network::ArbitrumOne => "https://arbitrum.blockscout.com/api", - Network::Base => "https://base.blockscout.com/api", + pub fn with_network(client: Client, chain: &Chain) -> Result { + let base_url = match chain { + Chain::Mainnet => "https://eth.blockscout.com/api", + Chain::Goerli => "https://eth-goerli.blockscout.com/api", + Chain::Gnosis => "https://blockscout.com/xdai/mainnet/api", + Chain::Sepolia => "https://eth-sepolia.blockscout.com/api", + Chain::ArbitrumOne => "https://arbitrum.blockscout.com/api", + Chain::Base => "https://base.blockscout.com/api", }; Ok(Self { @@ -140,7 +140,7 @@ mod tests { #[ignore] async fn test_blockscout_token_finding_mainnet() { let finder = - BlockscoutTokenOwnerFinder::with_network(Client::default(), &Network::Mainnet).unwrap(); + BlockscoutTokenOwnerFinder::with_network(Client::default(), &Chain::Mainnet).unwrap(); let owners = finder .find_candidate_owners(H160(hex!("1337BedC9D22ecbe766dF105c9623922A27963EC"))) .await; @@ -151,7 +151,7 @@ mod tests { #[ignore] async fn test_blockscout_token_finding_xdai() { let finder = - BlockscoutTokenOwnerFinder::with_network(Client::default(), &Network::Gnosis).unwrap(); + BlockscoutTokenOwnerFinder::with_network(Client::default(), &Chain::Gnosis).unwrap(); let owners = finder .find_candidate_owners(H160(hex!("1337BedC9D22ecbe766dF105c9623922A27963EC"))) .await; @@ -162,7 +162,7 @@ mod tests { #[ignore] async fn test_blockscout_token_finding_no_owners() { let finder = - BlockscoutTokenOwnerFinder::with_network(Client::default(), &Network::Gnosis).unwrap(); + BlockscoutTokenOwnerFinder::with_network(Client::default(), &Chain::Gnosis).unwrap(); let owners = finder .find_candidate_owners(H160(hex!("000000000000000000000000000000000000def1"))) .await; diff --git a/crates/shared/src/bad_token/token_owner_finder/ethplorer.rs b/crates/shared/src/bad_token/token_owner_finder/ethplorer.rs index c075c28814..89355b1310 100644 --- a/crates/shared/src/bad_token/token_owner_finder/ethplorer.rs +++ b/crates/shared/src/bad_token/token_owner_finder/ethplorer.rs @@ -1,8 +1,8 @@ use { super::TokenOwnerProposing, anyhow::{ensure, Result}, + chain::Chain, ethcontract::H160, - network::Network, prometheus::IntCounterVec, prometheus_metric_storage::MetricStorage, rate_limit::{back_off, RateLimiter, Strategy}, @@ -29,10 +29,10 @@ impl EthplorerTokenOwnerFinder { pub fn try_with_network( client: Client, api_key: Option, - network: &Network, + chain: &Chain, ) -> Result { ensure!( - *network == Network::Mainnet, + *chain == Chain::Mainnet, "Ethplorer API unsupported network" ); Ok(Self { @@ -157,7 +157,7 @@ mod tests { #[ignore] async fn token_finding_mainnet() { let finder = - EthplorerTokenOwnerFinder::try_with_network(Client::default(), None, &Network::Mainnet) + EthplorerTokenOwnerFinder::try_with_network(Client::default(), None, &Chain::Mainnet) .unwrap(); let owners = finder .find_candidate_owners(H160(hex!("1337BedC9D22ecbe766dF105c9623922A27963EC"))) @@ -169,7 +169,7 @@ mod tests { #[ignore] async fn returns_no_owners_on_invalid_token() { let finder = - EthplorerTokenOwnerFinder::try_with_network(Client::default(), None, &Network::Gnosis) + EthplorerTokenOwnerFinder::try_with_network(Client::default(), None, &Chain::Gnosis) .unwrap(); let owners = finder .find_candidate_owners(H160(hex!("000000000000000000000000000000000000def1"))) diff --git a/crates/shared/src/bad_token/trace_call.rs b/crates/shared/src/bad_token/trace_call.rs index 8082f1f457..00da8feb3c 100644 --- a/crates/shared/src/bad_token/trace_call.rs +++ b/crates/shared/src/bad_token/trace_call.rs @@ -331,9 +331,9 @@ mod tests { ethrpc::create_env_test_transport, sources::{uniswap_v2, BaselineSource}, }, + chain::Chain, contracts::{BalancerV2Vault, IUniswapV3Factory}, hex_literal::hex, - network::Network, std::{env, time::Duration}, web3::types::{ Action, @@ -700,7 +700,7 @@ mod tests { Arc::new( BlockscoutTokenOwnerFinder::with_network( reqwest::Client::new(), - &Network::Mainnet, + &Chain::Mainnet, ) .unwrap(), ), diff --git a/crates/shared/src/price_estimation.rs b/crates/shared/src/price_estimation.rs index 6a8fa88674..fceced8b7c 100644 --- a/crates/shared/src/price_estimation.rs +++ b/crates/shared/src/price_estimation.rs @@ -167,7 +167,7 @@ pub struct Arguments { /// The amount in native tokens atoms to use for price estimation. Should be /// reasonably large so that small pools do not influence the prices. If - /// not set a reasonable default is used based on network id. + /// not set a reasonable default is used based on chain id. #[clap(long, env, value_parser = U256::from_dec_str)] pub amount_to_estimate_prices_with: Option, diff --git a/crates/shared/src/price_estimation/factory.rs b/crates/shared/src/price_estimation/factory.rs index 9e60ba3a4a..03868ff1b1 100644 --- a/crates/shared/src/price_estimation/factory.rs +++ b/crates/shared/src/price_estimation/factory.rs @@ -56,7 +56,7 @@ struct EstimatorEntry { pub struct Network { pub web3: Web3, pub simulation_web3: Option, - pub network: network::Network, + pub chain: chain::Chain, pub native_token: H160, pub settlement: H160, pub authenticator: H160, @@ -101,7 +101,7 @@ impl<'a> PriceEstimatorFactory<'a> { .tenderly .get_api_instance(&components.http_factory, "price_estimation".to_owned()) .unwrap() - .map(|t| TenderlyCodeSimulator::new(t, network.network.chain_id())); + .map(|t| TenderlyCodeSimulator::new(t, network.chain.id())); let simulator: Arc = match tenderly { Some(tenderly) => Arc::new(code_simulation::Web3ThenTenderly::new( @@ -129,7 +129,7 @@ impl<'a> PriceEstimatorFactory<'a> { .or_else(|| { Some( self.network - .network + .chain .default_amount_to_estimate_native_prices_with(), ) }) @@ -211,7 +211,7 @@ impl<'a> PriceEstimatorFactory<'a> { self.components.http_factory.create(), self.args.one_inch_url.clone(), self.args.one_inch_api_key.clone(), - self.network.network.chain_id(), + self.network.chain.id(), self.network.block_stream.clone(), self.components.tokens.clone(), ), @@ -225,7 +225,7 @@ impl<'a> PriceEstimatorFactory<'a> { self.components.http_factory.create(), self.args.coin_gecko.coin_gecko_url.clone(), self.args.coin_gecko.coin_gecko_api_key.clone(), - &self.network.network, + &self.network.chain, weth.address(), self.components.tokens.clone(), ) diff --git a/crates/shared/src/price_estimation/native/coingecko.rs b/crates/shared/src/price_estimation/native/coingecko.rs index b2139122e0..49d33cf10e 100644 --- a/crates/shared/src/price_estimation/native/coingecko.rs +++ b/crates/shared/src/price_estimation/native/coingecko.rs @@ -5,8 +5,8 @@ use { token_info::{TokenInfo, TokenInfoFetching}, }, anyhow::{anyhow, Context, Result}, + chain::Chain, futures::{future::BoxFuture, FutureExt}, - network::Network, primitive_types::H160, reqwest::{Client, StatusCode}, rust_decimal::{prelude::ToPrimitive, Decimal, MathematicalOps}, @@ -54,7 +54,7 @@ impl CoinGecko { client: Client, base_url: Url, api_key: Option, - network: &Network, + chain: &Chain, native_token: H160, token_infos: Arc, ) -> Result { @@ -69,13 +69,13 @@ impl CoinGecko { decimals: denominator_decimals, }; - let chain = match network { - Network::Mainnet => "ethereum".to_string(), - Network::Gnosis => "xdai".to_string(), - Network::ArbitrumOne => "arbitrum-one".to_string(), - Network::Base => "base".to_string(), - Network::Sepolia | Network::Goerli => { - anyhow::bail!("unsupported network {}", network.name()) + let chain = match chain { + Chain::Mainnet => "ethereum".to_string(), + Chain::Gnosis => "xdai".to_string(), + Chain::ArbitrumOne => "arbitrum-one".to_string(), + Chain::Base => "base".to_string(), + Chain::Sepolia | Chain::Goerli => { + anyhow::bail!("unsupported network {}", chain.name()) } }; Ok(Self { @@ -308,25 +308,25 @@ mod tests { client: Client, base_url: Url, api_key: Option, - network: &Network, + chain: &Chain, token_infos: Arc, ) -> Result { - let (chain, denominator) = match network { - Network::Mainnet => ( + let (chain, denominator) = match chain { + Chain::Mainnet => ( "ethereum".to_string(), Denominator { address: addr!("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"), decimals: 18, }, ), - Network::Gnosis => ( + Chain::Gnosis => ( "xdai".to_string(), Denominator { address: addr!("e91d153e0b41518a2ce8dd3d7944fa863463a97d"), decimals: 18, }, ), - Network::ArbitrumOne => ( + Chain::ArbitrumOne => ( "arbitrum-one".to_string(), Denominator { address: addr!("82af49447d8a07e3bd95bd0d56f35241523fbab1"), @@ -383,7 +383,7 @@ mod tests { Client::default(), Url::parse(BASE_API_URL).unwrap(), None, - &Network::Mainnet, + &Chain::Mainnet, default_token_info_fetcher(), ) .unwrap(); @@ -403,7 +403,7 @@ mod tests { Client::default(), Url::parse(BASE_API_PRO_URL).unwrap(), env::var("COIN_GECKO_API_KEY").ok(), - &Network::Gnosis, + &Chain::Gnosis, default_token_info_fetcher(), ) .unwrap(); @@ -423,7 +423,7 @@ mod tests { Client::default(), Url::parse(BASE_API_PRO_URL).unwrap(), env::var("COIN_GECKO_API_KEY").ok(), - &Network::Gnosis, + &Chain::Gnosis, default_token_info_fetcher(), ) .unwrap(); @@ -449,7 +449,7 @@ mod tests { Client::default(), Url::parse(BASE_API_PRO_URL).unwrap(), env::var("COIN_GECKO_API_KEY").ok(), - &Network::Gnosis, + &Chain::Gnosis, default_token_info_fetcher(), ) .unwrap(); @@ -490,7 +490,7 @@ mod tests { Client::default(), Url::parse(BASE_API_PRO_URL).unwrap(), env::var("COIN_GECKO_API_KEY").ok(), - &Network::Gnosis, + &Chain::Gnosis, Arc::new(mock), ) .unwrap(); @@ -538,7 +538,7 @@ mod tests { Client::default(), Url::parse(BASE_API_PRO_URL).unwrap(), env::var("COIN_GECKO_API_KEY").ok(), - &Network::Gnosis, + &Chain::Gnosis, Arc::new(mock), ) .unwrap(); diff --git a/crates/shared/src/sources.rs b/crates/shared/src/sources.rs index 6e17ba0f71..eed9bbc5cc 100644 --- a/crates/shared/src/sources.rs +++ b/crates/shared/src/sources.rs @@ -10,8 +10,8 @@ use { self::uniswap_v2::pool_fetching::{Pool, PoolFetching}, crate::recent_block_cache::Block, anyhow::Result, + chain::Chain, model::TokenPair, - network::Network, std::{collections::HashSet, sync::Arc}, }; @@ -30,9 +30,9 @@ pub enum BaselineSource { TestnetUniswapV2, } -pub fn defaults_for_network(network: &Network) -> Vec { - match network { - Network::Mainnet => vec![ +pub fn defaults_for_network(chain: &Chain) -> Vec { + match chain { + Chain::Mainnet => vec![ BaselineSource::UniswapV2, BaselineSource::SushiSwap, BaselineSource::Swapr, @@ -40,18 +40,18 @@ pub fn defaults_for_network(network: &Network) -> Vec { BaselineSource::ZeroEx, BaselineSource::UniswapV3, ], - Network::Goerli => vec![ + Chain::Goerli => vec![ BaselineSource::UniswapV2, BaselineSource::SushiSwap, BaselineSource::BalancerV2, ], - Network::Gnosis => vec![ + Chain::Gnosis => vec![ BaselineSource::Honeyswap, BaselineSource::SushiSwap, BaselineSource::Baoswap, BaselineSource::Swapr, ], - Network::ArbitrumOne => vec![ + Chain::ArbitrumOne => vec![ BaselineSource::UniswapV2, BaselineSource::SushiSwap, BaselineSource::Swapr, @@ -59,7 +59,7 @@ pub fn defaults_for_network(network: &Network) -> Vec { BaselineSource::ZeroEx, BaselineSource::UniswapV3, ], - Network::Base => vec![ + Chain::Base => vec![ BaselineSource::UniswapV2, BaselineSource::SushiSwap, BaselineSource::Swapr, @@ -67,7 +67,7 @@ pub fn defaults_for_network(network: &Network) -> Vec { BaselineSource::ZeroEx, BaselineSource::UniswapV3, ], - Network::Sepolia => vec![BaselineSource::TestnetUniswapV2], + Chain::Sepolia => vec![BaselineSource::TestnetUniswapV2], } } diff --git a/crates/solvers/Cargo.toml b/crates/solvers/Cargo.toml index 2fa7f5bd97..54eb233926 100644 --- a/crates/solvers/Cargo.toml +++ b/crates/solvers/Cargo.toml @@ -15,6 +15,7 @@ path = "src/main.rs" [dependencies] axum = { workspace = true } bigdecimal = { version = "0.3", features = ["serde"] } +chain = { path = "../chain" } chrono = { workspace = true, features = ["serde"], default-features = false } clap = { workspace = true, features = ["derive", "env"] } derive_more = { workspace = true } @@ -25,7 +26,6 @@ hex = { workspace = true } hyper = { workspace = true } itertools = { workspace = true } mimalloc = { workspace = true } -network = { path = "../network" } num = { workspace = true } prometheus = { workspace = true } prometheus-metric-storage = { workspace = true } diff --git a/crates/solvers/src/infra/config/baseline.rs b/crates/solvers/src/infra/config/baseline.rs index a5a22f45c7..354d383bff 100644 --- a/crates/solvers/src/infra/config/baseline.rs +++ b/crates/solvers/src/infra/config/baseline.rs @@ -4,8 +4,8 @@ use { infra::{config::unwrap_or_log, contracts}, util::serialize, }, + chain::Chain, ethereum_types::H160, - network::Network, serde::Deserialize, serde_with::serde_as, shared::price_estimation::gas::SETTLEMENT_OVERHEAD, @@ -19,7 +19,7 @@ use { struct Config { /// Optional chain ID. This is used to automatically determine the address /// of the WETH contract. - chain_id: Option, + chain_id: Option, /// Optional WETH contract address. This can be used to specify a manual /// value **instead** of using the canonical WETH contract for the diff --git a/crates/solvers/src/infra/contracts.rs b/crates/solvers/src/infra/contracts.rs index c13a885b62..d0707d7bf4 100644 --- a/crates/solvers/src/infra/contracts.rs +++ b/crates/solvers/src/infra/contracts.rs @@ -1,4 +1,4 @@ -use {crate::domain::eth, network::Network}; +use {crate::domain::eth, chain::Chain}; #[derive(Clone, Debug)] pub struct Contracts { @@ -9,12 +9,12 @@ pub struct Contracts { } impl Contracts { - pub fn for_chain(chain: Network) -> Self { + pub fn for_chain(chain: Chain) -> Self { let a = |contract: &contracts::ethcontract::Contract| { eth::ContractAddress( contract .networks - .get(&chain.chain_id().to_string()) + .get(&chain.id().to_string()) .expect("contract address for all supported chains") .address, )