Find all available pairs for a chain
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 convenience view function getAllPairData() returns:
| Field | Description |
|---|---|
pairAddress | Proxy address of the pair contract |
token0 / token1 | Structs containing address, name, symbol, and decimals |
1. Pick a factory address
// AgoraStableSwapFactory contract on Avalanche Fuji Testnet
const TESTNET_FACTORY = '0x237591AaF2FCCb34464Ceae9EeA1eb6f375843AF';
2. Helper to read the purchase fees
/**
* Returns an array of pair data for every pool created by the factory.
*/
async function getAllPairData(factory: `0x${string}`) {
return await client.readContract({
address: factory,
abi: stableSwapFactoryAbi,
functionName: "getAllPairData",
});
}
3. Run the query
(async () => {
const allPairData = await getAllPairData(TESTNET_FACTORY);
console.log(allPairData);
})();
[
{
pairAddress: '0x237591AaF2FCCb34464Ceae9EeA1eb6f375843AF',
token0: {
tokenAddress: '0xa9012a055bd4e0eDfF8Ce09f960291C09D5322dC',
name: 'AUSD',
symbol: 'AUSD',
decimals: 6n
},
token1: {
tokenAddress: '0xb8d4F619B3a482349DF31c33e75E28C93Eb92527',
name: 'ConstantToken',
symbol: 'CTK',
decimals: 18n
}
}
]