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

How to Retrieve a Specific Pool’s ETH Balance from the PoolManager in Uniswap V4? #935

Open
TangMonk opened this issue Feb 1, 2025 · 2 comments

Comments

@TangMonk
Copy link

TangMonk commented Feb 1, 2025

In Uniswap V2 and V3, you can simply call the pool’s balanceOf function to determine its balance. However, Uniswap V4 centralizes liquidity management through a PoolManager contract that aggregates funds from multiple pools. This design makes it challenging to pinpoint the ETH balance for a single pool.

For example, consider two pools:

	•	Pool A: Contains 1000 TokenA and 1 ETH
	•	Pool B: Contains 1000 TokenB and 1 ETH

Here, the PoolManager holds a combined total of 2 ETH. The key question is: how can we extract the ETH balance corresponding to either Pool A or Pool B using an approach analogous to balanceOf? Although the PoolManager provides a getLiquidity() function, it appears to return a combined value of amount0 and amount1, which does not directly reveal the individual ETH amounts.

Are there any available interfaces or methods that allow us to segregate the liquidity on a per-pool basis? Any insights or suggestions on how to achieve this separation would be greatly appreciated.

@saucepoint
Copy link
Collaborator

its not super easy to do onchain -- for a given pool, you need to iterate over each liquidity position (from an offchain indexer) and calculate the underlying token amounts

as an approximation (still wildy inaccurate), you can take a pool's liquidity StateLibrary.getLiquidity and assume that all liquidity is in the full-range. Then you can use LiquidityAmounts to extract the underlying token reserves

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

No branches or pull requests

2 participants