0

I am trying to get a list of all pools containing a token symbol with Uniswap v3 for arbitrage opportunities. For example, if I want to find all pools containing "WETH".

Using the subgraph,

{
    tokens(first: 10, where:{symbol:"WETH"}){
    id
    name
    symbol
  }
}

Returns:

{
  "data": {
    "tokens": [
      {
        "id": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
        "name": "Wrapped Ether",
        "symbol": "WETH"
      }
    ]
  }
}

Once I have a selected pool, I then will have token0 and token1 to use later in factory.getPool().

Now to find the pools that contain WETH, I use the graph to check if token0 OR token1 contains the WETH ID, 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.

// search token0
{
    pools(first:10, where: {
    token0:"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",            
}){
    token0{
      name
      symbol
      id
    }
    token1{
      name
      symbol
      id
    }
    }
}


// search token1
{
    pools(first:10, where: {
    token1:"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",            
}){
    token0{
      name
      symbol
      id
    }
    token1{
      name
      symbol
      id
    }
    }
}

Now I have a list of all pools that that contain "WETH" and the pool ID's to use in factory to perform swaps.

So, what I would like to know is if there is a much simpler way of doing this please!?

ElHaix
  • 12,846
  • 27
  • 115
  • 203

1 Answers1

1

I think you could use the "whitelistPools" property available in the Token query object.

Here is an example, tested on Uniswap v3 explorer and it works:

{
  token(id:"0x6b175474e89094c44da98b954eedeac495271d0f") {
    symbol,
    name,
    whitelistPools (orderBy: liquidity, orderDirection: desc) {
      id,
      token0 { id, symbol, decimals},
      token1 { id, symbol, decimals },
      liquidity,
      feeTier
    }
  }
}

In the example above I just passed in the DAI token address and I got a list of pools containing the given token. You can also know where our given token is a "token0" or "token1" (actually token0 is just the one with a smaller address hex value).

From the resulting list, you get a list of pools that you can easily filter from your code.

DharmanBot
  • 1,066
  • 2
  • 6
  • 10