diff --git a/crates/driver/src/domain/competition/auction.rs b/crates/driver/src/domain/competition/auction.rs index 3d8f249890..ffd7586e15 100644 --- a/crates/driver/src/domain/competition/auction.rs +++ b/crates/driver/src/domain/competition/auction.rs @@ -4,13 +4,14 @@ use { domain::{ competition::{self, solution}, eth, + liquidity, }, infra::{blockchain, observe, Ethereum}, util, }, futures::future::join_all, itertools::Itertools, - std::collections::HashMap, + std::collections::{HashMap, HashSet}, thiserror::Error, }; @@ -227,6 +228,20 @@ impl Auction { &self.tokens } + /// Returns a collection of liquidity token pairs that are relevant to this + /// auction. + pub fn liquidity_pairs(&self) -> HashSet { + self.orders + .iter() + .filter_map(|order| match order.kind { + order::Kind::Market | order::Kind::Limit { .. } => { + liquidity::TokenPair::new(order.sell.token, order.buy.token).ok() + } + order::Kind::Liquidity => None, + }) + .collect() + } + pub fn gas_price(&self) -> eth::GasPrice { self.gas_price } diff --git a/crates/driver/src/domain/competition/mod.rs b/crates/driver/src/domain/competition/mod.rs index 5646cceac1..048793bb55 100644 --- a/crates/driver/src/domain/competition/mod.rs +++ b/crates/driver/src/domain/competition/mod.rs @@ -2,7 +2,7 @@ use { self::solution::settlement, super::{eth, Mempools}, crate::{ - domain::{competition::solution::Settlement, liquidity}, + domain::competition::solution::Settlement, infra::{ self, blockchain::Ethereum, @@ -47,21 +47,10 @@ pub struct Competition { impl Competition { /// Solve an auction as part of this competition. pub async fn solve(&self, auction: &Auction) -> Result { - let liquidity = self - .liquidity - .fetch( - &auction - .orders() - .iter() - .filter_map(|order| match order.kind { - order::Kind::Market | order::Kind::Limit { .. } => { - liquidity::TokenPair::new(order.sell.token, order.buy.token).ok() - } - order::Kind::Liquidity => None, - }) - .collect(), - ) - .await; + let liquidity = match self.solver.liquidity() { + solver::Liquidity::Fetch => self.liquidity.fetch(&auction.liquidity_pairs()).await, + solver::Liquidity::Skip => Default::default(), + }; // Fetch the solutions from the solver. let solutions = self diff --git a/crates/driver/src/domain/quote.rs b/crates/driver/src/domain/quote.rs index dddc868819..25c099eb66 100644 --- a/crates/driver/src/domain/quote.rs +++ b/crates/driver/src/domain/quote.rs @@ -74,7 +74,10 @@ impl Order { liquidity: &infra::liquidity::Fetcher, tokens: &infra::tokens::Fetcher, ) -> Result { - let liquidity = liquidity.fetch(&self.liquidity_pairs()).await; + let liquidity = match solver.liquidity() { + solver::Liquidity::Fetch => liquidity.fetch(&self.liquidity_pairs()).await, + solver::Liquidity::Skip => Default::default(), + }; let timeout = self.deadline.timeout()?; let solutions = solver .solve(&self.fake_auction(eth, tokens).await?, &liquidity, timeout) diff --git a/crates/driver/src/infra/config/file/load.rs b/crates/driver/src/infra/config/file/load.rs index 4c4d0e780e..5de57c5dd0 100644 --- a/crates/driver/src/infra/config/file/load.rs +++ b/crates/driver/src/infra/config/file/load.rs @@ -60,6 +60,11 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config { relative: config.relative_slippage, absolute: config.absolute_slippage.map(Into::into), }, + liquidity: if config.skip_liquidity { + solver::Liquidity::Skip + } else { + solver::Liquidity::Fetch + }, account, } })) diff --git a/crates/driver/src/infra/config/file/mod.rs b/crates/driver/src/infra/config/file/mod.rs index 9d31b9b080..3af51fb25a 100644 --- a/crates/driver/src/infra/config/file/mod.rs +++ b/crates/driver/src/infra/config/file/mod.rs @@ -164,6 +164,10 @@ struct SolverConfig { #[serde_as(as = "Option")] absolute_slippage: Option, + /// Whether or not to skip fetching liquidity for this solver. + #[serde(default)] + skip_liquidity: bool, + /// The account which should be used to sign settlements for this solver. account: Account, } diff --git a/crates/driver/src/infra/solver/mod.rs b/crates/driver/src/infra/solver/mod.rs index abf6f2f857..5f9e83f298 100644 --- a/crates/driver/src/infra/solver/mod.rs +++ b/crates/driver/src/infra/solver/mod.rs @@ -48,6 +48,16 @@ pub struct Slippage { pub absolute: Option, } +#[derive(Clone, Copy, Debug)] +pub enum Liquidity { + /// Liquidity should be fetched and included in the auction sent to this + /// solver. + Fetch, + /// The solver does not need liquidity, so fetching can be skipped for this + /// solver. + Skip, +} + /// Solvers are controlled by the driver. Their job is to search for solutions /// to auctions. They do this in various ways, often by analyzing different AMMs /// on the Ethereum blockchain. @@ -65,6 +75,8 @@ pub struct Config { pub name: Name, /// The acceptable slippage for this solver. pub slippage: Slippage, + /// Whether or not liquidity is used by this solver. + pub liquidity: Liquidity, /// The private key of this solver, used for settlement submission. pub account: ethcontract::Account, } @@ -101,6 +113,11 @@ impl Solver { &self.config.slippage } + /// The liquidity configuration of this solver + pub fn liquidity(&self) -> Liquidity { + self.config.liquidity + } + /// The blockchain address of this solver. pub fn address(&self) -> eth::Address { self.config.account.address().into()