Goal
to generate a list of all pool tokens for the v2 dex available under the migration feature.
Reasoning
harvesting this information is expensive and repetitive without relying on a pre existing list.
API data structure
{dexName}
- pool token address
- pool token address
{dexName}
- pool token address
- pool token address
Dex
uni v2: 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f
sushi v2: 0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac
pancake v2: 0x1097053Fd2ea711dad45caCcc45EfF7548fCB362
Process
suggested script
import { ethers } from "ethers";
const FACTORY_ADDRESS = "{factoryAddress}";
const FACTORY_ABI = [
"function allPairs(uint) view returns (address)",
"function allPairsLength() view returns (uint)",
"event PairCreated(address indexed token0, address indexed token1, address pair, uint)",
];
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const factory = new ethers.Contract(FACTORY_ADDRESS, FACTORY_ABI, provider);
let pairs = [];
let currentIndex = 0;
async function fetchPair(index) {
try {
const pair = await factory.allPairs(index);
pairs.push({ index, pair });
console.log(`[${index}] ${pair}`);
currentIndex = index + 1;
// Immediately try to fetch the next one
await fetchPair(currentIndex);
} catch (err) {
console.log(`Reached end at index ${index}. Total pairs: ${pairs.length}`);
}
}
// Listen for new pairs
factory.on("PairCreated", (token0, token1, pair, index) => {
console.log(`\nNew pair created: ${pair} (index ${index})`);
// Try fetching from the latest known index
fetchPair(currentIndex);
});
// Start fetching
console.log("Starting pair fetch...");
fetchPair(0);
Goal
to generate a list of all pool tokens for the v2 dex available under the migration feature.
Reasoning
harvesting this information is expensive and repetitive without relying on a pre existing list.
API data structure
{dexName}
{dexName}
Dex
uni v2:
0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6fsushi v2:
0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2acpancake v2:
0x1097053Fd2ea711dad45caCcc45EfF7548fCB362Process
suggested script