This week's release of the Python SDK brings dynamic event filters! Dynamic event filters enable developers to add event filters while indexing, for example in response to another event.
Use cases for dynamic event filters include indexing:
- DEX pools that are created by pool factories,
- game rounds that are created by the main instance of the on-chain game.
To try out this feature, upgrade the apibara package to version 0.5.4.
After that you can subscribe to new events directly in your event handler.
For example, the following snippet shows how to decode a
from a Uniswap V2-like DEX and then subscribe to the
on the new trade pair.
async def handle_events(info: Info, block_events: NewEvents):for event in block_events.events:if event.name == "PairCreated":pair_created = decode_event(pair_created_decoder, event.data)info.add_event_filters(filters=[EventFilter.from_event_name("Swap", address=pair_created.pair),EventFilter.from_event_name("Sync", address=pair_created.pair),])
You can find more information about dynamic filters in the documentation.