Skip to content

Commit

Permalink
feat: change subgraph constructor to use full urls (#2381)
Browse files Browse the repository at this point in the history
# Description
This PR fixes #2105 

# Changes
Subgraph constrictor now uses full urls

## How to test
All unit tests still pass

## Related Issues

Fixes  #2105

---------

Co-authored-by: Martin Beckmann <[email protected]>
Co-authored-by: Felix Leupold <[email protected]>
  • Loading branch information
3 people authored Mar 22, 2024
1 parent e09bded commit 6ff4eda
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 560 deletions.
16 changes: 12 additions & 4 deletions crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,13 @@ pub async fn run(args: Arguments) {
.clone()
.unwrap_or_else(|| BalancerFactoryKind::for_chain(chain_id));
let contracts = BalancerContracts::new(&web3, factories).await.unwrap();
let graph_url = args
.shared
.balancer_v2_graph_url
.as_ref()
.expect("provide a balancer subgraph url when enabling balancer liquidity");
match BalancerPoolFetcher::new(
&args.shared.graph_api_base_url,
chain_id,
graph_url,
block_retriever.clone(),
token_info_fetcher.clone(),
cache_config,
Expand All @@ -355,9 +359,13 @@ pub async fn run(args: Arguments) {
None
};
let uniswap_v3_pool_fetcher = if baseline_sources.contains(&BaselineSource::UniswapV3) {
let graph_url = args
.shared
.uniswap_v3_graph_url
.as_ref()
.expect("provide a uniswapV3 subgraph url when enabling uniswapV3 liquidity");
match UniswapV3PoolFetcher::new(
&args.shared.graph_api_base_url,
chain_id,
graph_url,
web3.clone(),
http_factory.create(),
block_retriever,
Expand Down
4 changes: 2 additions & 2 deletions crates/driver/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ 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.

Expand All @@ -62,6 +60,7 @@ graph-api-base-url = "https://api.thegraph.com/subgraphs/name/"

# [[liquidity.balancer-v2]] # Balancer V2 configuration
# preset = "balancer-v2"
# graph-url = "http://localhost:1234" # which subgraph url to fetch the data from
# pool-deny-list = [] # optional

# [[liquidity.balancer-v2]] # Custom Balancer V2 configuration
Expand All @@ -73,6 +72,7 @@ graph-api-base-url = "https://api.thegraph.com/subgraphs/name/"

# [[liquidity.uniswap-v3]] # Uniswap V3 configuration
# preset = "uniswap-v3"
# graph-url = "http://localhost:1234" # which subgraph url to fetch the data from
# max_pools_to_initialize = 100 # how many of the deepest pools to initialise on startup

# [[liquidity.uniswap-v3]] # Custom Uniswap V3 configuration
Expand Down
3 changes: 1 addition & 2 deletions crates/driver/src/boundary/liquidity/balancer/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ async fn init_liquidity(

let balancer_pool_fetcher = Arc::new(
BalancerPoolFetcher::new(
&config.graph_api_base_url,
eth.network().0,
&config.graph_url,
block_retriever.clone(),
token_info_fetcher.clone(),
boundary::liquidity::cache_config(),
Expand Down
3 changes: 1 addition & 2 deletions crates/driver/src/boundary/liquidity/uniswap/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ async fn init_liquidity(

let pool_fetcher = Arc::new(
UniswapV3PoolFetcher::new(
&config.graph_api_base_url,
eth.network().0,
&config.graph_url,
web3.clone(),
boundary::liquidity::http_client(),
block_retriever,
Expand Down
27 changes: 8 additions & 19 deletions crates/driver/src/infra/config/file/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@ use {
infra::{self, blockchain, config::file, liquidity, mempool, simulator, solver},
},
futures::future::join_all,
lazy_static::lazy_static,
reqwest::Url,
std::path::Path,
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.
///
Expand Down Expand Up @@ -43,10 +35,6 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config {
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 {
Expand Down Expand Up @@ -167,22 +155,24 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config {
file::UniswapV3Config::Preset {
preset,
max_pools_to_initialize,
graph_url,
} => liquidity::config::UniswapV3 {
max_pools_to_initialize,
..match preset {
file::UniswapV3Preset::UniswapV3 => {
liquidity::config::UniswapV3::uniswap_v3(&graph_api_base_url, chain)
liquidity::config::UniswapV3::uniswap_v3(&graph_url, chain)
}
}
.expect("no Uniswap V3 preset for current network")
},
file::UniswapV3Config::Manual {
router,
max_pools_to_initialize,
graph_url,
} => liquidity::config::UniswapV3 {
router: router.into(),
max_pools_to_initialize,
graph_api_base_url: graph_api_base_url.clone(),
graph_url,
},
})
.collect(),
Expand All @@ -195,14 +185,12 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config {
file::BalancerV2Config::Preset {
preset,
pool_deny_list,
graph_url,
} => liquidity::config::BalancerV2 {
pool_deny_list: pool_deny_list.clone(),
..match preset {
file::BalancerV2Preset::BalancerV2 => {
liquidity::config::BalancerV2::balancer_v2(
&graph_api_base_url,
chain,
)
liquidity::config::BalancerV2::balancer_v2(&graph_url, chain)
}
}
.expect("no Balancer V2 preset for current network")
Expand All @@ -215,6 +203,7 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config {
liquidity_bootstrapping,
composable_stable,
pool_deny_list,
graph_url,
} => liquidity::config::BalancerV2 {
vault: vault.into(),
weighted: weighted
Expand All @@ -235,7 +224,7 @@ pub async fn load(chain: eth::ChainId, 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(),
graph_url,
},
})
.collect(),
Expand Down
14 changes: 11 additions & 3 deletions crates/driver/src/infra/config/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ struct LiquidityConfig {
/// Liquidity provided by 0x API.
#[serde(default)]
zeroex: Option<ZeroExConfig>,

/// The base URL used to connect to subgraph clients.
graph_api_base_url: Option<Url>,
}

#[derive(Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -387,6 +384,8 @@ enum UniswapV3Config {
/// How many pools to initialize during start up.
#[serde(default = "uniswap_v3::default_max_pools_to_initialize")]
max_pools_to_initialize: usize,

graph_url: Url,
},

#[serde(rename_all = "kebab-case")]
Expand All @@ -397,6 +396,9 @@ enum UniswapV3Config {
/// How many pools to initialize during start up.
#[serde(default = "uniswap_v3::default_max_pools_to_initialize")]
max_pools_to_initialize: usize,

/// The URL used to connect to uniswap v3 subgraph client.
graph_url: Url,
},
}

Expand All @@ -422,6 +424,9 @@ enum BalancerV2Config {
/// Deny listed Balancer V2 pools.
#[serde(default)]
pool_deny_list: Vec<eth::H256>,

/// The URL used to connect to balancer v2 subgraph client.
graph_url: Url,
},

#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -455,6 +460,9 @@ enum BalancerV2Config {
/// Deny listed Balancer V2 pools.
#[serde(default)]
pool_deny_list: Vec<eth::H256>,

/// The URL used to connect to balancer v2 subgraph client.
graph_url: Url,
},
}

Expand Down
16 changes: 8 additions & 8 deletions crates/driver/src/infra/liquidity/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ pub struct UniswapV3 {
/// 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,
/// The URL used to connect to uniswap v3 subgraph client.
pub graph_url: Url,
}

impl UniswapV3 {
/// Returns the liquidity configuration for Uniswap V3.
#[allow(clippy::self_named_constructors)]
pub fn uniswap_v3(graph_api_base_url: &Url, chain: eth::ChainId) -> Option<Self> {
pub fn uniswap_v3(graph_url: &Url, chain: eth::ChainId) -> Option<Self> {
Some(Self {
router: deployment_address(contracts::UniswapV3SwapRouter::raw_contract(), chain)?,
max_pools_to_initialize: 100,
graph_api_base_url: graph_api_base_url.clone(),
graph_url: graph_url.clone(),
})
}
}
Expand Down Expand Up @@ -189,14 +189,14 @@ pub struct BalancerV2 {
/// ignored.
pub pool_deny_list: Vec<eth::H256>,

/// The base URL used to connect to subgraph clients.
pub graph_api_base_url: Url,
/// The base URL used to connect to balancer v2 subgraph client.
pub graph_url: Url,
}

impl BalancerV2 {
/// Returns the liquidity configuration for Balancer V2.
#[allow(clippy::self_named_constructors)]
pub fn balancer_v2(graph_api_base_url: &Url, chain: eth::ChainId) -> Option<Self> {
pub fn balancer_v2(graph_url: &Url, chain: eth::ChainId) -> Option<Self> {
let factory_addresses =
|contracts: &[&ethcontract::Contract]| -> Vec<eth::ContractAddress> {
contracts
Expand Down Expand Up @@ -228,7 +228,7 @@ impl BalancerV2 {
contracts::BalancerV2ComposableStablePoolFactoryV5::raw_contract(),
]),
pool_deny_list: Vec::new(),
graph_api_base_url: graph_api_base_url.clone(),
graph_url: graph_url.clone(),
})
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/e2e/src/setup/colocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ weth = "{:?}"
[liquidity]
base-tokens = []
graph-api-base-url = "https://api.thegraph.com/subgraphs/name/"
[[liquidity.uniswap-v2]]
router = "{:?}"
Expand Down
16 changes: 12 additions & 4 deletions crates/orderbook/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,13 @@ pub async fn run(args: Arguments) {
.clone()
.unwrap_or_else(|| BalancerFactoryKind::for_chain(chain_id));
let contracts = BalancerContracts::new(&web3, factories).await.unwrap();
let graph_url = args
.shared
.balancer_v2_graph_url
.as_ref()
.expect("provide a balancer subgraph url when enabling balancer liquidity");
match BalancerPoolFetcher::new(
&args.shared.graph_api_base_url,
chain_id,
graph_url,
block_retriever.clone(),
token_info_fetcher.clone(),
cache_config,
Expand All @@ -313,9 +317,13 @@ pub async fn run(args: Arguments) {
None
};
let uniswap_v3_pool_fetcher = if baseline_sources.contains(&BaselineSource::UniswapV3) {
let graph_url = args
.shared
.uniswap_v3_graph_url
.as_ref()
.expect("provide a uniswapV3 subgraph url when enabling uniswapV3 liquidity");
match UniswapV3PoolFetcher::new(
&args.shared.graph_api_base_url,
chain_id,
graph_url,
web3.clone(),
http_factory.create(),
block_retriever,
Expand Down
16 changes: 11 additions & 5 deletions crates/shared/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ 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,
/// The Balancer subgraph URL.
#[clap(long, env)]
pub balancer_v2_graph_url: Option<Url>,

/// The UniswapV3 subgraph URL.
#[clap(long, env)]
pub uniswap_v3_graph_url: Option<Url>,

/// An Ethereum node URL that supports `eth_call`s with state overrides to
/// be used for simulations.
Expand Down Expand Up @@ -396,7 +400,8 @@ impl Display for Arguments {
tenderly,
logging,
node_url,
graph_api_base_url,
balancer_v2_graph_url,
uniswap_v3_graph_url,
chain_id,
simulation_node_url,
gas_estimators,
Expand Down Expand Up @@ -434,7 +439,8 @@ impl Display for Arguments {
write!(f, "{}", tenderly)?;
write!(f, "{}", logging)?;
writeln!(f, "node_url: {}", node_url)?;
writeln!(f, "graph_api_base_url: {}", graph_api_base_url)?;
display_option(f, "balancer_v2_graph_url: {}", balancer_v2_graph_url)?;
display_option(f, "uniswap_v3_graph_url: {}", uniswap_v3_graph_url)?;
display_option(f, "chain_id", chain_id)?;
display_option(f, "simulation_node_url", simulation_node_url)?;
writeln!(f, "gas_estimators: {:?}", gas_estimators)?;
Expand Down
Loading

0 comments on commit 6ff4eda

Please sign in to comment.