🔥Get Pools by Token Addresses

Fetch Pumpswap Pools based on a single Token Address or a Liquidity Pair

Pump AMM, the native decentralized exchange for Pump.fun tokens, utilizes liquidity pools to facilitate trading. Each pool is defined by a liquidity pair of token mint addresses. This pair is denoted by baseMint and quoteMint addresses on Pumpswap. We can add filters to these two fields, to retrieve specific pool details involving a particular liquidity pair. For instance we are trying to get liquidity pools involving USDC and SOL, so we filter baseMintand quoteMintfields using the _in filter.

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

Fetch Pool by Liquidity Pair (USDC-SOL)

async function getPoolDetailsByLiquidtyPair(mintAddressA, mintAddressB) {
  const SHYFT_API_KEY = "YOUR_SHYFT_API_KEY";
    //query to get pool details on PumpSwap by liquidity pair
  const operationsDoc = `
    query MyQuery {
      pump_fun_amm_Pool(where: {base_mint: {_in: ${JSON.stringify([
        mintAddressA,
        mintAddressB,
      ])}}, 
      quote_mint: {_in: ${JSON.stringify([
        mintAddressA,
        mintAddressB,
      ])}}}) 
          {
                base_mint
                creator
                index
                lp_mint
                lp_supply
                pool_base_token_account
                pool_bump
                pool_quote_token_account
                quote_mint
                pubkey
            }
        }
`; //you can cherrypick the fields as per your requirement

  const result = await fetch(
    `https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`, //SHYFT's GQL endpoint
    {
      method: "POST",
      body: JSON.stringify({
        query: operationsDoc,
        variables: {},
        operationName: "MyQuery",
      }),
    }
  );

  const { errors, data } = await result.json();

  console.dir(data, { depth: null });
}

getPoolDetailsByLiquidtyPair("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","So11111111111111111111111111111111111111112");
//getting USDC_SOL pairs, you can get other tokens by just changing the address

We can also query liquidity pool involving a particular token address, for that we would have to filter the baseMint or quoteMint field using the _in filter.

Fetch Pools involving a Token (USDC)

async function getPoolsForAToken(mintAddress) {
  const SHYFT_API_KEY = "YOUR_SHYFT_API_KEY";
  //query to get pool details on PumpSwap involving one token
  const operationsDoc = `
		query MyQuery {
            pump_fun_amm_Pool(where: {_or: [{_or: {base_mint: {_eq: ${JSON.stringify(
              mintAddress
            )}}}},{_or: {quote_mint: {_eq: ${JSON.stringify(
    mintAddress
  )}}}}]}) {
                base_mint
                creator
                index
                lp_mint
                lp_supply
                pool_base_token_account
                pool_bump
                pool_quote_token_account
                quote_mint
                pubkey
            }
        }
		`; //you can cherrypick the fields as per your requirement

  const result = await fetch(
    `https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`, //SHYFT's GQL endpoint
    {
      method: "POST",
      body: JSON.stringify({
        query: operationsDoc,
        variables: {},
        operationName: "MyQuery",
      }),
    }
  );

  const { errors, data } = await result.json();

  console.dir(data, { depth: null });
}

getPoolsForAToken("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
//for getting all pools involving USDC

Last updated

Was this helpful?