2

I am just wondering why Uniswap use reserve and getReserves() instead of just using tokenA.balanceOf(this) and tokenB.balanceOf(this)?

Is there any reason that I do not see, like flash loans or so? (Because it is possible to call .sync() anyway... so I do not realy understand why they use this strange implementation)

Maybe someone can help me there... Thank you :)

To make it more clear:

Why Uniswap use this method:

function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) {
        _reserve0 = reserve0;
        _reserve1 = reserve1;
        _blockTimestampLast = blockTimestampLast;
    }

And not something like:

function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) {
            _reserve0 = token0.balanceOf(this);
            _reserve1 = token1.balanceOf(this);
            _blockTimestampLast = blockTimestampLast;
        }
3
  • doesnt reserves refer to the LP pools not the token?
    – johnny 5
    Dec 27, 2021 at 22:35
  • @johnny5 yes this are attributes/methodes of the UniswapV2Pair contract. But it does not matter... I will edit the post to make it more clear what I mean.
    – MaTok
    Dec 27, 2021 at 23:09
  • 1. The later requires more gas.
    – johnny 5
    Dec 27, 2021 at 23:16

0

Your Answer

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

Browse other questions tagged or ask your own question.