Fetching All Pairs

Every AgoraStableSwapFactory keeps an on-chain registry of every pair it deploys.

If you want to run this example, be sure that you have followed the steps here to configure your Wallet Client.

The convenient view function getAllPairData() returns:

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

Pick a factory address

1// AgoraStableSwapFactory contract on Sepolia
2const TESTNET_FACTORY = '0x8468587Af422ad440F58a57E955eCA6A970b5375';

Helper function to get all pairs

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}

Example use of the helper function

1(async () => {
2 const allPairData = await getAllPairData(TESTNET_FACTORY);
3 console.log(allPairData);
4})();

Returned Data

1[
2 {
3 pairAddress: '0x1Aa8958Aa34cEC8096EF4381cb335effe977b0ae',
4 token0: {
5 tokenAddress: '0x7BEb5D9DB0d85cBEa543C04f0dE8c23c2176cd9D',
6 name: 'ConstantToken',
7 symbol: 'CTK',
8 decimals: 18n
9 },
10 token1: {
11 tokenAddress: '0xa9012a055bd4e0eDfF8Ce09f960291C09D5322dC',
12 name: 'AUSD',
13 symbol: 'AUSD',
14 decimals: 6n
15 }
16 }
17]