Get Reserve Details

Fetch a lending reserve to know about the asset being borrowed or deposited.

Along with lending and borrowing, you can also get all the details of a reservesuch as liquidity, token vault, supply details, token mint by querying the kamino_lending_Reserve account.

'liquidity.mintPubkey' field in the response is the asset being borrowed or deposited.

You can directly copy paste this code on replit and see it in action.

async function fetchReserve(ownerAddress: string) {
  //get Reserve details using graphQl
  const operationsDoc = `
      query MyQuery {
        kamino_lending_Reserve(
          where: {pubkey: {_eq: ${JSON.stringify(ownerAddress)}}}
        ) {
          version
          pubkey
          liquidity
          lendingMarket
          lastUpdate
          farmDebt
          farmCollateral
          config
          collateral
        }
      }
    `; //graphQl query
  const result = await fetch(
    `https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`,
    {
      method: "POST",
      body: JSON.stringify({
        query: operationsDoc,
        variables: {},
        operationName: "MyQuery",
      }),
    }
  );

  return await result.json();
}

async function getData(address: string) {
  const { errors, data } = await fetchReserve(address);
  
  if (errors) {
    console.error(errors);
  }
  
  console.log(JSON.stringify(data)); //can process this json data received
}

getData("d4A2prbA2whesmvHaL88BH6Ewn5N4bTSU2Ze8P6Bc4Q"); //Sol reserve pubkey

The liquidity field returned in the response contains all the liquidity details of the asset in the reserve.

  • mintPubkey : the mint address of the asset in the reserve.

  • supplyVault : Whenever users add their assets to liquidity pool, they are usually contributing to an account called the supply vault. This field contains the supply vault address for that particular reserve.

  • feeVault : Fee Vault contains the fees generated by the trading activities. This field denotes the address of the fee vault for that particular reserve.

  • mintDecimals : Decimals for the liquidity or token associated with the reserve.

  • availableAmount : Amount of liquidity available in the reserve.

  • borrowedAmountSf : Amount of liquidity borrowed from the reserve.

Last updated