1

I am reading this smart contract. In that smart contract, they are comparing two addresses.

(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);

What is the meaning of comparing two address. On what basis it will return true of false.

1
  • 1
    It has the exact same semantics as comparing integers. – hrkrshnn Feb 18 at 11:19
1

This line of code ensures that the passed tokens are sorted deterministically (e.g. token with lower address first), so that the pair address can be retrieved in a single lookup:

(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
    require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS');
    require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient

Hence the comment in the last line:

single check is sufficient

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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