Skip to content

Clamp negative subgraph liquidity to 0 in pool-indexer seeding#4616

Open
AryanGodara wants to merge 5 commits into
mainfrom
aryan/pool-indexer-tolerate-negative-liquidity
Open

Clamp negative subgraph liquidity to 0 in pool-indexer seeding#4616
AryanGodara wants to merge 5 commits into
mainfrom
aryan/pool-indexer-tolerate-negative-liquidity

Conversation

@AryanGodara

@AryanGodara AryanGodara commented Jul 10, 2026

Copy link
Copy Markdown
Member

Description

Rolling out the pool-indexer on polygon staging, the bootstrap init container paniced after seeding ~12k pools due to subgraph seeding failed: parse liquidity. Caused by: invalid digit found in string

Root cause: the Uniswap V3 subgraph's liquidity is not the on-chain uint128 getter. the subgraph derives it incrementally, and it's reset to absolute on swaps.

The in-range check keys off pool.tick, which is only refreshed on swaps, so the running sum drifts and can go negative. The Graph serializes BigInt as a signed decimal string, so a value like "-967991328" fails .parse::<u128>(), and that error was aborting the initial seed.

Receipts: negative-liquidity pools from the polygon subgraph:

0x137308f66b84649132d1985d97bbb267f338e8b4  -967991328
0x5397c74039b97a3949ef20e2598b91c5be7ae0cd  -759058283752
0x5796062b5a8d207698373be746c974623ce521c0  -6419326288196812212
0x6d775af032b596e4eb71e888a6f1b7e37fc58821  -171385170910744
0x8572c67ede549f317e9f7bc8ccbe6065a15ec819  -28902987511385690976927

Each has a real tick + non-zero sqrtPrice, so it reaches the liquidity parse.

Changes

  • Clamp negative/unparseable subgraph liquidity to 0, matching the live indexer's apply_position_delta_to_pool_liq (which already clamps negative to 0). The pool keeps a state row and stays visible via the get_pools join, with its correct on-chain sqrtPrice/tick.
  • A warn! log to record the raw value.
  • Only liquidity is affected. sqrtPrice/tick stay strict. Ticks were already fine (liquidityNet → i128).

Safe because clamp-to-0 produces the same DB state the live indexer already writes in prod, and the same 0 the subgraph itself now returns for these pools; liquidity=0 is unusable for routing (a solver won't pick it) and the driver simulates before executing.

Testing

  • Unit + pool-indexer e2e (incl. driver integration).
  • Real polygon seed locally: 37.5k pools, no panic; the previously-negative pool now has a state row (liquidity=0) and is returned by get_pools_by_ids.
  • Tested on polygon staging on this branch's image

@AryanGodara AryanGodara self-assigned this Jul 10, 2026
@AryanGodara AryanGodara marked this pull request as ready for review July 10, 2026 11:00
@AryanGodara AryanGodara requested a review from a team as a code owner July 10, 2026 11:00
@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Claude finished @AryanGodara's task in 1m 33s —— View job


PR Review: Warn for negative subgraph liquidity in pool-indexer seeding

  • Read PR diff and context
  • Review changes in subgraph_seeder.rs
  • Post inline findings
  • Post summary

Verdict: LGTM ✅ — a clean, minimal, well-reasoned robustness fix.

The change correctly turns a bootstrap-aborting parse liquidity failure into a per-pool skip of just the seed state. I verified that:

  • The pool is still registered — persist_pool_page (line ~356) pushes pool_id/new_pool regardless of pool_state, so only the optional state is dropped. The PR's "pool stays registered" claim holds.
  • sqrtPrice/tick correctly remain strict; only unsigned liquidity is made lenient, which matches the root cause (signed subgraph drift vs. on-chain u128).

I left one inline comment with two non-blocking notes (a suggested regression unit test, and a wording nit that parse::<u128>() also guards against > u128::MAX). Nothing here should block merge.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the subgraph seeder to handle unparseable liquidity values by skipping the pool's seed state instead of aborting the bootstrap process. However, skipping the pool state entirely causes these pools to be omitted from queries due to an inner join on the pool states table. It is recommended to parse the liquidity as an i128 and clamp negative values to 0 to preserve the pool state.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/pool-indexer/src/subgraph_seeder.rs Outdated
Comment thread crates/pool-indexer/src/subgraph_seeder.rs Outdated
Comment thread crates/pool-indexer/src/subgraph_seeder.rs Outdated
@AryanGodara AryanGodara changed the title Warn for negative subgraph liquidity in pool-indexer seeding Clamp negative subgraph liquidity to 0 in pool-indexer seeding Jul 10, 2026
@AryanGodara AryanGodara requested a review from jmg-duarte July 10, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants