Step 5: Initialize and Run the Uniswap V2 Indexer
Now, you use the mapped config to start your indexer:
import { AbsintheApiClient, validateEnv, HOURS_TO_MS, ProtocolType } from '@absinthe/common';
import { UniswapV2Processor } from './BatchProcessor';
const env = validateEnv();
const apiClient = new AbsintheApiClient({
baseUrl: env.baseConfig.absintheApiUrl,
apiKey: env.baseConfig.absintheApiKey,
});
const uniswapV2DexProtocol = env.dexProtocols.find(dexProtocol => {
return dexProtocol.type === ProtocolType.UNISWAP_V2;
});
if (!uniswapV2DexProtocol) {
throw new Error('Uniswap V2 protocol not found');
}
const chainConfig = {
chainArch: uniswapV2DexProtocol.chainArch,
networkId: uniswapV2DexProtocol.chainId,
chainShortName: uniswapV2DexProtocol.chainShortName,
chainName: uniswapV2DexProtocol.chainName,
};
const WINDOW_DURATION_MS = env.baseConfig.balanceFlushIntervalHours * HOURS_TO_MS;
const uniswapProcessor = new UniswapV2Processor(
uniswapV2DexProtocol, // The full protocol config (with pools, chain, etc)
WINDOW_DURATION_MS, // How often to flush balances (in ms)
apiClient, // The Absinthe API client for sending data
env.baseConfig, // Base config (API URLs, etc)
chainConfig, // Chain metadata
);
uniswapProcessor.run(); // Start the indexer!
What does this do?
- Loads and validates config (including your Uniswap V2 pools).
- Finds the Uniswap V2 protocol config from the list.
- Builds chain metadata for the processor.
- Creates an API client for sending data to Absinthe.
- Initializes the UniswapV2Processor with all the above.
- Starts the processor with
.run()
, which begins indexing blocks, decoding events, and sending data.