◆ Purpose

tokenA, B is address. This means address is hex decimal so, you can compare the two numbers

◆ Input & Return value

(address tokenA, address tokenB) ⇒ (address token0, address token1)

address is hex decimal.

this means that address is a list of numbers.

◆ Example

tokenA(WETH) = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 (hex)

1097077688018008265106216665536940668749033598146(decimal)

tokenB(USDC) = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 (hex)

917551056842671309452305380979543736893630245704(decimal)


(1097077688018008265106216665536940668749033598146) > (917551056842671309452305380979543736893630245704)


token0(USDC) = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48

token1(WETH) = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

◆ Code and Explain

function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
        require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
				// token0 is smaller one.
				// (A) ? (B) :(C); == if(A) {B} else {C}
        (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
    }

◆ Link