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

feat: change subgraph constructor to use full urls #2381

Merged
merged 35 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c805414
feat: change subgraph constructor to use full urls
fredmarques Feb 6, 2024
a9bd9e5
chore: update comment
fredmarques Feb 6, 2024
9836589
feat: add specifc urls for uniswapv3 and balancerv2 subgraphs
fredmarques Feb 7, 2024
12b9c42
Merge branch 'main' into configurable-subgraph-urls
fredmarques Feb 7, 2024
6afbe6e
Merge branch 'main' into configurable-subgraph-urls
fredmarques Feb 12, 2024
487ebe2
feat: add new URL settings to liquidity config
fredmarques Feb 12, 2024
dc248ee
test: rename client factory function
fredmarques Feb 12, 2024
6a15e97
test: fix test-driver
fredmarques Feb 12, 2024
8e1f00d
test: fix test-local-node
fredmarques Feb 12, 2024
6811647
lint: cargo +nightly fmt --all
fredmarques Feb 12, 2024
412021f
Update crates/shared/src/arguments.rs
fredmarques Feb 13, 2024
58f6747
Merge branch 'main' into configurable-subgraph-urls
fredmarques Feb 13, 2024
f3f98b5
Merge branch 'main' into configurable-subgraph-urls
fredmarques Feb 13, 2024
84c0d2d
feat: use predefined url only on presets
fredmarques Feb 20, 2024
2e50d6b
chore: merge main
fredmarques Feb 20, 2024
c9b311b
chore: remove empty file
fredmarques Feb 20, 2024
1eb773a
lint: remove ununsed export
fredmarques Feb 20, 2024
0be5dc7
lint
fredmarques Feb 20, 2024
42709ae
Merge branch 'main' into configurable-subgraph-urls
fredmarques Feb 20, 2024
e0e37f1
feat: add move subgraph url to uniswap and balancer, with default preset
fredmarques Feb 22, 2024
0ed8fd5
Update crates/driver/src/infra/config/file/mod.rs
fredmarques Feb 27, 2024
6d3aca4
chore: remove invalid example
fredmarques Feb 27, 2024
6af839c
feat: add default to graph_url on manual config
fredmarques Feb 27, 2024
3b0cb19
test: remove graph_urls from dirver test setup.
fredmarques Feb 27, 2024
34d69d6
chore: merge main
fredmarques Feb 27, 2024
5067cef
Merge branch 'main' into configurable-subgraph-urls
fredmarques Mar 4, 2024
a16035f
Merge branch 'main' into configurable-subgraph-urls
fredmarques Mar 10, 2024
1ead679
Merge branch 'main' into configurable-subgraph-urls
fredmarques Mar 18, 2024
784aa2e
Merge branch 'main' into configurable-subgraph-urls
fleupold Mar 19, 2024
3ad77c6
Merge remote-tracking branch 'origin/main' into configurable-subgraph…
MartinquaXD Mar 22, 2024
444b1df
Make shared CLI arg optional since the public graph no longer works
MartinquaXD Mar 22, 2024
20714b7
Adjust driver config logic
MartinquaXD Mar 22, 2024
6d0197d
Delete graph based liquidity from ignored unit test
MartinquaXD Mar 22, 2024
d756379
Delete tests that rely on publicly hosted graph
MartinquaXD Mar 22, 2024
386622e
Fix univ3 error log
MartinquaXD Mar 22, 2024
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
6 changes: 2 additions & 4 deletions crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,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,
&args.shared.graph_api_url,
block_retriever.clone(),
token_info_fetcher.clone(),
cache_config,
Expand Down Expand Up @@ -363,8 +362,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,
&args.shared.graph_api_url,
web3.clone(),
http_factory.create(),
block_retriever,
Expand Down
1 change: 0 additions & 1 deletion crates/driver/src/boundary/liquidity/balancer/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ 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(),
boundary::liquidity::cache_config(),
Expand Down
1 change: 0 additions & 1 deletion crates/driver/src/boundary/liquidity/uniswap/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ 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(),
block_retriever,
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/infra/config/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ struct LiquidityConfig {
#[serde(default)]
zeroex: Option<ZeroExConfig>,

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

Expand Down
6 changes: 2 additions & 4 deletions crates/orderbook/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,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,
&args.shared.graph_api_url,
block_retriever.clone(),
token_info_fetcher.clone(),
cache_config,
Expand Down Expand Up @@ -319,8 +318,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,
&args.shared.graph_api_url,
web3.clone(),
http_factory.create(),
block_retriever,
Expand Down
4 changes: 2 additions & 2 deletions crates/shared/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub struct Arguments {

/// 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,
pub graph_api_url: Url,

/// An Ethereum node URL that supports `eth_call`s with state overrides to
/// be used for simulations.
Expand Down Expand Up @@ -432,7 +432,7 @@ impl Display for Arguments {
tenderly,
logging,
node_url,
graph_api_base_url,
graph_api_url: graph_api_base_url,
chain_id,
simulation_node_url,
gas_estimators,
Expand Down
9 changes: 3 additions & 6 deletions crates/shared/src/price_estimation/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,6 @@ mod tests {
"main".into(),
);
let web3 = Web3::new(DynTransport::new(transport));
let chain_id = web3.eth().chain_id().await.unwrap().as_u64();
let version = web3.net().version().await.unwrap();

let pools = Arc::new(
Expand Down Expand Up @@ -766,11 +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 subgraph_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
let balancer_pool_fetcher = Arc::new(
BalancerPoolFetcher::new(
&base_url,
chain_id,
&subgraph_url,
block_retriever.clone(),
token_info.clone(),
Default::default(),
Expand All @@ -785,8 +783,7 @@ mod tests {
);
let uniswap_v3_pool_fetcher = Arc::new(
UniswapV3PoolFetcher::new(
&base_url,
chain_id,
&subgraph_url,
web3.clone(),
client.clone(),
block_retriever.clone(),
Expand Down
26 changes: 9 additions & 17 deletions crates/shared/src/sources/balancer_v2/graph_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use {
super::swap::fixed_point::Bfp,
crate::{event_handling::MAX_REORG_BLOCK_COUNT, subgraph::SubgraphClient},
anyhow::{bail, Result},
anyhow::Result,
ethcontract::{H160, H256},
reqwest::{Client, Url},
serde::Deserialize,
Expand All @@ -33,18 +33,10 @@ const QUERY_PAGE_SIZE: usize = 10;
pub struct BalancerSubgraphClient(SubgraphClient);

impl BalancerSubgraphClient {
/// Creates a new Balancer subgraph client for the specified chain ID.
pub fn for_chain(base_url: &Url, chain_id: u64, client: Client) -> Result<Self> {
let subgraph_name = match chain_id {
1 => "balancer-v2",
5 => "balancer-goerli-v2",
100 => "balancer-gnosis-chain-v2",
_ => bail!("unsupported chain {}", chain_id),
};
/// Creates a new Balancer subgraph client with full subgraph URL.
pub fn from_subgraph_url(subgraph_url: &Url, client: Client) -> Result<Self> {
Ok(Self(SubgraphClient::new(
base_url,
"balancer-labs",
subgraph_name,
subgraph_url.clone(),
client,
)?))
}
Expand Down Expand Up @@ -256,9 +248,9 @@ mod tests {
std::collections::HashMap,
};

pub fn default_for_chain(chain_id: u64, client: Client) -> Result<BalancerSubgraphClient> {
let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
BalancerSubgraphClient::for_chain(&base_url, chain_id, client)
pub fn default_for_chain(client: Client) -> Result<BalancerSubgraphClient> {
let subgraph_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
BalancerSubgraphClient::from_subgraph_url(&subgraph_url, client)
}

#[test]
Expand Down Expand Up @@ -490,9 +482,9 @@ mod tests {
#[tokio::test]
#[ignore]
async fn balancer_subgraph_query() {
for (network_name, chain_id) in [("Mainnet", 1), ("Goerli", 5)] {
for network_name in ["Mainnet", "Goerli"] {
println!("### {network_name}");
let client = default_for_chain(chain_id, Client::new()).unwrap();
let client = default_for_chain(Client::new()).unwrap();
let result = client.get_registered_pools().await.unwrap();
println!(
"Retrieved {} total pools at block {}",
Expand Down
15 changes: 6 additions & 9 deletions crates/shared/src/sources/balancer_v2/pool_fetching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ impl BalancerContracts {
impl BalancerPoolFetcher {
#[allow(clippy::too_many_arguments)]
pub async fn new(
base_url: &Url,
chain_id: u64,
subgraph_url: &Url,
block_retriever: Arc<dyn BlockRetrieving>,
token_infos: Arc<dyn TokenInfoFetching>,
config: CacheConfig,
Expand All @@ -296,7 +295,7 @@ impl BalancerPoolFetcher {
contracts: &BalancerContracts,
deny_listed_pool_ids: Vec<H256>,
) -> Result<Self> {
let pool_initializer = BalancerSubgraphClient::for_chain(base_url, chain_id, client)?;
let pool_initializer = BalancerSubgraphClient::from_subgraph_url(subgraph_url, client)?;
let fetcher = Arc::new(Cache::new(
create_aggregate_pool_fetcher(
web3,
Expand Down Expand Up @@ -520,7 +519,6 @@ mod tests {
async fn balancer_pool_fetcher_print() {
let transport = ethrpc::create_env_test_transport();
let web3 = Web3::new(transport);
let chain_id = web3.eth().chain_id().await.unwrap().as_u64();
let contracts =
BalancerContracts::new(&web3, BalancerFactoryKind::value_variants().to_vec())
.await
Expand All @@ -539,10 +537,9 @@ mod tests {
"072f14b85add63488ddad88f855fda4a99d6ac9b000200000000000000000027"
))];
// let deny_list = vec![];
let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
let subgraph_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
let pool_fetcher = BalancerPoolFetcher::new(
&base_url,
chain_id,
&subgraph_url,
Arc::new(web3.clone()),
token_info_fetcher,
Default::default(),
Expand Down Expand Up @@ -599,9 +596,9 @@ mod tests {
),
pool_id_deny_list: Default::default(),
};
let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
let subgraph_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
// see what the subgraph says.
let client = BalancerSubgraphClient::for_chain(&base_url, chain_id, Client::new()).unwrap();
let client = BalancerSubgraphClient::from_subgraph_url(&subgraph_url, Client::new()).unwrap();
let subgraph_pools = client.get_registered_pools().await.unwrap();
let subgraph_token_pairs = subgraph_pools_token_pairs(&subgraph_pools.pools).collect();

Expand Down
33 changes: 15 additions & 18 deletions crates/shared/src/sources/uniswap_v3/graph_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
event_handling::MAX_REORG_BLOCK_COUNT,
subgraph::{ContainsId, SubgraphClient},
},
anyhow::{bail, Result},
anyhow::Result,
ethcontract::{H160, U256},
num::BigInt,
number::serialization::HexOrDecimalU256,
Expand Down Expand Up @@ -106,16 +106,10 @@ const TICKS_BY_POOL_IDS_QUERY: &str = r#"
pub struct UniV3SubgraphClient(SubgraphClient);

impl UniV3SubgraphClient {
/// Creates a new Uniswap V3 subgraph client for the specified chain ID.
pub fn for_chain(base_url: &Url, chain_id: u64, client: Client) -> Result<Self> {
let subgraph_name = match chain_id {
1 => "uniswap-v3",
_ => bail!("unsupported chain {}", chain_id),
};
/// Creates a new Uniswap V3 subgraph client from the specified URL.
pub fn from_subgraph_url(subgraph_url: &Url, client: Client) -> Result<Self> {
Ok(Self(SubgraphClient::new(
base_url,
"uniswap",
subgraph_name,
subgraph_url.clone(),
client,
)?))
}
Expand Down Expand Up @@ -323,13 +317,16 @@ mod tests {
std::str::FromStr,
};

pub fn default_for_chain(chain_id: u64, client: Client) -> Result<UniV3SubgraphClient> {
let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
UniV3SubgraphClient::for_chain(&base_url, chain_id, client)
pub fn default_for_chain(client: Client) -> Result<UniV3SubgraphClient> {
let subgraph_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
UniV3SubgraphClient::from_subgraph_url(
&subgraph_url,
client
)
}

#[test]
fn decode_pools_data() {
fn decode_pools_data(){
assert_eq!(
serde_json::from_value::<Data<PoolData>>(json!({
"pools": [
Expand Down Expand Up @@ -482,7 +479,7 @@ mod tests {
#[tokio::test]
#[ignore]
async fn get_registered_pools_test() {
let client = default_for_chain(1, Client::new()).unwrap();
let client = default_for_chain(Client::new()).unwrap();
let result = client.get_registered_pools().await.unwrap();
println!(
"Retrieved {} total pools at block {}",
Expand All @@ -494,7 +491,7 @@ mod tests {
#[tokio::test]
#[ignore]
async fn get_pools_by_pool_ids_test() {
let client = default_for_chain(1, Client::new()).unwrap();
let client = default_for_chain(Client::new()).unwrap();
let registered_pools = client.get_registered_pools().await.unwrap();
let pool_ids = registered_pools
.pools
Expand All @@ -515,7 +512,7 @@ mod tests {
#[tokio::test]
#[ignore]
async fn get_ticks_by_pools_ids_test() {
let client = default_for_chain(1, Client::new()).unwrap();
let client = default_for_chain(Client::new()).unwrap();
let block_number = client.get_safe_block().await.unwrap();
let pool_ids = vec![
H160::from_str("0x9db9e0e53058c89e5b94e29621a205198648425b").unwrap(),
Expand All @@ -531,7 +528,7 @@ mod tests {
#[tokio::test]
#[ignore]
async fn get_pools_with_ticks_by_ids_test() {
let client = default_for_chain(1, Client::new()).unwrap();
let client = default_for_chain(Client::new()).unwrap();
let block_number = client.get_safe_block().await.unwrap();
let pool_ids = vec![
H160::from_str("0x9db9e0e53058c89e5b94e29621a205198648425b").unwrap(),
Expand Down
25 changes: 12 additions & 13 deletions crates/shared/src/sources/uniswap_v3/pool_fetching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ 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,
subgraph_url: &Url,
client: Client,
max_pools_to_initialize_cache: usize,
) -> Result<Self> {
let graph_api = UniV3SubgraphClient::for_chain(base_url, chain_id, client)?;
let graph_api = UniV3SubgraphClient::from_subgraph_url(subgraph_url, client)?;
let mut registered_pools = graph_api.get_registered_pools().await?;
tracing::debug!(
block = %registered_pools.fetched_block_number, pools = %registered_pools.pools.len(),
Expand Down Expand Up @@ -266,15 +265,14 @@ pub struct UniswapV3PoolFetcher {

impl UniswapV3PoolFetcher {
pub async fn new(
base_url: &Url,
chain_id: u64,
subgraph_url: &Url,
web3: Web3,
client: Client,
block_retriever: Arc<dyn BlockRetrieving>,
max_pools_to_initialize: usize,
) -> Result<Self> {
let checkpoint =
PoolsCheckpointHandler::new(base_url, chain_id, client, max_pools_to_initialize)
PoolsCheckpointHandler::new(subgraph_url, client, max_pools_to_initialize)
.await?;

let init_block = checkpoint.pools_checkpoint.lock().unwrap().block_number;
Expand Down Expand Up @@ -726,9 +724,10 @@ mod tests {
let transport = ethrpc::create_env_test_transport();
let web3 = Web3::new(transport);
let block_retriever = Arc::new(web3.clone());
let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
let subgraph_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)
UniswapV3PoolFetcher::new( &subgraph_url, web3, Client::new(), block_retriever, 100)
.await
.unwrap();

Expand All @@ -748,10 +747,9 @@ mod tests {
let transport = ethrpc::create_env_test_transport();
let web3 = Web3::new(transport);
let block_retriever = Arc::new(web3.clone());
let base_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
let subgraph_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
let fetcher = UniswapV3PoolFetcher::new(
&base_url,
1,
&subgraph_url,
web3.clone(),
Client::new(),
block_retriever,
Expand Down Expand Up @@ -781,9 +779,10 @@ 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(&base_url, 1, Client::new()).unwrap();
let subgraph_url = Url::parse("https://api.thegraph.com/subgraphs/name/").expect("invalid url");
let graph_api = UniV3SubgraphClient::from_subgraph_url(&subgraph_url, Client::new()).unwrap();
let pool_ids = pools.iter().map(|pool| pool.address).collect::<Vec<_>>();

// first get at the block in history
Expand Down
Loading
Loading