diff --git a/Cargo.lock b/Cargo.lock index 8713e4b0ff..0dc7c0fd8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1655,6 +1655,7 @@ dependencies = [ "hyper", "indexmap 2.0.0", "itertools 0.11.0", + "lazy_static", "maplit", "mockall", "model", diff --git a/crates/autopilot/src/run.rs b/crates/autopilot/src/run.rs index 8c294d24b2..84729aa1d9 100644 --- a/crates/autopilot/src/run.rs +++ b/crates/autopilot/src/run.rs @@ -307,6 +307,7 @@ pub async fn run(args: Arguments) { .unwrap_or_else(|| BalancerFactoryKind::for_chain(chain_id)); let contracts = BalancerContracts::new(&web3, factories).await.unwrap(); match BalancerPoolFetcher::new( + &args.shared.graph_api_base_url, chain_id, block_retriever.clone(), token_info_fetcher.clone(), @@ -335,6 +336,7 @@ pub async fn run(args: Arguments) { }; let uniswap_v3_pool_fetcher = if baseline_sources.contains(&BaselineSource::UniswapV3) { match UniswapV3PoolFetcher::new( + &args.shared.graph_api_base_url, chain_id, web3.clone(), http_factory.create(), diff --git a/crates/driver/Cargo.toml b/crates/driver/Cargo.toml index ac1a895a69..9c50be3b9b 100644 --- a/crates/driver/Cargo.toml +++ b/crates/driver/Cargo.toml @@ -26,6 +26,7 @@ futures = "0.3" hex = "0.4" hex-literal = "0.4" hyper = "0.14" +lazy_static = { workspace = true } indexmap = { version = "2", features = ["serde"] } itertools = "0.11" num = "0.4" diff --git a/crates/driver/example.toml b/crates/driver/example.toml index 8ddda559ee..4db4cc011b 100644 --- a/crates/driver/example.toml +++ b/crates/driver/example.toml @@ -34,6 +34,7 @@ base-tokens = [ "0xDEf1CA1fb7FBcDC777520aa7f396b4E015F497aB", "0x6B175474E89094C44Da98b954EedeAC495271d0F", ] +graph-api-base-url = "https://api.thegraph.com/subgraphs/name/" # [[liquidity.uniswap-v2]] # Uniswap V2 configuration # preset = "uniswap-v2" # or "sushi-swap", "honeyswap", "baoswap", "pancake-swap", etc. @@ -74,4 +75,3 @@ base-tokens = [ # [[liquidity.uniswap-v3]] # Custom Uniswap V3 configuration # router = "0xE592427A0AEce92De3Edee1F18E0157C05861564" # max_pools_to_initialize = 100 # how many of the deepest pools to initialise on startup - diff --git a/crates/driver/src/boundary/liquidity/balancer/v2/mod.rs b/crates/driver/src/boundary/liquidity/balancer/v2/mod.rs index a09315c254..561f8ea336 100644 --- a/crates/driver/src/boundary/liquidity/balancer/v2/mod.rs +++ b/crates/driver/src/boundary/liquidity/balancer/v2/mod.rs @@ -178,6 +178,7 @@ async fn init_liquidity( let balancer_pool_fetcher = Arc::new( BalancerPoolFetcher::new( + &config.graph_api_base_url, eth.network().chain.into(), block_retriever.clone(), token_info_fetcher.clone(), diff --git a/crates/driver/src/boundary/liquidity/uniswap/v3.rs b/crates/driver/src/boundary/liquidity/uniswap/v3.rs index a6a251ff82..60a2b2fc5f 100644 --- a/crates/driver/src/boundary/liquidity/uniswap/v3.rs +++ b/crates/driver/src/boundary/liquidity/uniswap/v3.rs @@ -135,6 +135,7 @@ async fn init_liquidity( let pool_fetcher = Arc::new( UniswapV3PoolFetcher::new( + &config.graph_api_base_url, eth.network().chain.into(), web3.clone(), boundary::liquidity::http_client(), diff --git a/crates/driver/src/infra/config/file/load.rs b/crates/driver/src/infra/config/file/load.rs index 888ac25f76..48a5823dbe 100644 --- a/crates/driver/src/infra/config/file/load.rs +++ b/crates/driver/src/infra/config/file/load.rs @@ -4,10 +4,18 @@ use { infra::{self, blockchain, config::file, liquidity, mempool, simulator, solver}, }, futures::future::join_all, + lazy_static::lazy_static, + reqwest::Url, std::{path::Path, time::Duration}, tokio::fs, }; +lazy_static! { + pub static ref DEFAULT_GRAPH_API_BASE_URL: Url = + Url::parse("https://api.thegraph.com/subgraphs/name/") + .expect("invalid default Graph API base URL"); +} + /// Load the driver configuration from a TOML file for the specifed Ethereum /// network. /// @@ -35,7 +43,10 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config { network.chain, "The configured chain ID does not match connected Ethereum node" ); - + let graph_api_base_url = config + .liquidity + .graph_api_base_url + .unwrap_or(DEFAULT_GRAPH_API_BASE_URL.clone()); infra::Config { solvers: join_all(config.solvers.into_iter().map(|config| async move { let account = match config.account { @@ -164,7 +175,10 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config { max_pools_to_initialize, ..match preset { file::UniswapV3Preset::UniswapV3 => { - liquidity::config::UniswapV3::uniswap_v3(&network.id) + liquidity::config::UniswapV3::uniswap_v3( + &graph_api_base_url, + &network.id, + ) } } .expect("no Uniswap V3 preset for current network") @@ -175,6 +189,7 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config { } => liquidity::config::UniswapV3 { router: router.into(), max_pools_to_initialize, + graph_api_base_url: graph_api_base_url.clone(), }, }) .collect(), @@ -191,7 +206,10 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config { pool_deny_list: pool_deny_list.clone(), ..match preset { file::BalancerV2Preset::BalancerV2 => { - liquidity::config::BalancerV2::balancer_v2(&network.id) + liquidity::config::BalancerV2::balancer_v2( + &graph_api_base_url, + &network.id, + ) } } .expect("no Balancer V2 preset for current network") @@ -224,6 +242,7 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config { .map(eth::ContractAddress::from) .collect(), pool_deny_list: pool_deny_list.clone(), + graph_api_base_url: graph_api_base_url.clone(), }, }) .collect(), diff --git a/crates/driver/src/infra/config/file/mod.rs b/crates/driver/src/infra/config/file/mod.rs index 2508e38743..d39b817d5d 100644 --- a/crates/driver/src/infra/config/file/mod.rs +++ b/crates/driver/src/infra/config/file/mod.rs @@ -293,6 +293,9 @@ struct LiquidityConfig { /// Liquidity provided by a Balancer V2 compatible contract. #[serde(default)] balancer_v2: Vec, + + /// The base URL used to connect to subgraph clients. + graph_api_base_url: Option, } #[derive(Clone, Debug, Deserialize)] diff --git a/crates/driver/src/infra/liquidity/config.rs b/crates/driver/src/infra/liquidity/config.rs index 92f8f2950e..a149c00148 100644 --- a/crates/driver/src/infra/liquidity/config.rs +++ b/crates/driver/src/infra/liquidity/config.rs @@ -1,6 +1,7 @@ use { crate::{domain::eth, infra::blockchain::contracts::deployment_address}, hex_literal::hex, + reqwest::Url, std::{collections::HashSet, time::Duration}, }; @@ -121,22 +122,26 @@ impl Swapr { } /// Uniswap V3 liquidity fetching options. -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub struct UniswapV3 { /// The address of the Uniswap V3 compatible router contract. pub router: eth::ContractAddress, /// How many pools should be initialized during start up. pub max_pools_to_initialize: usize, + + /// The base URL used to connect to subgraph clients. + pub graph_api_base_url: Url, } impl UniswapV3 { /// Returns the liquidity configuration for Uniswap V3. #[allow(clippy::self_named_constructors)] - pub fn uniswap_v3(network: ð::NetworkId) -> Option { + pub fn uniswap_v3(graph_api_base_url: &Url, network: ð::NetworkId) -> Option { Some(Self { router: deployment_address(contracts::UniswapV3SwapRouter::raw_contract(), network)?, max_pools_to_initialize: 100, + graph_api_base_url: graph_api_base_url.clone(), }) } } @@ -168,12 +173,15 @@ pub struct BalancerV2 { /// pools to get "bricked". This configuration allows those pools to be /// ignored. pub pool_deny_list: Vec, + + /// The base URL used to connect to subgraph clients. + pub graph_api_base_url: Url, } impl BalancerV2 { /// Returns the liquidity configuration for Balancer V2. #[allow(clippy::self_named_constructors)] - pub fn balancer_v2(network: ð::NetworkId) -> Option { + pub fn balancer_v2(graph_api_base_url: &Url, network: ð::NetworkId) -> Option { let factory_addresses = |contracts: &[ðcontract::Contract]| -> Vec { contracts @@ -205,6 +213,7 @@ impl BalancerV2 { contracts::BalancerV2ComposableStablePoolFactoryV5::raw_contract(), ]), pool_deny_list: Vec::new(), + graph_api_base_url: graph_api_base_url.clone(), }) } } diff --git a/crates/e2e/src/setup/colocation.rs b/crates/e2e/src/setup/colocation.rs index ba1a4603c6..d5e842167a 100644 --- a/crates/e2e/src/setup/colocation.rs +++ b/crates/e2e/src/setup/colocation.rs @@ -51,6 +51,7 @@ account = "0x{}" [liquidity] base-tokens = [] +graph-api-base-url = "https://api.thegraph.com/subgraphs/name/" [[liquidity.uniswap-v2]] router = "{:?}" diff --git a/crates/orderbook/src/run.rs b/crates/orderbook/src/run.rs index 98a469f04a..4b354eae1f 100644 --- a/crates/orderbook/src/run.rs +++ b/crates/orderbook/src/run.rs @@ -291,6 +291,7 @@ pub async fn run(args: Arguments) { .unwrap_or_else(|| BalancerFactoryKind::for_chain(chain_id)); let contracts = BalancerContracts::new(&web3, factories).await.unwrap(); match BalancerPoolFetcher::new( + &args.shared.graph_api_base_url, chain_id, block_retriever.clone(), token_info_fetcher.clone(), @@ -319,6 +320,7 @@ pub async fn run(args: Arguments) { }; let uniswap_v3_pool_fetcher = if baseline_sources.contains(&BaselineSource::UniswapV3) { match UniswapV3PoolFetcher::new( + &args.shared.graph_api_base_url, chain_id, web3.clone(), http_factory.create(), diff --git a/crates/shared/src/arguments.rs b/crates/shared/src/arguments.rs index 059ba21d5f..8302c9ea17 100644 --- a/crates/shared/src/arguments.rs +++ b/crates/shared/src/arguments.rs @@ -162,6 +162,10 @@ pub struct Arguments { #[clap(long, env, default_value = "http://localhost:8545")] pub node_url: Url, + /// The base URL used to connect to subgraph clients. + #[clap(long, env, default_value = "https://api.thegraph.com/subgraphs/name/")] + pub graph_api_base_url: Url, + /// An Ethereum node URL that supports `eth_call`s with state overrides to /// be used for simulations. #[clap(long, env)] @@ -414,6 +418,7 @@ impl Display for Arguments { self.logging.log_stderr_threshold )?; writeln!(f, "node_url: {}", self.node_url)?; + writeln!(f, "graph_api_base_url: {}", self.graph_api_base_url)?; display_option(f, "chain_id", &self.chain_id)?; display_option(f, "simulation_node_url", &self.simulation_node_url)?; writeln!(f, "gas_estimators: {:?}", self.gas_estimators)?; diff --git a/crates/shared/src/price_estimation/http.rs b/crates/shared/src/price_estimation/http.rs index 0da3e35447..3eba1d5cf4 100644 --- a/crates/shared/src/price_estimation/http.rs +++ b/crates/shared/src/price_estimation/http.rs @@ -765,8 +765,10 @@ mod tests { current_block_stream(Arc::new(web3.clone()), Duration::from_secs(10)) .await .unwrap(); + let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url"); let balancer_pool_fetcher = Arc::new( BalancerPoolFetcher::new( + &base_url, chain_id, block_retriever.clone(), token_info.clone(), @@ -782,6 +784,7 @@ mod tests { ); let uniswap_v3_pool_fetcher = Arc::new( UniswapV3PoolFetcher::new( + &base_url, chain_id, web3.clone(), client.clone(), diff --git a/crates/shared/src/sources/balancer_v2/graph_api.rs b/crates/shared/src/sources/balancer_v2/graph_api.rs index f565d6a4db..a6e2bbd942 100644 --- a/crates/shared/src/sources/balancer_v2/graph_api.rs +++ b/crates/shared/src/sources/balancer_v2/graph_api.rs @@ -13,7 +13,7 @@ use { crate::{event_handling::MAX_REORG_BLOCK_COUNT, subgraph::SubgraphClient}, anyhow::{bail, Result}, ethcontract::{H160, H256}, - reqwest::Client, + reqwest::{Client, Url}, serde::Deserialize, serde_json::json, serde_with::{serde_as, DisplayFromStr}, @@ -34,7 +34,7 @@ pub struct BalancerSubgraphClient(SubgraphClient); impl BalancerSubgraphClient { /// Creates a new Balancer subgraph client for the specified chain ID. - pub fn for_chain(chain_id: u64, client: Client) -> Result { + pub fn for_chain(base_url: &Url, chain_id: u64, client: Client) -> Result { let subgraph_name = match chain_id { 1 => "balancer-v2", 5 => "balancer-goerli-v2", @@ -42,6 +42,7 @@ impl BalancerSubgraphClient { _ => bail!("unsupported chain {}", chain_id), }; Ok(Self(SubgraphClient::new( + base_url, "balancer-labs", subgraph_name, client, @@ -254,6 +255,11 @@ mod tests { std::collections::HashMap, }; + pub fn default_for_chain(chain_id: u64, client: Client) -> Result { + let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url"); + BalancerSubgraphClient::for_chain(&base_url, chain_id, client) + } + #[test] fn decode_pools_data() { use pools_query::*; @@ -485,8 +491,7 @@ mod tests { async fn balancer_subgraph_query() { for (network_name, chain_id) in [("Mainnet", 1), ("Goerli", 5)] { println!("### {network_name}"); - - let client = BalancerSubgraphClient::for_chain(chain_id, Client::new()).unwrap(); + let client = default_for_chain(chain_id, Client::new()).unwrap(); let result = client.get_registered_pools().await.unwrap(); println!( "Retrieved {} total pools at block {}", diff --git a/crates/shared/src/sources/balancer_v2/pool_fetching.rs b/crates/shared/src/sources/balancer_v2/pool_fetching.rs index ab68ea9867..af0340d3b4 100644 --- a/crates/shared/src/sources/balancer_v2/pool_fetching.rs +++ b/crates/shared/src/sources/balancer_v2/pool_fetching.rs @@ -49,7 +49,7 @@ use { ethcontract::{dyns::DynInstance, BlockId, Instance, H160, H256}, ethrpc::current_block::{BlockRetrieving, CurrentBlockStream}, model::TokenPair, - reqwest::Client, + reqwest::{Client, Url}, std::{ collections::{BTreeMap, HashMap, HashSet}, sync::Arc, @@ -279,6 +279,7 @@ impl BalancerContracts { impl BalancerPoolFetcher { #[allow(clippy::too_many_arguments)] pub async fn new( + base_url: &Url, chain_id: u64, block_retriever: Arc, token_infos: Arc, @@ -289,7 +290,7 @@ impl BalancerPoolFetcher { contracts: &BalancerContracts, deny_listed_pool_ids: Vec, ) -> Result { - let pool_initializer = BalancerSubgraphClient::for_chain(chain_id, client)?; + let pool_initializer = BalancerSubgraphClient::for_chain(base_url, chain_id, client)?; let fetcher = Arc::new(Cache::new( create_aggregate_pool_fetcher( web3, @@ -532,7 +533,9 @@ mod tests { "072f14b85add63488ddad88f855fda4a99d6ac9b000200000000000000000027" ))]; // let deny_list = vec![]; + let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url"); let pool_fetcher = BalancerPoolFetcher::new( + &base_url, chain_id, Arc::new(web3.clone()), token_info_fetcher, @@ -590,9 +593,9 @@ mod tests { ), pool_id_deny_list: Default::default(), }; - + let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url"); // see what the subgraph says. - let client = BalancerSubgraphClient::for_chain(chain_id, Client::new()).unwrap(); + let client = BalancerSubgraphClient::for_chain(&base_url, chain_id, Client::new()).unwrap(); let subgraph_pools = client.get_registered_pools().await.unwrap(); let subgraph_token_pairs = subgraph_pools_token_pairs(&subgraph_pools.pools).collect(); diff --git a/crates/shared/src/sources/uniswap_v3/graph_api.rs b/crates/shared/src/sources/uniswap_v3/graph_api.rs index 2a80031ee5..df604e0de5 100644 --- a/crates/shared/src/sources/uniswap_v3/graph_api.rs +++ b/crates/shared/src/sources/uniswap_v3/graph_api.rs @@ -10,7 +10,7 @@ use { ethcontract::{H160, U256}, num::BigInt, number::serialization::HexOrDecimalU256, - reqwest::Client, + reqwest::{Client, Url}, serde::{Deserialize, Serialize}, serde_json::{json, Map, Value}, serde_with::{serde_as, DisplayFromStr}, @@ -107,12 +107,17 @@ pub struct UniV3SubgraphClient(SubgraphClient); impl UniV3SubgraphClient { /// Creates a new Uniswap V3 subgraph client for the specified chain ID. - pub fn for_chain(chain_id: u64, client: Client) -> Result { + pub fn for_chain(base_url: &Url, chain_id: u64, client: Client) -> Result { let subgraph_name = match chain_id { 1 => "uniswap-v3", _ => bail!("unsupported chain {}", chain_id), }; - Ok(Self(SubgraphClient::new("uniswap", subgraph_name, client)?)) + Ok(Self(SubgraphClient::new( + base_url, + "uniswap", + subgraph_name, + client, + )?)) } async fn get_pools(&self, query: &str, variables: Map) -> Result> { @@ -318,6 +323,11 @@ mod tests { std::str::FromStr, }; + pub fn default_for_chain(chain_id: u64, client: Client) -> Result { + let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url"); + UniV3SubgraphClient::for_chain(&base_url, chain_id, client) + } + #[test] fn decode_pools_data() { assert_eq!( @@ -472,7 +482,7 @@ mod tests { #[tokio::test] #[ignore] async fn get_registered_pools_test() { - let client = UniV3SubgraphClient::for_chain(1, Client::new()).unwrap(); + let client = default_for_chain(1, Client::new()).unwrap(); let result = client.get_registered_pools().await.unwrap(); println!( "Retrieved {} total pools at block {}", @@ -484,7 +494,7 @@ mod tests { #[tokio::test] #[ignore] async fn get_pools_by_pool_ids_test() { - let client = UniV3SubgraphClient::for_chain(1, Client::new()).unwrap(); + let client = default_for_chain(1, Client::new()).unwrap(); let registered_pools = client.get_registered_pools().await.unwrap(); let pool_ids = registered_pools .pools @@ -505,7 +515,7 @@ mod tests { #[tokio::test] #[ignore] async fn get_ticks_by_pools_ids_test() { - let client = UniV3SubgraphClient::for_chain(1, Client::new()).unwrap(); + let client = default_for_chain(1, Client::new()).unwrap(); let block_number = client.get_safe_block().await.unwrap(); let pool_ids = vec![ H160::from_str("0x9db9e0e53058c89e5b94e29621a205198648425b").unwrap(), @@ -521,7 +531,7 @@ mod tests { #[tokio::test] #[ignore] async fn get_pools_with_ticks_by_ids_test() { - let client = UniV3SubgraphClient::for_chain(1, Client::new()).unwrap(); + let client = default_for_chain(1, Client::new()).unwrap(); let block_number = client.get_safe_block().await.unwrap(); let pool_ids = vec![ H160::from_str("0x9db9e0e53058c89e5b94e29621a205198648425b").unwrap(), diff --git a/crates/shared/src/sources/uniswap_v3/pool_fetching.rs b/crates/shared/src/sources/uniswap_v3/pool_fetching.rs index 5102d85cb6..269eb754ab 100644 --- a/crates/shared/src/sources/uniswap_v3/pool_fetching.rs +++ b/crates/shared/src/sources/uniswap_v3/pool_fetching.rs @@ -18,7 +18,7 @@ use { model::TokenPair, num::{rational::Ratio, BigInt, Zero}, number::serialization::HexOrDecimalU256, - reqwest::Client, + reqwest::{Client, Url}, serde::Serialize, serde_with::{serde_as, DisplayFromStr}, std::{ @@ -131,11 +131,12 @@ impl PoolsCheckpointHandler { /// state/ticks). Then fetches state/ticks for the most deepest pools /// (subset of all existing pools) pub async fn new( + base_url: &Url, chain_id: u64, client: Client, max_pools_to_initialize_cache: usize, ) -> Result { - let graph_api = UniV3SubgraphClient::for_chain(chain_id, client)?; + let graph_api = UniV3SubgraphClient::for_chain(base_url, chain_id, client)?; let mut registered_pools = graph_api.get_registered_pools().await?; tracing::debug!( block = %registered_pools.fetched_block_number, pools = %registered_pools.pools.len(), @@ -265,6 +266,7 @@ pub struct UniswapV3PoolFetcher { impl UniswapV3PoolFetcher { pub async fn new( + base_url: &Url, chain_id: u64, web3: Web3, client: Client, @@ -272,7 +274,8 @@ impl UniswapV3PoolFetcher { max_pools_to_initialize: usize, ) -> Result { let checkpoint = - PoolsCheckpointHandler::new(chain_id, client, max_pools_to_initialize).await?; + PoolsCheckpointHandler::new(base_url, chain_id, client, max_pools_to_initialize) + .await?; let init_block = checkpoint.pools_checkpoint.lock().unwrap().block_number; let init_block = block_retriever.block(init_block).await?; @@ -723,9 +726,11 @@ mod tests { let transport = ethrpc::create_env_test_transport(); let web3 = Web3::new(transport); let block_retriever = Arc::new(web3.clone()); - let fetcher = UniswapV3PoolFetcher::new(1, web3, Client::new(), block_retriever, 100) - .await - .unwrap(); + let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url"); + let fetcher = + UniswapV3PoolFetcher::new(&base_url, 1, web3, Client::new(), block_retriever, 100) + .await + .unwrap(); assert!(!fetcher.checkpoint.pools_by_token_pair.is_empty()); assert!(!fetcher @@ -743,10 +748,17 @@ mod tests { let transport = ethrpc::create_env_test_transport(); let web3 = Web3::new(transport); let block_retriever = Arc::new(web3.clone()); - let fetcher = - UniswapV3PoolFetcher::new(1, web3.clone(), Client::new(), block_retriever, 100) - .await - .unwrap(); + let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url"); + let fetcher = UniswapV3PoolFetcher::new( + &base_url, + 1, + web3.clone(), + Client::new(), + block_retriever, + 100, + ) + .await + .unwrap(); fetcher.run_maintenance().await.unwrap(); let token_pairs = HashSet::from([ TokenPair::new( @@ -769,8 +781,9 @@ mod tests { .unwrap(); pools.sort_by(|a, b| a.address.cmp(&b.address)); + let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url"); // get the same pools using direct call to subgraph - let graph_api = UniV3SubgraphClient::for_chain(1, Client::new()).unwrap(); + let graph_api = UniV3SubgraphClient::for_chain(&base_url, 1, Client::new()).unwrap(); let pool_ids = pools.iter().map(|pool| pool.address).collect::>(); // first get at the block in history diff --git a/crates/shared/src/subgraph.rs b/crates/shared/src/subgraph.rs index 139b784b79..3536a04763 100644 --- a/crates/shared/src/subgraph.rs +++ b/crates/shared/src/subgraph.rs @@ -2,7 +2,6 @@ use { anyhow::{bail, Result}, - lazy_static::lazy_static, reqwest::{Client, IntoUrl, Url}, serde::{de::DeserializeOwned, Deserialize, Serialize}, serde_json::{json, Map, Value}, @@ -18,12 +17,6 @@ pub struct SubgraphClient { subgraph_url: Url, } -lazy_static! { - pub static ref DEFAULT_GRAPH_API_BASE_URL: Url = - Url::parse("https://api.thegraph.com/subgraphs/name/") - .expect("invalid default Graph API base URL"); -} - pub trait ContainsId { fn get_id(&self) -> String; } @@ -36,8 +29,13 @@ pub struct Data { impl SubgraphClient { /// Creates a new subgraph client from the specified organization and name. - pub fn new(org: impl AsRef, name: impl AsRef, client: Client) -> Result { - Self::with_base_url(DEFAULT_GRAPH_API_BASE_URL.clone(), org, name, client) + pub fn new( + base_url: &Url, + org: impl AsRef, + name: impl AsRef, + client: Client, + ) -> Result { + Self::with_base_url(base_url.clone(), org, name, client) } /// Creates a new subgraph client with the specified base URL. diff --git a/crates/solver/src/run.rs b/crates/solver/src/run.rs index 391d8e77ef..09fd848b1b 100644 --- a/crates/solver/src/run.rs +++ b/crates/solver/src/run.rs @@ -210,6 +210,7 @@ pub async fn run(args: Arguments) { .unwrap_or_else(|| BalancerFactoryKind::for_chain(chain_id)); let contracts = BalancerContracts::new(&web3, factories).await.unwrap(); match BalancerPoolFetcher::new( + &args.shared.graph_api_base_url, chain_id, block_retriever.clone(), token_info_fetcher.clone(), @@ -418,6 +419,7 @@ pub async fn run(args: Arguments) { if baseline_sources.contains(&BaselineSource::UniswapV3) { match UniswapV3PoolFetcher::new( + &args.shared.graph_api_base_url, chain_id, web3.clone(), http_factory.create(),