web3jssolana-web3js

How do I use Javascript to check if the LP tokens of a solana liquidity pool is locked and burnt?


I have the mint addresses of two tokens on solana and their pair address. Using javascript, I want to know if the liquidity of the pool is locked and burnt. Thanks

This is what I've tried:

  const info = await connection.getAccountInfo(
    new PublicKey(pooladdress)
  );
  if (!info) return;

  const poolState = LIQUIDITY_STATE_LAYOUT_V4.decode(info.data);
  console.log("poolState=============", poolState);
};

const SOL_USDC_POOL_ID = "58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2";

getPoolInfo(SOL_USDC_POOL_ID);

I would appreciate pointers in the right direction.


Solution

  • Something like this:

    Get the LP mints and reserve of the pool:

    const acc = await connection.getMultipleAccountsInfo([new 
    PublicKey("pool address")])
    const parsed = acc.map((v) => LIQUIDITY_STATE_LAYOUT_V4.decode(v.data))
    
    const lpMint = parsed[0].lpMint
    const lpReserve = parsed[0].lpReserve
    

    Get the mint info:

    const accInfo = await connection.getParsedAccountInfo(new solana.PublicKey(lpMint));
    const mintInfo = accInfo?.value?.data?.parsed?.info
    

    Calculate:

    const lpReserve = lpReserve / Math.pow(10, mintInfo?.decimals)
    const actualSupply = mintInfo?.supply / Math.pow(10, mintInfo?.decimals)
    console.log(`lpMint: ${lpMint}, Reserve: ${lpReserve}, Actual Supply: ${actualSupply}`);
    
    //Calculate burn percentage
    const maxLpSupply = Math.max(actualSupply, (lpReserve - 1));
    const burnAmt = (lpReserve - actualSupply)
    console.log(`burn amt: ${burnAmt}`)
    const burnPct = (burnAmt / lpReserve) * 100;
    console.log(`${burnPct} LP burned`);