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

Remove chain::Id completely #3173

Merged
merged 9 commits into from
Dec 23, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use chain::Chain
  • Loading branch information
sunce86 committed Dec 19, 2024
commit f627e9e1e0b29be930e51d10f16c9345d210ece6
5 changes: 3 additions & 2 deletions crates/driver/src/infra/blockchain/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
crate::{boundary, domain::eth, infra::blockchain::Ethereum},
chain::Chain,
ethcontract::dyns::DynWeb3,
ethrpc::block_stream::CurrentBlockWatcher,
thiserror::Error,
@@ -28,7 +29,7 @@ pub struct Addresses {
impl Contracts {
pub(super) async fn new(
web3: &DynWeb3,
chain: chain::Chain,
chain: Chain,
addresses: Addresses,
block_stream: CurrentBlockWatcher,
archive_node_url: Option<&Url>,
@@ -130,7 +131,7 @@ pub struct CowAmmConfig {
/// there is no known deployment for the contract on that network.
pub fn deployment_address(
contract: &ethcontract::Contract,
chain: chain::Chain,
chain: Chain,
) -> Option<eth::ContractAddress> {
Some(
contract
13 changes: 7 additions & 6 deletions crates/driver/src/infra/blockchain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
self::contracts::ContractAt,
crate::{boundary, domain::eth},
chain::Chain,
ethcontract::{dyns::DynWeb3, errors::ExecutionError},
ethrpc::block_stream::CurrentBlockWatcher,
std::{fmt, sync::Arc},
@@ -18,7 +19,7 @@ pub use self::{contracts::Contracts, gas::GasPriceEstimator};
/// An Ethereum RPC connection.
pub struct Rpc {
web3: DynWeb3,
chain: chain::Chain,
chain: Chain,
url: Url,
}

@@ -27,8 +28,8 @@ impl Rpc {
/// at the specifed URL.
pub async fn new(url: &url::Url) -> Result<Self, Error> {
sunce86 marked this conversation as resolved.
Show resolved Hide resolved
let web3 = boundary::buffered_web3_client(url);
let chain = chain::Chain::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,
@@ -38,7 +39,7 @@ impl Rpc {
}

/// Returns the chain for the RPC connection.
pub fn chain(&self) -> chain::Chain {
pub fn chain(&self) -> Chain {
self.chain
}

@@ -56,7 +57,7 @@ pub struct Ethereum {
}

struct Inner {
chain: chain::Chain,
chain: Chain,
contracts: Contracts,
gas: Arc<GasPriceEstimator>,
current_block: CurrentBlockWatcher,
@@ -103,7 +104,7 @@ impl Ethereum {
}
}

pub fn chain(&self) -> chain::Chain {
pub fn chain(&self) -> Chain {
self.inner.chain
}

5 changes: 3 additions & 2 deletions crates/driver/src/infra/config/file/load.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ use {
solver::{self, SolutionMerging},
},
},
chain::Chain,
futures::future::join_all,
number::conversions::big_decimal_to_big_rational,
std::path::Path,
@@ -23,7 +24,7 @@ use {
/// # Panics
///
/// This method panics if the config is invalid or on I/O errors.
pub async fn load(chain: chain::Chain, path: &Path) -> infra::Config {
pub async fn load(chain: Chain, path: &Path) -> infra::Config {
let data = fs::read_to_string(path)
.await
.unwrap_or_else(|e| panic!("I/O error while reading {path:?}: {e:?}"));
@@ -42,7 +43,7 @@ pub async fn load(chain: chain::Chain, path: &Path) -> infra::Config {
assert_eq!(
config
.chain_id
.and_then(|id| chain::Chain::try_from(id).ok())
.and_then(|id| Chain::try_from(id).ok())
sunce86 marked this conversation as resolved.
Show resolved Hide resolved
.unwrap_or(chain),
chain,
"The configured chain ID does not match the connected Ethereum node"
19 changes: 10 additions & 9 deletions crates/driver/src/infra/liquidity/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
crate::{domain::eth, infra::blockchain::contracts::deployment_address},
chain::Chain,
derive_more::Debug,
hex_literal::hex,
reqwest::Url,
@@ -49,7 +50,7 @@ pub struct UniswapV2 {
impl UniswapV2 {
/// Returns the liquidity configuration for Uniswap V2.
#[allow(clippy::self_named_constructors)]
pub fn uniswap_v2(chain: chain::Chain) -> Option<Self> {
pub fn uniswap_v2(chain: Chain) -> Option<Self> {
Some(Self {
router: deployment_address(contracts::UniswapV2Router02::raw_contract(), chain)?,
pool_code: hex!("96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f")
@@ -59,7 +60,7 @@ impl UniswapV2 {
}

/// Returns the liquidity configuration for SushiSwap.
pub fn sushi_swap(chain: chain::Chain) -> Option<Self> {
pub fn sushi_swap(chain: Chain) -> Option<Self> {
Some(Self {
router: deployment_address(contracts::SushiSwapRouter::raw_contract(), chain)?,
pool_code: hex!("e18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303")
@@ -69,7 +70,7 @@ impl UniswapV2 {
}

/// Returns the liquidity configuration for Honeyswap.
pub fn honeyswap(chain: chain::Chain) -> Option<Self> {
pub fn honeyswap(chain: Chain) -> Option<Self> {
Some(Self {
router: deployment_address(contracts::HoneyswapRouter::raw_contract(), chain)?,
pool_code: hex!("3f88503e8580ab941773b59034fb4b2a63e86dbc031b3633a925533ad3ed2b93")
@@ -79,7 +80,7 @@ impl UniswapV2 {
}

/// Returns the liquidity configuration for Baoswap.
pub fn baoswap(chain: chain::Chain) -> Option<Self> {
pub fn baoswap(chain: Chain) -> Option<Self> {
Some(Self {
router: deployment_address(contracts::BaoswapRouter::raw_contract(), chain)?,
pool_code: hex!("0bae3ead48c325ce433426d2e8e6b07dac10835baec21e163760682ea3d3520d")
@@ -89,7 +90,7 @@ impl UniswapV2 {
}

/// Returns the liquidity configuration for PancakeSwap.
pub fn pancake_swap(chain: chain::Chain) -> Option<Self> {
pub fn pancake_swap(chain: Chain) -> Option<Self> {
Some(Self {
router: deployment_address(contracts::PancakeRouter::raw_contract(), chain)?,
pool_code: hex!("57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d")
@@ -100,7 +101,7 @@ impl UniswapV2 {

/// Returns the liquidity configuration for liquidity sources only used on
/// test networks.
pub fn testnet_uniswapv2(chain: chain::Chain) -> Option<Self> {
pub fn testnet_uniswapv2(chain: Chain) -> Option<Self> {
Some(Self {
router: deployment_address(contracts::TestnetUniswapV2Router02::raw_contract(), chain)?,
pool_code: hex!("0efd7612822d579e24a8851501d8c2ad854264a1050e3dfcee8afcca08f80a86")
@@ -126,7 +127,7 @@ pub struct Swapr {
impl Swapr {
/// Returns the liquidity configuration for Swapr.
#[allow(clippy::self_named_constructors)]
pub fn swapr(chain: chain::Chain) -> Option<Self> {
pub fn swapr(chain: Chain) -> Option<Self> {
Some(Self {
router: deployment_address(contracts::SwaprRouter::raw_contract(), chain)?,
pool_code: hex!("d306a548755b9295ee49cc729e13ca4a45e00199bbd890fa146da43a50571776")
@@ -152,7 +153,7 @@ pub struct UniswapV3 {
impl UniswapV3 {
/// Returns the liquidity configuration for Uniswap V3.
#[allow(clippy::self_named_constructors)]
pub fn uniswap_v3(graph_url: &Url, chain: chain::Chain) -> Option<Self> {
pub fn uniswap_v3(graph_url: &Url, chain: Chain) -> Option<Self> {
Some(Self {
router: deployment_address(contracts::UniswapV3SwapRouter::raw_contract(), chain)?,
max_pools_to_initialize: 100,
@@ -196,7 +197,7 @@ pub struct BalancerV2 {
impl BalancerV2 {
/// Returns the liquidity configuration for Balancer V2.
#[allow(clippy::self_named_constructors)]
pub fn balancer_v2(graph_url: &Url, chain: chain::Chain) -> Option<Self> {
pub fn balancer_v2(graph_url: &Url, chain: Chain) -> Option<Self> {
let factory_addresses =
|contracts: &[&ethcontract::Contract]| -> Vec<eth::ContractAddress> {
contracts
9 changes: 3 additions & 6 deletions crates/driver/src/infra/simulator/enso/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
crate::domain::eth,
chain::Chain,
ethrpc::block_stream::CurrentBlockWatcher,
reqwest::ClientBuilder,
std::time::Duration,
@@ -13,7 +14,7 @@ const GAS_LIMIT: u64 = 30_000_000;
#[derive(Debug, Clone)]
pub(super) struct Enso {
url: reqwest::Url,
chain: chain::Chain,
chain: Chain,
current_block: CurrentBlockWatcher,
network_block_interval: Option<Duration>,
}
@@ -27,11 +28,7 @@ pub struct Config {
}

impl Enso {
pub(super) fn new(
config: Config,
chain: chain::Chain,
current_block: CurrentBlockWatcher,
) -> Self {
pub(super) fn new(config: Config, chain: Chain, current_block: CurrentBlockWatcher) -> Self {
Self {
url: reqwest::Url::parse(&format!("{}api/v1/simulate", config.url)).unwrap(),
chain,
Loading