Fetching Purchase Fees

The AgoraStableSwapPair contract stores the current purchase-fee rate (in 18-dec “fee precision” units) for each token direction:

  • token0PurchaseFee – fee charged when buying token0 (i.e., swapping into token0).
  • token1PurchaseFee – fee charged when buying token1.

1. Pick a pair address

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

2. Helper to read the purchase fees

1/**
2 * Returns raw purchase-fee rates (18-dec precision).
3 */
4async function getPairPurchaseFees(
5 pair: `0x${string}`,
6): Promise<{ token0PurchaseFee: bigint; token1PurchaseFee: bigint }> {
7 const token0PurchaseFee = await client.readContract({
8 address: pair,
9 abi: stableSwapAbi,
10 functionName: "token0PurchaseFee",
11 args: [],
12 });
13
14 const token1PurchaseFee = await client.readContract({
15 address: pair,
16 abi: stableSwapAbi,
17 functionName: "token1PurchaseFee",
18 args: [],
19 });
20
21 return { token0PurchaseFee, token1PurchaseFee };
22}

3. Run the query

1(async () => {
2 const { token0PurchaseFee, token1PurchaseFee } = await getPairPurchaseFees(
3 TESTNET_PAIR_AUSD_CTK,
4 );
5
6 console.log("Purchase fee (token0 → token1):", token0PurchaseFee);
7 console.log("Purchase fee (token1 → token0):", token1PurchaseFee);
8})();
1Purchase fee (token0 → token1): 100000000000000n // 0.01% (1 bps)
2Purchase fee (token1 → token0): 200000000000000n // 0.02% (2 bps)

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.