Handling Factory Contract

In many cases, there is a factory contract that is responsible to create multiple actual contracts. The typical example is UniswapV3Factory, every time a pool is created, an PoolCreated event is emitted.

In this case, you could use Dynamic Processor Creationto handle this case. In this very concrete uniswap case, you'd first create a factory processor to track PoolCreated event:

UniswapFactoryProcessor.bind({address: '0x1F98431c8aD98523631AE4a59f267346ea31F984'})
        async function (event: PoolCreatedEvent, ctx: UniswapFactoryContext) {
            poolTemplate.bind({address: event.args.pool, startBlock: ctx.blockNumber})

Note this monitors the total # of pools created. It uses poolTemplate to track the actual swap Events.

const poolTemplate = new UniswapProcessorTemplate()
        async function (event: SwapEvent, ctx: UniswapContext) {
                    from: await ctx.contract.token0(),
                    to: await ctx.contract.token1()

Notice the template must be declared in the top level of your processor file to be successfully registered.

Last updated