22 lines
707 B
JavaScript
22 lines
707 B
JavaScript
import { useReadContract } from "wagmi";
|
|
|
|
import { abi as UniswapV2Factory } from "../../abi/UniswapV2Factory.json";
|
|
import { UNISWAP_V2_FACTORY } from "../../constants/addresses";
|
|
|
|
export const useUniswapV2Pair = (chainId, factoryAddress, token0, token1) => {
|
|
const t0 = token0 > token1 ? token0 : token1;
|
|
const t1 = token0 > token1 ? token1 : token0;
|
|
const { data, refetch } = useReadContract({
|
|
abi: UniswapV2Factory,
|
|
address: factoryAddress,
|
|
functionName: "getPair",
|
|
args: [token0, token1],
|
|
scopeKey: `getPair-${t0}-${t1}-${chainId}`,
|
|
chainId: chainId,
|
|
});
|
|
|
|
const pairAddress = data ? data : "";
|
|
|
|
return { pairAddress, refetch };
|
|
}
|