Fetching All Pairs

Every AgoraStableSwapFactory keeps an on-chain registry of every pair it deploys. This guide shows how to query all available pairs using the wallet client created earlier.

The convenient view function getAllPairData() returns:

FieldDescription
pairAddressProxy address of the pair contract
token0 / token1Structs containing address, name, symbol, and decimals

1. Pick a factory address

1// AgoraStableSwapFactory contract on Avalanche Fuji Testnet
2const TESTNET_FACTORY = '0x237591AaF2FCCb34464Ceae9EeA1eb6f375843AF';

2. Helper to read the purchase fees

1/**
2 * Returns an array of pair data for every pool created by the factory.
3 */
4async function getAllPairData(factory: `0x${string}`) {
5 return await client.readContract({
6 address: factory,
7 abi: stableSwapFactoryAbi,
8 functionName: "getAllPairData",
9 });
10}

3. Run the query

1(async () => {
2 const allPairData = await getAllPairData(TESTNET_FACTORY);
3 console.log(allPairData);
4})();
1[
2 {
3 pairAddress: '0x237591AaF2FCCb34464Ceae9EeA1eb6f375843AF',
4 token0: {
5 tokenAddress: '0xa9012a055bd4e0eDfF8Ce09f960291C09D5322dC',
6 name: 'AUSD',
7 symbol: 'AUSD',
8 decimals: 6n
9 },
10 token1: {
11 tokenAddress: '0xb8d4F619B3a482349DF31c33e75E28C93Eb92527',
12 name: 'ConstantToken',
13 symbol: 'CTK',
14 decimals: 18n
15 }
16 }
17]