Get percentage of liquidity burnt/locked for a given pool.
The best way to check if a token is trying to rug your or not is to see how much liquidity is locked inside the token's pool. Whenever liquidity is added to a pool on Raydium, lpMint tokens are minted to the liquidity provider.
If anyone wants to remove the liquidity, they need the orginal minted lpMint tokens. If those lpMint tokens are burnt, then it means the liquidity is locked inside the pool and cannot be withdrawn. We can see how easy it is to fetch this info with GraphQL APIs and RPC calls.
import { gql, GraphQLClient } from"graphql-request";import*as solana from'@solana/web3.js';constgqlEndpoint=`https://programs.shyft.to/v0/graphql/?api_key=YOUR-KEY`;constrpcEndpoint=`https://rpc.shyft.to/?api_key=YOUR-KEY`constgraphQLClient=newGraphQLClient(gqlEndpoint, { method:`POST`, jsonSerializer: { parse:JSON.parse, stringify:JSON.stringify, },});constconnection=newsolana.Connection(rpcEndpoint);asyncfunctionqueryLpMintInfo(address:string) {// See how we are only querying what we needconstquery=gql` query MyQuery ($where: Raydium_LiquidityPoolv4_bool_exp) { Raydium_LiquidityPoolv4( where: $where ) { baseMint lpMint lpReserve }}`;constvariables= { where: { pubkey: { _eq: address, }, }, };returnawaitgraphQLClient.request(query, variables);}/*This is taken from Raydium's FE codehttps://github.com/raydium-io/raydium-frontend/blob/572e4973656e899d04e30bfad1f528efbf79f975/src/pages/liquidity/add.tsx#L646*/functiongetBurnPercentage(lpReserve:number, actualSupply:number):number {constmaxLpSupply=Math.max(actualSupply, (lpReserve -1));constburnAmt= (maxLpSupply - actualSupply)console.log(`burn amt: ${burnAmt}`)return (burnAmt / maxLpSupply) *100;}//This is Jup-Sol pool addresconstinfo=awaitqueryLpMintInfo("7RJ5qmsgmvUKK5QtCLT9qHpQMegkiULppHRBNuWso12E");constlpMint=info.Raydium_LiquidityPoolv4[0].lpMint//Once we have the lpMint address, we need to fetch the current token supply and decimalsconstparsedAccInfo=awaitconnection.getParsedAccountInfo(newsolana.PublicKey(lpMint));constmintInfo=parsedAccInfo?.value?.data?.parsed?.info//We divide the values based on the mint decimalsconstlpReserve=info.Raydium_LiquidityPoolv4[0].lpReserve /Math.pow(10,mintInfo?.decimals)constactualSupply=mintInfo?.supply /Math.pow(10,mintInfo?.decimals)console.log(`lpMint: ${lpMint}, Reserve: ${lpReserve}, Actual Supply: ${actualSupply}`);//Calculate burn percentageconstburnPct=getBurnPercentage(lpReserve, actualSupply)console.log(`${burnPct} LP burned`);
In order to find LP burned for a token, instead of fetching by pool's pubkey you can fetch pools by baseMint, and then follow the above outlined approach.