Pool Indexer crate for uniswap-v3 liquidity from subgraphs#4422
Pool Indexer crate for uniswap-v3 liquidity from subgraphs#4422AryanGodara wants to merge 3 commits into
Conversation
|
Reminder: Please update the DB Readme and comment whether migrations are reversible (include rollback scripts if applicable).
Caused by: |
5937458 to
f10f0fc
Compare
|
|
||
| /// Kebab-case slug used in URLs and per-network configs (pool-indexer API | ||
| /// routes, DB database names, etc). Stable — other services parse it. | ||
| pub fn slug(&self) -> &'static str { |
There was a problem hiding this comment.
| pub fn slug(&self) -> &'static str { | |
| pub fn as_str(&self) -> &'static str { |
| pub fn slug(&self) -> &'static str { | ||
| match &self { | ||
| Self::Mainnet => "mainnet", | ||
| Self::Goerli => "goerli", |
There was a problem hiding this comment.
note: goerli is no longer up, maybe we should remove this
| pub mod autopilot; | ||
| pub mod banned_users; | ||
| pub mod database; | ||
| pub(crate) mod deserialize_env; |
There was a problem hiding this comment.
To me, this starts to hint that this should probably be a crate on its own, but at the same time IMO the configs crate should be removed and the configs moved to their "users"
| // TODO: model these two URLs as an enum (Graph / PoolIndexer / Both) | ||
| // once serde supports `deny_unknown_fields` with internally-tagged or | ||
| // flattened enum variants — https://github.com/serde-rs/serde/issues/1547. |
There was a problem hiding this comment.
I still wonder if there's a better way even if we need to modify the config again
| ### Reversibility | ||
|
|
||
| We do not ship paired `down`/rollback scripts with our Flyway migrations. The release model (autopilot rolls forward, old pods drain after the new schema is in place) means rollback is handled by deploying a previous binary against the migrated schema, not by reversing the SQL. Migrations must therefore be **forward-compatible with the previous binary** for the duration of the rolling deployment. | ||
|
|
||
| `V110__pool_indexer_uniswap_v3.sql` is purely additive: it introduces four new tables (`pool_indexer_checkpoints`, `uniswap_v3_pools`, `uniswap_v3_pool_states`, `uniswap_v3_ticks`) and four partial indexes. Nothing in the rest of the schema is touched, so the previous binary continues to function unchanged during the overlap window. If we ever need to undo it, the rollback is a `DROP TABLE ... CASCADE` on those four tables — but with `pool-indexer-url` unset on all chains (the default), nothing reads from them anyway, so a forward-only rollout is the expected path. |
There was a problem hiding this comment.
This seems like a justification Claude wrote for you, I don't think this is necessary, especially in the readme
The drop instructions could be in the migration itself
| /// Retry only when `should_retry(&err)` returns true. Permanent errors | ||
| /// (e.g. contract reverts, bad input) bail out immediately so callers don't | ||
| /// waste sleep budget on something that won't get better. | ||
| pub async fn retry_with_sleep_if<F, T, E, P>( |
There was a problem hiding this comment.
Nit: the autopilot has one very similar if not the same function
You could create another PR moving it out and pointing to this one
Or just remove it from the autopilot in this one
| #!/usr/bin/env bash | ||
| # Wipes the local test DB, re-applies migrations, and runs pool-indexer | ||
| # against config.local.toml (mainnet + Ink by default). | ||
| set -euo pipefail |
There was a problem hiding this comment.
Add the purpose / usage of this script in the docs
| path = "src/main.rs" | ||
|
|
||
| [dependencies] | ||
| alloy = { workspace = true, features = ["contract", "providers", "rpc-types", "sol-types"] } |
There was a problem hiding this comment.
Could you replace the broad usage of alloy with the separate crates? it enables this crate to be compiled earlier than alloy is available
Description
Replaces our driver's third-party Uniswap V3 subgraph dependency with our
own pool-indexer service. This is the subgraph-bootstrap slice of
the larger #4349, to keep the scope focused. Along with some fixes surfaced during local testing.
Out of scope (deferred to a follow-up PRs):
Changes
New service:
crates/pool-indexer/eth_getLogsand persists incremental state to Postgres/pools,/pools/by-ids,/pools/{addr}/ticks,/pools/ticksDriver-side abstraction (same as original PR, already reviewed)
V3PoolDataSourcetrait inliquidity-sources/src/uniswap_v3/mod.rsUniV3SubgraphClient(no behavior change) + newPoolIndexerClientbuild_pool_data_sourceselects the impl based on the optionalpool-indexer-urldriver config; defaults to subgraphDatabase migration:
V110__pool_indexer_uniswap_v3.sqlpool_indexer_checkpoints,uniswap_v3_pools,uniswap_v3_pool_states,uniswap_v3_ticksIS NULLcolumns for the backfill hot pathE2E test
local_node_pool_indexer_driver_integrationtest exercising thedriver → pool-indexer wiring. Uses inline
alloy::sol!macros withembedded compiled bytecode for the mock V3 contracts.
Local Testing Findings
Summary of what was verified locally against Ink mainnet (chain 57073):
8266 ticks loaded in ~30s via bearer auth.
indexed_blockgaugetracking,
caught up to finalized blocklog).INFO uniswap v3: using pool-indexer as data source url=....via
pool_indexer_api_requests.USDT0 ↔ WETH both directions returned HTTP 200 with internally
consistent prices (WETH ≈ $2078–$2141).
(Also consistent with current price, when I tested)