v3-subgraph icon indicating copy to clipboard operation
v3-subgraph copied to clipboard

I can't get all the pools created in Uniswap V3

Open fedecastelli opened this issue 3 years ago • 6 comments

I'm trying to get all the pools created in Uniswap V3 using the method pools(). Currently, the pools created are more than 1000 so I can't use the parameter first to get them all (the limit is 1000).

I decided to use this approach:

  1. call the method pools setting these parameters:

pools(first: 1000, orderBy: createdAtTimestamp, orderDirection: asc) { id, createdAtBlockNumber, createdAtTimestamp }

  1. if the returned list has 1000 items, I get the last element returned and I call the method pools again setting these parameters:

pools(first: 1000, orderBy: createdAtTimestamp, orderDirection: asc, where: {id_gt: "last_pool_address"}) { id, createdAtBlockNumber, createdAtTimestamp }

This step is a loop executed until the result has less than 1000 items.

Here is the error

The error here is I get the same pools twice, three times. Is there a way to get all the pools without having duplicates?

I could use the createdAtTimestamp_gt parameter inside the where clause but it may happen I'll exclude pools created at the same timestamp.

fedecastelli avatar Aug 25 '21 08:08 fedecastelli

Did you try to use first and skip first: 1000 => 1000 first items first: 1000 + skip: 1000 => 1001 to 2000 items and so on with the same orderBy you should be able to get all the pools

sydneyhenrard avatar Aug 28 '21 06:08 sydneyhenrard

I tried it and it worked only because there are less than 6000 pools in Uniswap V3.

If you try to use first and skip first: 1000, skip: 6000 => it throws an error saying "The "skip" argument must be between 0 and 5000, but is 6000"

fedecastelli avatar Aug 30 '21 09:08 fedecastelli

First query

{
  pools(first: 1000, orderBy: createdAtTimestamp, orderDirection: asc) 
  { id, createdAtBlockNumber, createdAtTimestamp }
}

Second query (use the where clause by providing the createdAtTimestamp from the last record of the previous query.

{
  pools(first: 1000, orderBy: createdAtTimestamp, orderDirection: asc
  where: {createdAtTimestamp_gt: 1621164209 }) 
  { id, createdAtBlockNumber, createdAtTimestamp }
}

Do that until you have no result

sydneyhenrard avatar Aug 30 '21 17:08 sydneyhenrard

@fedecastelli mentionned this solution already in his question, but you didn't answer his related question "I could use the createdAtTimestamp_gt parameter inside the where clause but it may happen I'll exclude pools created at the same timestamp.".

For timestamps I'm guessing its unlikely to have two pools with the same timestamp (unless the timestamp is extremely discrete, like block number for eg.). But when ordering by other attributes (say liquidity, volume, etc.) there is a chance to skip out one of the pools.

samlaf avatar Mar 30 '22 00:03 samlaf

How about ordering by id then, assuming it is unique and alphanumeric, so can be ordered and compared?

f-z avatar Apr 26 '22 23:04 f-z

Hi @fedecastelli, were you able to solve this issue?

egearikan avatar May 31 '23 16:05 egearikan