Get Pool by Address
Fetch an Orca pool by pubkey.
We can apply filters on any field of a Orca account. If we want to fetch a pool by its address (public key), then we need to apply where filter on its pubKey.
You can directly copy paste this code on replit and see it in action.
Fetch parsed pool info
import { Connection, PublicKey } from "@solana/web3.js";
import { gql, GraphQLClient } from "graphql-request";
const SHYFT_API_KEY = 'YOUR-KEY';
const graphQLEndpoint = `https://programs.shyft.to/v0/graphql/?api_key=${SHYFT_API_KEY}`;
const graphQLClient = new GraphQLClient(graphQLEndpoint, {
method: `POST`,
jsonSerializer: {
parse: JSON.parse,
stringify: JSON.stringify,
},
});
async function queryOrcaPool(address:string) {
// We only fetch fields necessary for us
const query = gql`
query MyQuery {
ORCA_WHIRLPOOLS_whirlpool(
where: {pubkey: {_eq: ${JSON.stringify(address)}}}
) {
feeGrowthGlobalA
feeGrowthGlobalB
feeRate
liquidity
protocolFeeOwedA
protocolFeeOwedB
protocolFeeRate
rewardLastUpdatedTimestamp
sqrtPrice
tickCurrentIndex
tickSpacing
tokenMintA
tokenMintB
tokenVaultA
tokenVaultB
whirlpoolsConfig
rewardInfos
tickSpacingSeed
whirlpoolBump
pubkey
}
}`;
return await graphQLClient.request(query);
}
//This is WEN-USDC pool addres
const poolInfo = await queryOrcaPool('5y2jFFA3A8GNjRnVMg8LfTHbBg7y2vivopiK8LmGRP2B');
console.log(poolInfo)
Once you have the pool info, you need to make sense of the data as well. For example, how much liquidity is present in the pool. You can do it by following this case study.
Get Liquidity Details of a PoolLast updated
Was this helpful?