sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'PancakeLibrary: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'PancakeLibrary: ZERO_ADDRESS');
}
The addresses are being compared and assigned in the right order using the trinary operators ? and : at this line (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); This line says, if tokenA is less than tokenB, then (?) assign tokenA to token0 and tokenB to token1, else (:) assign tokenB to token0 and tokenA to token1. Addresses are really just numbers, and you can compare them mathematically. 0x00123... would be less than 0x0A026... additionally, the function ensures that the two addresses are not the same and that neither of them are the zero address.
Обсуждают сегодня