# Transformers

### Structure

The structure of the transformers is quite similar to [The Graph](https://thegraph.com/) subgraphs in which we have functions named event handlers containing event objects as arguments.

Each transformer belongs to one contract.

```
type Transformer = {
 address?:string;
 getAddresses?:(chain:Chain) => Promise<Array<string>>;
 contract: Interface;
 eventHandlers: Record<Signature,EventHandler>;
 startBlock:number;
}
```

<table><thead><tr><th width="160.33333333333331">Property</th><th width="137">Type</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>optional</td><td>Contract address, if undefined will sync all the events of given signatures in event handlers</td></tr><tr><td>getAddresses</td><td>optional</td><td>If you have a mapping of contract addresses and want to sync events for all those addresses</td></tr><tr><td>contract</td><td>required</td><td>The interface of contract generated by typechain through contract ABI</td></tr><tr><td>eventHandlers</td><td>required</td><td>It's the key value object in which the key is the signature (keccak256 hash of event topic) of the event and the value is the callback function that will be executed when the event gets fired</td></tr><tr><td>startBlock</td><td>required</td><td>Block number from which the syncing of contract events will start</td></tr></tbody></table>

### Event Handler

The event handler is basically a function linked with its signature that is called when a specific event is fired.\
It takes event data as an argument and returns protocol value (contribution/extraction).

```
type EventHandler = (
  event: Event<any>
) => Promise<ProtocolValueReturnType | void | undefined>;
```

Event (passed as an argument in the event handler)

```
import {
  TransactionResponse,
  Block,
  TransactionReceipt,
} from '@ethersproject/providers';

interface Event<T> {
  address: string;
  blockNumber: number;
  params: T;
  signature: string;
  block: Promise<Block>;
  transaction: Promise<TransactionResponse>;
  transactionReceipt: Promise<TransactionReceipt>;
  transactionHash: string;
  transactionLogIndex: number;
  logIndex: number;
  chain: Chain;
}
```

Protocol Value (returned by event handler)

```
type ProtocolValueReturnType = {
  type: 'contribution' | 'extraction';
  label: string;
  value: number;
  user: string;
};
```


---

# 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://spock-analytics.gitbook.io/introduction/configuration/adapter/transformers.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.
