The most obvious way to get the address for a pair is to call getPair on the factory. If the pair exists, this function will return its address, else address(0)
(0x0000000000000000000000000000000000000000
).
Thanks to some fancy footwork in the factory, we can also compute pair addresses without any on-chain lookups because of CREATE2. The following values are required for this technique:
address | The factory address |
salt | keccak256(abi.encodePacked(token0, token1)) |
keccak256(init_code) | 0x3a1b8c90f0ece2019085f38a482fb7538bb84471f01b56464ac88dd6bece344e |
token0
must be strictly less than token1
by sort order.keccak256
.address factory = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;address pair = address(uint(keccak256(abi.encodePacked(hex'ff',factory,keccak256(abi.encodePacked(wusd, item)),hex'3a1b8c90f0ece2019085f38a482fb7538bb84471f01b56464ac88dd6bece344e'))));