Fetch Fluxbeam Pool based on a single Token Address or a Liquidity Pair
Liquidity pools rely on liquidity token pairs. These pairs are the two tokens that users contribute in equal value to the pool. In Fluxbeam, the liquidity pairs denoted by the mintA and mintB fields.
For instance we are trying to get liquidity pools involving USDC and SOL, so we filter mintA and mintB fields 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)
asyncfunctiongetPoolByPair(mintAddressA,mintAddressB) {constSHYFT_API_KEY="YOUR_SHYFT_API_KEY";//get a fluxbeam Pool details using a liquidity pool pairconstoperationsDoc=` query MyQuery { Fluxbeam_TokenSwap( where: {mintA: {_in: ${JSON.stringify([mintAddressA,mintAddressB])}}, mintB: {_in: ${JSON.stringify([mintAddressA,mintAddressB])}}}
) { tokenPool mintB mintA pubkey curveType } } `; //graphQl queryconstresult=awaitfetch( `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 } =awaitresult.json();console.dir(data, { depth:null });}getPoolByPair("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","So11111111111111111111111111111111111111112")//for getting the SOL-USDC pool, however you can enter your own liquidity pool pair as well