0

I'd like to be able to check if an arbitrary address is a Uniswap liquidity pool pair address. I know I can compute the LP with CREATE2 but what if I don't know the tokens, I just have an address and want to know if it's a Uniswap LP. Will something like this work:

IUniswapV2Pair pair = IUniswapV2Pair(0x000...some address....0000);
uint256 price=pair.price0CumulativeLast();
if (price>0) { this is a real LP... }

Or is there a Uniswap function specifically for this purpose?

1 Answer 1

1

Actually, you can try to call any function of possible pair contract

contract PairChecker {
    function _tryPairTokens(address token, address possiblyPair)
        public
        view
        returns (bool isPair)
    {
        address token0 = IUniswapV2Pair(possiblyPair).token0();
        address token1 = IUniswapV2Pair(possiblyPair).token1();
        return token0 == token || token1 == token;
    }

    function _checkPair(address token, address possiblyPair)
        internal
        view
        returns (bool isPair)
    {
        try this._tryPairTokens(token, possiblyPair) returns (bool value) {
            if (token == address(0)) return true;
            return value;
        } catch {
            return false;
        }
    }
}

Just call _tryPairTokens(token, possiblePair) to figure out if address is pair of your token or not. Same stuff you can do without having a token

Your Answer

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

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