Fetching Pair Reserves

Fetching live reserves is useful for knowing the liquidity on each side of the pair before you trade. The snippet below re-uses the wallet client you created in Quick Start, so no extra setup is needed.

  • If you are following our example using Avalanche Fuji, you can use the Address 0x237591AaF2FCCb34464Ceae9EeA1eb6f375843AF .
  • If you are trying to swap in a mainnet chain, you can check out Find all available Pairs

1. Pick a pair address

1// AUSD / CTK pair on Avalanche Fuji Testnet
2const TESTNET_PAIR_AUSD_CTK = '0x237591AaF2FCCb34464Ceae9EeA1eb6f375843AF';

In order to query the reserves from the contract, we’ll call the methods reserve0 and reserve1

2. Helper to read raw reserves

1/**
2 * Returns the raw on-chain reserves (no decimal conversion).
3 */
4async function getPairReserves(
5 pair: `0x${string}`,
6): Promise<{ reserve0: bigint; reserve1: bigint }> {
7 const reserve0 = await client.readContract({
8 address: pair,
9 abi: stableSwapAbi,
10 functionName: "reserve0",
11 });
12
13 const reserve1 = await client.readContract({
14 address: pair,
15 abi: stableSwapAbi,
16 functionName: "reserve1",
17 });
18
19 return { reserve0, reserve1 };
20}

3. Run the query

1(async () => {
2 const { reserve0, reserve1 } = await getPairReserves(TESTNET_PAIR_AUSD_CTK);
3
4 console.log(`Reserves token0 (AUSD – 6 dec):`, reserve0);
5 console.log(`Reserves token1 (CTK – 18 dec):`, reserve1);
6})();
1Reserves token0 (AUSD – 6 dec): 1000000000000n
2Reserves token1 (CTK – 18 dec): 1000000000000000000000000n

This is the value stored by the contract. In order to convert these units to human readable values, we’ll need to divide the output by the ERC20 token decimals.