Commit a4a954c8 authored by Jordan Frankfurt's avatar Jordan Frankfurt Committed by GitHub

fix: update subgraph query to actually fetch all tick data (#5982)

parent 82dcdcec
...@@ -83,7 +83,8 @@ export enum Chain { ...@@ -83,7 +83,8 @@ export enum Chain {
Ethereum = 'ETHEREUM', Ethereum = 'ETHEREUM',
EthereumGoerli = 'ETHEREUM_GOERLI', EthereumGoerli = 'ETHEREUM_GOERLI',
Optimism = 'OPTIMISM', Optimism = 'OPTIMISM',
Polygon = 'POLYGON' Polygon = 'POLYGON',
UnknownChain = 'UNKNOWN_CHAIN'
} }
export type ContractInput = { export type ContractInput = {
...@@ -632,9 +633,12 @@ export type QueryNftBalancesArgs = { ...@@ -632,9 +633,12 @@ export type QueryNftBalancesArgs = {
after?: InputMaybe<Scalars['String']>; after?: InputMaybe<Scalars['String']>;
before?: InputMaybe<Scalars['String']>; before?: InputMaybe<Scalars['String']>;
chain?: InputMaybe<Chain>; chain?: InputMaybe<Chain>;
cursor?: InputMaybe<Scalars['String']>;
datasource?: InputMaybe<DatasourceProvider>;
filter?: InputMaybe<NftBalancesFilterInput>; filter?: InputMaybe<NftBalancesFilterInput>;
first?: InputMaybe<Scalars['Int']>; first?: InputMaybe<Scalars['Int']>;
last?: InputMaybe<Scalars['Int']>; last?: InputMaybe<Scalars['Int']>;
limit?: InputMaybe<Scalars['Int']>;
ownerAddress: Scalars['String']; ownerAddress: Scalars['String'];
}; };
......
...@@ -24,7 +24,7 @@ export default function useAllV3TicksQuery(poolAddress: string | undefined, skip ...@@ -24,7 +24,7 @@ export default function useAllV3TicksQuery(poolAddress: string | undefined, skip
data, data,
loading: isLoading, loading: isLoading,
error, error,
} = useQuery(query, { } = useQuery<Record<'ticks', Ticks>>(query, {
variables: { variables: {
poolAddress: poolAddress?.toLowerCase(), poolAddress: poolAddress?.toLowerCase(),
skip, skip,
......
...@@ -3,7 +3,7 @@ import { FeeAmount, nearestUsableTick, Pool, TICK_SPACINGS, tickToPrice } from ' ...@@ -3,7 +3,7 @@ import { FeeAmount, nearestUsableTick, Pool, TICK_SPACINGS, tickToPrice } from '
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from 'constants/chains' import { SupportedChainId } from 'constants/chains'
import { ZERO_ADDRESS } from 'constants/misc' import { ZERO_ADDRESS } from 'constants/misc'
import useAllV3TicksQuery, { TickData } from 'graphql/thegraph/AllV3TicksQuery' import useAllV3TicksQuery, { TickData, Ticks } from 'graphql/thegraph/AllV3TicksQuery'
import JSBI from 'jsbi' import JSBI from 'jsbi'
import { useSingleContractMultipleData } from 'lib/hooks/multicall' import { useSingleContractMultipleData } from 'lib/hooks/multicall'
import ms from 'ms.macro' import ms from 'ms.macro'
...@@ -140,7 +140,8 @@ function useTicksFromTickLens( ...@@ -140,7 +140,8 @@ function useTicksFromTickLens(
function useTicksFromSubgraph( function useTicksFromSubgraph(
currencyA: Currency | undefined, currencyA: Currency | undefined,
currencyB: Currency | undefined, currencyB: Currency | undefined,
feeAmount: FeeAmount | undefined feeAmount: FeeAmount | undefined,
skip = 0
) { ) {
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
const poolAddress = const poolAddress =
...@@ -154,9 +155,10 @@ function useTicksFromSubgraph( ...@@ -154,9 +155,10 @@ function useTicksFromSubgraph(
) )
: undefined : undefined
return useAllV3TicksQuery(poolAddress, 0, ms`30s`) return useAllV3TicksQuery(poolAddress, skip, ms`30s`)
} }
const MAX_THE_GRAPH_TICK_FETCH_VALUE = 1000
// Fetches all ticks for a given pool // Fetches all ticks for a given pool
function useAllV3Ticks( function useAllV3Ticks(
currencyA: Currency | undefined, currencyA: Currency | undefined,
...@@ -170,12 +172,31 @@ function useAllV3Ticks( ...@@ -170,12 +172,31 @@ function useAllV3Ticks(
const useSubgraph = currencyA ? !CHAIN_IDS_MISSING_SUBGRAPH_DATA.includes(currencyA.chainId) : true const useSubgraph = currencyA ? !CHAIN_IDS_MISSING_SUBGRAPH_DATA.includes(currencyA.chainId) : true
const tickLensTickData = useTicksFromTickLens(!useSubgraph ? currencyA : undefined, currencyB, feeAmount) const tickLensTickData = useTicksFromTickLens(!useSubgraph ? currencyA : undefined, currencyB, feeAmount)
const subgraphTickData = useTicksFromSubgraph(useSubgraph ? currencyA : undefined, currencyB, feeAmount)
const [skipNumber, setSkipNumber] = useState(0)
const [subgraphTickData, setSubgraphTickData] = useState<Ticks>([])
const { data, error, isLoading } = useTicksFromSubgraph(
useSubgraph ? currencyA : undefined,
currencyB,
feeAmount,
skipNumber
)
useEffect(() => {
if (data?.ticks.length) {
setSubgraphTickData((tickData) => [...tickData, ...data.ticks])
if (data.ticks.length === MAX_THE_GRAPH_TICK_FETCH_VALUE) {
setSkipNumber((skipNumber) => skipNumber + MAX_THE_GRAPH_TICK_FETCH_VALUE)
}
}
}, [data?.ticks])
return { return {
isLoading: useSubgraph ? subgraphTickData.isLoading : tickLensTickData.isLoading, isLoading: useSubgraph
error: useSubgraph ? subgraphTickData.error : tickLensTickData.isError, ? isLoading || data?.ticks.length === MAX_THE_GRAPH_TICK_FETCH_VALUE
ticks: useSubgraph ? subgraphTickData.data?.ticks : tickLensTickData.tickData, : tickLensTickData.isLoading,
error: useSubgraph ? error : tickLensTickData.isError,
ticks: useSubgraph ? subgraphTickData : tickLensTickData.tickData,
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment