# Tracking Components

{% hint style="info" %}
Note: this implementation pattern is, by default, used in the [ethereum-template-factory](https://github.com/propeller-heads/tycho-indexer/tree/main/protocols/substreams/ethereum-template-factory) template.
{% endhint %}

If protocols use factories to deploy components, a common pattern used during indexing is to detect the creation of these new components and store their contract addresses to track them downstream. Later, you might need to emit balance and state changes based on the current set of tracked components.

### Implementation Steps

1. Implement logic to identify newly created components. A recommended approach is to create a `factory.rs` module to facilitate the detection of newly deployed components.
2. Use the logic/helper module from step 1 in a map handler that consumes `substreams_ethereum::pb::eth::v2::Block` models and outputs a message containing all available information about the component at the time of creation, along with the transaction that deployed it. The recommended output model for this initial handler is [BlockTransactionProtocolComponents](https://github.com/propeller-heads/tycho-indexer/blob/main/proto/tycho/evm/v1/utils.proto).\
   Note that a single transaction may create multiple components. In such cases, `TransactionProtocolComponents.components` should list all newly created `ProtocolComponents`.
3. After emitting, store the protocol components in a `Store`. This you will use later in the module to detect relevant balance changes and to determine whether a contract is relevant for tracking.

{% hint style="danger" %}
Emitting state or balance changes for components not previously registered/stored is considered an error.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.propellerheads.xyz/tycho/for-dexs/protocol-integration/indexing/common-problems-and-patterns/tracking-components.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
