Get Pool by Token Address

Get pool details from Orca for a token address.

Orca Whirlpool allows users to provide liquidity for token pairs. We can get all pool addresses involving a particular token, by filtering the tokenMintA and tokenMintB fields using GraphQl.

You can directly copy paste this code on replit and see it in action.

Fetch pools with Jito token

import { gql, GraphQLClient } from 'graphql-request';

const endpoint = `https://programs.shyft.to/v0/graphql?api_key=YOUR-API-KEY`; //Shyft's gQl endpoint

const graphQLClient = new GraphQLClient(endpoint, {
  method: `POST`,
  jsonSerializer: {
    parse: JSON.parse,
    stringify: JSON.stringify,
  },
}); //Initialize gQL Client

async function getWhirlpoolsforToken(tokenAddress) {
    //you can cherry pick fields as per your requirements
    const query = gql`
    query MyQuery {
      ORCA_WHIRLPOOLS_whirlpool(
        where: {liquidity: {_gt: "0"}, tokenMintB: {_eq: ${JSON.stringify(tokenAddress)}}}
      ) {
        tokenMintA
        tokenMintB
        rewardInfos
        tickCurrentIndex
        liquidity
        whirlpoolsConfig
        pubkey
      }
    }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
}
getWhirlpoolsforToken('J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn');
//replace this with token address for which you want to get Pools

Please note that, the filter liquidity {_gt: "0"} is optional and has been added to get Whirlpools which have a liquidity greater than 0.

Fetch Token Pairs SOL-USDC

You can also fetch a particular token pair, for example SOL-USDC. Here you need to apply where filter on both tokenA and tokenB.


import { gql, GraphQLClient } from 'graphql-request';

const endpoint = `https://programs.shyft.to/v0/graphql?api_key=PjnsMufcmuJVt3E9`; //Shyft's gQl endpoint

const graphQLClient = new GraphQLClient(endpoint, {
  method: `POST`,
  jsonSerializer: {
    parse: JSON.parse,
    stringify: JSON.stringify,
  },
}); //Initialize gQL Client

async function getWhirlpoolsforToken(tokenA, tokenB) {
    //you can cherry pick fields as per your requirements
    const query = gql`
    query MyQuery {
      ORCA_WHIRLPOOLS_whirlpool(
        where: {tokenMintA: {_eq: ${JSON.stringify(tokenA)}}, tokenMintB: {_eq: ${JSON.stringify(tokenB)}}}
      ) {
        tokenMintA
        tokenMintB
        rewardInfos
        tickCurrentIndex
        liquidity
        whirlpoolsConfig
        pubkey
      }
    }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
}

await getWhirlpoolsforToken('So11111111111111111111111111111111111111112', 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');

Last updated