2

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 2

2

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);
-1

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.

3
  • Do you know which function I should use? 😄 Jul 21, 2021 at 4:55
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.