Get Pool by Token Addresses

Fetch all liquidity pools involving specific tokens for Meteora DLMM

Liquidity Pools are smart contract based vaults that are associated with specific liquidity token pairs. With SHYFT's GraphQL APIs, we can query Liquidity Pools based on the tokens associated with them for Meteora DLMM. The liquidity pairs are denoted by the following fields: tokenXMint and tokenYMint.

You can directly copy paste the following on replit and see it in action.

Fetch Pool for a Liquidity Pair (SOL-USDC)

async function getLBPairByTokenPair(tokenAddressX, tokenAddressY) {
  const SHYFT_API_KEY = "YOUR_SHYFT_API_KEY";
  //get Pools involving a specific liquidity pair
  const operationsDoc = `
	query MyQuery {
		meteora_dlmm_LbPair(
		where: {tokenXMint: {_in: ${JSON.stringify([tokenAddressX, tokenAddressY])}}, tokenYMint: {_in: ${JSON.stringify([tokenAddressX, tokenAddressY])}}}
		) {
			activationPoint
                        activationType
                        activeId
                        baseKey
                        binStep
                        creator
                        creatorPoolOnOffControl
                        lastUpdatedAt
                        oracle
                        padding4
                        pairType
                        parameters
                        preActivationDuration
                        preActivationSwapAddress
                        protocolFee
                        requireBaseFactorSeed
                        reserveX
                        reserveY
                        status
                        tokenMintXProgramFlag
                        tokenMintYProgramFlag
                        tokenXMint
                        tokenYMint
		}
	}
`; //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 });
}
getLBPairByTokenPair("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "So11111111111111111111111111111111111111112");
//fetching Pools for SOL-USDC pair

Fetch Pool for a particular Token (USDC)

async function getLBPairBySingleToken(tokenAddress) {
  const SHYFT_API_KEY = "YOUR_SHYFT_API_KEY";
  //get all Lb Pairs for meteora DLMM
  const operationsDoc = `
	query MyQuery {
		meteora_dlmm_LbPair(
		where: {_or: [{_or: {tokenXMint: {_eq: ${JSON.stringify(
        tokenAddress
      )}}}}, {_or: {tokenYMint: {_eq: ${JSON.stringify(tokenAddress)}}}}]}
			) {
			oracle
			pairType
			reserveX
			reserveY
			status
			tokenXMint
			tokenYMint
			lastUpdatedAt
			}
		}
	`; //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 });
}
getLBPairBySingleToken("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
//getting pools involving USDC token

Please note that the above query fetches all pools involving USDC as tokenXMint as well as tokenYMint in a single GraphQL request.

Last updated

Was this helpful?