Below are the common methods to get the current liquidity reserves:

Getting the reserves data for a liquidity pool using SaucerSwapโ€™s REST API is also a suitable alternative. For more information, see Get liquidity pool reserves (V1). The pool metadata includes the reserve data.

To track updates to liquidity pool reserves in near real-time, see Track LP updates (V1).

Get Pool Reserves via REST API

Fetch all HTS token balances for a pool via Mirror Nodeโ€™s REST API.

Code Overview

Resources:

Typescript
const apiUrl = `/api/v1/accounts/${poolContractId}/tokens`;  
const response = await axios.get(`${mirrorNodeBaseUrl}${apiUrl}`);
const tokens = response.data.tokens;

for (const token of tokens ) {
  console.log(`Token id: ${token.token_id}, Reserve: ${token.balance}`);
}

Get Pool Reserves via JSON RPC

Fetch all HTS token balances for a pool using the getReserves() solidity function via Mirror Nodeโ€™s JSON RPC Relay.

Function name: getReserves

โ›ฝ No gas cost

function getReserves() external view returns (
  uint112 reserve0, 
  uint112 reserve1, 
  uint32 blockTimestampLast
);

Code Overview

Resources:

Typescript
import * as ethers from 'ethers'; //V6

//Set one of Hedera's JSON RPC Relay as the provider
const provider = new ethers.JsonRpcProvider(hederaJsonRelayUrl, '', {
  batchMaxCount: 1, //workaround for V6
});

//load abi data containing Pair's getReserves() function
const interfaces = new ethers.Interface(abi);

const poolContract = new ethers.Contract(poolAddress, interfaces.fragments, provider);
const result = await poolContract.getReserves();
const reserve0 = result.reserve0; //in token's smallest unit
const reserve1 = result.reserve1; //in token's smallest unit
const block = result.blockTimestampLast;