I'm creating a token which when sold on a liquidity pool, takes fees and burns a certain amount.
Given that I have a recipient address, how would I check whether it is a liquidity pool?
I think I may be able to use this: https://docs.uniswap.org/protocol/V2/reference/smart-contracts/pair-erc-20 however I'm not sure which function would work or if there's another way.
You can test the address against the Uniswap Pair (V2) or Uniswap Pool (V3) interface, whether it returns expected values.
One step further, you can pass these returned values back to the Uniswap Factory contract (address can be found in V2 docs and V3 docs), which tells you a pool address based on the input values. This way you can be certain that the queried address is in fact a Uniswap Pool, and not just some other contract returning values from same-named functions.
I also added a condition checking if the target address is a contract:
if (target.code.length == 0)
. And if it is an end user address, it performs an early return.Note that this snippet works only on networks where Uniswap is deployed (e.g. your local fork of the mainnet, or some of the testnets). On other networks (such as the Remix VM emulator), the Uniswap contracts are unreachable, which results in revert of the call.