Skip to content

fix / return real ERC20 balances in Uniswap CLMM pool-info#635

Merged
fengtality merged 2 commits into
developmentfrom
fix/uniswap-clmm-pool-info-token-amounts
May 15, 2026
Merged

fix / return real ERC20 balances in Uniswap CLMM pool-info#635
fengtality merged 2 commits into
developmentfrom
fix/uniswap-clmm-pool-info-token-amounts

Conversation

@fengtality
Copy link
Copy Markdown
Contributor

Summary

  • GET /connectors/uniswap/clmm/pool-info was returning pool.liquidity / 10^decimals for both base and quote token amounts.
  • Uniswap V3's liquidity is the active virtual liquidity in sqrt-price space (~sqrt(x * y)), not a token amount. The route's output for baseTokenAmount / quoteTokenAmount was meaningless.
  • Replace with getERC20BalanceByAddress(token, poolAddress) for both token0 and token1 — the same pattern the Orca CLMM pool-info route uses.

Reproduction

Against the USDM1/USDC pool 0x6f161ad0e297ecb9d1b33c048272ccc964cb4b6a (real on-chain TVL: ~167.6K USDM1 / ~182.1K USDC):

curl "http://localhost:15888/connectors/uniswap/clmm/pool-info?network=mainnet&poolAddress=0x6f161ad0e297ecb9d1b33c048272ccc964cb4b6a"

Before

{ "baseTokenAmount": 11.034936417288527, "quoteTokenAmount": 11034936417288.527 }

(Both numbers come from pool.liquidity = 11034936417288527 divided by each token's decimals.)

After

{ "baseTokenAmount": 167600, "quoteTokenAmount": 182100 }

Test plan

  • New regression tests in test/connectors/uniswap/clmm-routes/pool-info.test.ts covering:
    • token amounts come from ERC20 balanceOf, not pool.liquidity
    • explicit assertion that the returned values are NOT the legacy buggy values
    • base/quote mapping flips correctly when the caller treats token1 as the base
  • pnpm typecheck clean
  • pnpm lint 0 errors

🤖 Generated with Claude Code

The /connectors/uniswap/clmm/pool-info route was returning
pool.liquidity / 10^decimals for both base and quote token amounts.
Uniswap V3's `liquidity` is the active virtual liquidity in sqrt-price
space (~sqrt(x*y)), not a token amount, so the returned values were
meaningless — for the USDM1/USDC pool the route reported 11 USDM1 and
11 trillion USDC instead of the actual ~167.6K USDM1 / ~182.1K USDC.

Replace with ERC20 balanceOf(poolAddress) for token0 and token1, the
same pattern used by the Orca CLMM pool-info route.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fengtality fengtality added this to the v2.15 milestone May 11, 2026
@rapcmia rapcmia changed the title fix: return real ERC20 balances in Uniswap CLMM pool-info fix / return real ERC20 balances in Uniswap CLMM pool-info May 12, 2026
@rapcmia rapcmia moved this to Backlog in Pull Request Board May 12, 2026
Copy link
Copy Markdown
Contributor

@nikspz nikspz left a comment

Choose a reason for hiding this comment

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

@fengtality
Copy link
Copy Markdown
Contributor Author

@nikspz thanks for the thorough test report — the 400 "Token information not found for pool" you hit on 0x6f161ad0e297ecb9d1b33c048272ccc964cb4b6a is not a regression from this PR. It's an existing constraint of /connectors/uniswap/clmm/pool-info: it resolves token metadata via the local token list (conf/tokens/ethereum/mainnet.json), and USDM1 (0x90a1717E0dABE37693f79aFe43AE236dc3b65957) wasn't in it.

The cleaner workflow exists on development (now merged into this branch as e3f6fd9) — POST /pools/save/:address auto-adds missing tokens via GeckoTerminal before saving the pool. Please re-pull the branch and re-run with that endpoint:

curl -X POST 'http://localhost:15888/pools/save/0x6f161ad0e297ecb9d1b33c048272ccc964cb4b6a?chainNetwork=ethereum-mainnet'

The response will include "tokensAdded": ["USDM1"] if GeckoTerminal had token info for it. After that, /connectors/uniswap/clmm/pool-info?network=mainnet&poolAddress=0x6f161ad0e297ecb9d1b33c048272ccc964cb4b6a should return the same shape as your USDC/ETH check, with the new ERC20-balance-based baseTokenAmount / quoteTokenAmount this PR is about.

If tokensAdded is missing from the response, GeckoTerminal didn't have token data for USDM1 and the auto-add silently fell through (logged as a warn on the server). In that case, register the token manually first and then retry pool-info:

curl -X POST 'http://localhost:15888/tokens/save/0x90a1717E0dABE37693f79aFe43AE236dc3b65957?chainNetwork=ethereum-mainnet'

@nikspz
Copy link
Copy Markdown
Contributor

nikspz commented May 14, 2026

yes,

curl -X POST 'http://localhost:15888/pools/save/0x6f161ad0e297ecb9d1b33c048272ccc964cb4b6a?chainNetwork=ethereum-mainnet'

and

curl -X POST 'http://localhost:15888/tokens/save/0x90a1717E0dABE37693f79aFe43AE236dc3b65957?chainNetwork=ethereum-mainnet'

helps

now returned for curl "http://localhost:15888/connectors/uniswap/clmm/pool-info?network=mainnet&poolAddress=0x6f161ad0e297ecb9d1b33c048272ccc964cb4b6a"

{"address":"0x6f161ad0e297ecb9d1b33c048272ccc964cb4b6a","baseTokenAddress":"0x90a1717E0dABE37693f79aFe43AE236dc3b65957","quoteTokenAddress":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","feePct":0.01,"price":1.0116788519894,"baseTokenAmount":167517.0177590482,"quoteTokenAmount":182086.464231,"activeBinId":-276208,"binStep":1}

"baseTokenAmount":167517.0177590482,"quoteTokenAmount":182086.464231 (matched with uniswap) ✅

@fengtality fengtality merged commit 9ec2acf into development May 15, 2026
5 checks passed
@fengtality fengtality deleted the fix/uniswap-clmm-pool-info-token-amounts branch May 15, 2026 02:40
@rapcmia rapcmia moved this from Backlog to Development 2.15.0 in Pull Request Board May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Development 2.15.0

Development

Successfully merging this pull request may close these issues.

3 participants