In Uniswap V2, we can use SYNC event to monitor the reserve changes in a pool for token0
and token1
. How can we do the same with Uniswap V3? If it can't be done through any event, what function can I call to check the reserve based on certain pool?
2 Answers
You can directly use the erc20 balanceOf function to get the reserves from a particular pool. For example,
address pairAddress = "PAIR ADDRESS OF TOKEN0 AND TOKEN1";
uint256 reserve0 = IERC20(token0).balanceOf(pairAddress);
uint256 reserve1 = IERC20(token1).balanceOf(pairAddress);
All available functions of uniswap v3 pool is here: https://github.com/Uniswap/uniswap-v3-core/blob/main/contracts/UniswapV3Pool.sol
function balance0() private view returns (uint256);
function balance1() private view returns (uint256);
every pool has these functions which return pool reserves.
-
-
function balance0() private view returns (uint256); function balance1() private view returns (uint256); Nov 2, 2021 at 11:50
-
Both of those functions are private meaning they cannot be called from outside of the smart contract they are defined within. Also, they use the ERC20 balanceOf method to obtain the balances which you can do yourself. Oct 16, 2022 at 10:48