v3-subgraph
v3-subgraph copied to clipboard
I can't get all the pools created in Uniswap V3
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:
- call the method
pools
setting these parameters:
pools(first: 1000, orderBy: createdAtTimestamp, orderDirection: asc) { id, createdAtBlockNumber, createdAtTimestamp }
- 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.
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
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"
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
@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.
How about ordering by id then, assuming it is unique and alphanumeric, so can be ordered and compared?
Hi @fedecastelli, were you able to solve this issue?