Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 2 additions & 10 deletions crates/driver/src/boundary/liquidity/balancer/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use {
BalancerV2WeightedPoolFactory,
BalancerV2WeightedPoolFactoryV3,
},
ethrpc::{
alloy::conversions::IntoLegacy,
block_stream::{BlockRetrieving, CurrentBlockWatcher},
},
ethrpc::block_stream::{BlockRetrieving, CurrentBlockWatcher},
shared::{
http_solver::model::TokenAmount,
sources::balancer_v2::{
Expand Down Expand Up @@ -181,12 +178,7 @@ async fn init_liquidity(
boundary::liquidity::http_client(),
web3.clone(),
&contracts,
config
.pool_deny_list
.iter()
.copied()
.map(IntoLegacy::into_legacy)
.collect(),
config.pool_deny_list.to_vec(),
)
.await
.context("failed to create balancer pool fetcher")?,
Expand Down
2 changes: 1 addition & 1 deletion crates/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
doctest = false

[dependencies]
alloy = { workspace = true, features = ["sol-types", "signer-local"] }
alloy = { workspace = true, features = ["sol-types", "signer-local", "rand"] }
anyhow = { workspace = true }
app-data = { workspace = true }
bytes-hex = { workspace = true }
Expand Down
14 changes: 1 addition & 13 deletions crates/shared/src/arguments.rs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also unused, on the infra repo too

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
use {
crate::{
gas_price_estimation::GasEstimatorType,
sources::{
BaselineSource,
balancer_v2::BalancerFactoryKind,
uniswap_v2::UniV2BaselineSourceParameters,
},
sources::{BaselineSource, uniswap_v2::UniV2BaselineSourceParameters},
tenderly_api,
},
alloy::primitives::Address,
Expand Down Expand Up @@ -218,12 +214,6 @@ pub struct Arguments {
#[clap(long, env, action = clap::ArgAction::Set, default_value = "false")]
pub use_internal_buffers: bool,

/// The Balancer V2 factories to consider for indexing liquidity. Allows
/// specific pool kinds to be disabled via configuration. Will use all
/// supported Balancer V2 factory kinds if not specified.
#[clap(long, env, value_enum, ignore_case = true, use_value_delimiter = true)]
pub balancer_factories: Option<Vec<BalancerFactoryKind>>,

/// Value of the authorization header for the solver competition post api.
#[clap(long, env)]
pub solver_competition_auth: Option<String>,
Expand Down Expand Up @@ -396,7 +386,6 @@ impl Display for Arguments {
pool_cache_maximum_retries,
pool_cache_delay_between_retries,
use_internal_buffers,
balancer_factories,
solver_competition_auth,
network_block_interval,
settlement_contract_address,
Expand Down Expand Up @@ -439,7 +428,6 @@ impl Display for Arguments {
"pool_cache_delay_between_retries: {pool_cache_delay_between_retries:?}"
)?;
writeln!(f, "use_internal_buffers: {use_internal_buffers}")?;
writeln!(f, "balancer_factories: {balancer_factories:?}")?;
display_secret_option(
f,
"solver_competition_auth",
Expand Down
11 changes: 11 additions & 0 deletions crates/shared/src/recent_block_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use {
crate::request_sharing::BoxRequestSharing,
alloy::eips::BlockId,
anyhow::{Context, Result},
cached::{Cached, SizedCache},
ethcontract::BlockNumber,
Expand Down Expand Up @@ -84,6 +85,16 @@ impl From<Block> for BlockNumber {
}
}

impl From<Block> for BlockId {
fn from(value: Block) -> Self {
match value {
Block::Recent => BlockId::latest(),
Block::Number(n) => BlockId::number(n),
Block::Finalized => BlockId::finalized(),
}
}
}

/// Recent block cache for arbitrary key-value pairs.
///
/// Caches on-chain data for a specific number of blocks and automatically
Expand Down
18 changes: 8 additions & 10 deletions crates/shared/src/sources/balancer_v2/graph_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
use {
super::swap::fixed_point::Bfp,
crate::{event_handling::MAX_REORG_BLOCK_COUNT, subgraph::SubgraphClient},
alloy::primitives::Address,
alloy::primitives::{Address, B256},
anyhow::Result,
ethcontract::H256,
reqwest::{Client, Url},
serde::Deserialize,
serde_json::json,
Expand Down Expand Up @@ -50,7 +49,7 @@ impl BalancerSubgraphClient {
let block_number = self.get_safe_block().await?;

let mut pools = Vec::new();
let mut last_id = H256::default();
let mut last_id = B256::default();

// We do paging by last ID instead of using `skip`. This is the
// suggested approach to paging best performance:
Expand Down Expand Up @@ -148,7 +147,7 @@ impl RegisteredPools {
#[serde(rename_all = "camelCase")]
pub struct PoolData {
pub pool_type: PoolType,
pub id: H256,
pub id: B256,
pub address: Address,
pub factory: Address,
pub swap_enabled: bool,
Expand Down Expand Up @@ -246,7 +245,6 @@ mod tests {
super::*,
crate::sources::balancer_v2::swap::fixed_point::Bfp,
alloy::primitives::U256,
ethcontract::H256,
maplit::hashmap,
};

Expand Down Expand Up @@ -336,7 +334,7 @@ mod tests {
pools: vec![
PoolData {
pool_type: PoolType::Weighted,
id: H256([0x11; 32]),
id: B256::repeat_byte(0x11),
address: Address::repeat_byte(0x22),
factory: Address::repeat_byte(0x55),
swap_enabled: true,
Expand All @@ -359,7 +357,7 @@ mod tests {
},
PoolData {
pool_type: PoolType::Stable,
id: H256([0x11; 32]),
id: B256::repeat_byte(0x11),
address: Address::repeat_byte(0x22),
factory: Address::repeat_byte(0x55),
swap_enabled: true,
Expand All @@ -378,7 +376,7 @@ mod tests {
},
PoolData {
pool_type: PoolType::LiquidityBootstrapping,
id: H256([0x11; 32]),
id: B256::repeat_byte(0x11),
address: Address::repeat_byte(0x22),
factory: Address::repeat_byte(0x55),
swap_enabled: true,
Expand All @@ -401,7 +399,7 @@ mod tests {
},
PoolData {
pool_type: PoolType::ComposableStable,
id: H256([0x11; 32]),
id: B256::repeat_byte(0x11),
address: Address::repeat_byte(0x22),
factory: Address::repeat_byte(0x55),
swap_enabled: true,
Expand Down Expand Up @@ -447,7 +445,7 @@ mod tests {
#[test]
fn groups_pools_by_factory() {
let pool = |factory: Address, id: u8| PoolData {
id: H256([id; 32]),
id: B256::repeat_byte(id),
factory,
pool_type: PoolType::Weighted,
address: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/shared/src/sources/balancer_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ pub mod pools;
pub mod swap;

pub use self::{
pool_fetching::{BalancerFactoryKind, BalancerPoolFetcher, BalancerPoolFetching},
pool_fetching::{BalancerPoolFetcher, BalancerPoolFetching},
pools::{Pool, PoolKind},
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use {
super::internal::InternalPoolFetching,
crate::{recent_block_cache::Block, sources::balancer_v2::pools::Pool},
alloy::primitives::B256,
anyhow::Result,
ethcontract::H256,
futures::future,
model::TokenPair,
std::collections::HashSet,
Expand All @@ -25,7 +25,7 @@ impl Aggregate {

#[async_trait::async_trait]
impl InternalPoolFetching for Aggregate {
async fn pool_ids_for_token_pairs(&self, token_pairs: HashSet<TokenPair>) -> HashSet<H256> {
async fn pool_ids_for_token_pairs(&self, token_pairs: HashSet<TokenPair>) -> HashSet<B256> {
future::join_all(
self.fetchers
.iter()
Expand All @@ -37,7 +37,7 @@ impl InternalPoolFetching for Aggregate {
.collect()
}

async fn pools_by_id(&self, pool_ids: HashSet<H256>, block: Block) -> Result<Vec<Pool>> {
async fn pools_by_id(&self, pool_ids: HashSet<B256>, block: Block) -> Result<Vec<Pool>> {
Ok(future::try_join_all(
self.fetchers
.iter()
Expand Down
16 changes: 8 additions & 8 deletions crates/shared/src/sources/balancer_v2/pool_fetching/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use {
recent_block_cache::{Block, CacheConfig, CacheFetching, CacheKey, RecentBlockCache},
sources::balancer_v2::pools::Pool,
},
alloy::primitives::B256,
anyhow::Result,
ethcontract::H256,
ethrpc::block_stream::CurrentBlockWatcher,
std::{collections::HashSet, sync::Arc},
};

/// Internal type alias used for inner recent block cache.
type PoolCache<Inner> = RecentBlockCache<H256, Pool, CacheFetcher<Inner>>;
type PoolCache<Inner> = RecentBlockCache<B256, Pool, CacheFetcher<Inner>>;

/// A cached pool fetcher that wraps an inner `InternalPoolFetching`
/// implementation.
Expand Down Expand Up @@ -52,18 +52,18 @@ where
async fn pool_ids_for_token_pairs(
&self,
token_pairs: HashSet<model::TokenPair>,
) -> HashSet<H256> {
) -> HashSet<B256> {
self.inner.pool_ids_for_token_pairs(token_pairs).await
}

async fn pools_by_id(&self, pool_ids: HashSet<H256>, block: Block) -> Result<Vec<Pool>> {
async fn pools_by_id(&self, pool_ids: HashSet<B256>, block: Block) -> Result<Vec<Pool>> {
self.cache.fetch(pool_ids, block).await
}
}

impl CacheKey<Pool> for H256 {
impl CacheKey<Pool> for B256 {
fn first_ord() -> Self {
H256::zero()
B256::ZERO
}

fn for_value(pool: &Pool) -> Self {
Expand All @@ -79,11 +79,11 @@ impl CacheKey<Pool> for H256 {
struct CacheFetcher<Inner>(Arc<Inner>);

#[async_trait::async_trait]
impl<Inner> CacheFetching<H256, Pool> for CacheFetcher<Inner>
impl<Inner> CacheFetching<B256, Pool> for CacheFetcher<Inner>
where
Inner: InternalPoolFetching,
{
async fn fetch_values(&self, pool_ids: HashSet<H256>, at_block: Block) -> Result<Vec<Pool>> {
async fn fetch_values(&self, pool_ids: HashSet<B256>, at_block: Block) -> Result<Vec<Pool>> {
self.0.pools_by_id(pool_ids, at_block).await
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use {
crate::{recent_block_cache::Block, sources::balancer_v2::pools::Pool},
alloy::primitives::B256,
anyhow::Result,
ethcontract::H256,
model::TokenPair,
std::collections::HashSet,
};
Expand All @@ -16,8 +16,8 @@ use {
#[async_trait::async_trait]
pub trait InternalPoolFetching: Send + Sync + 'static {
/// Retrives all pool IDs that trade the specified pairs.
async fn pool_ids_for_token_pairs(&self, token_pairs: HashSet<TokenPair>) -> HashSet<H256>;
async fn pool_ids_for_token_pairs(&self, token_pairs: HashSet<TokenPair>) -> HashSet<B256>;

/// Fetches current pool states for the specified IDs and block.
async fn pools_by_id(&self, pool_ids: HashSet<H256>, block: Block) -> Result<Vec<Pool>>;
async fn pools_by_id(&self, pool_ids: HashSet<B256>, block: Block) -> Result<Vec<Pool>>;
}
Loading
Loading