Transformers

The transformers are responsible to track the data of contributions and extractions through the events fired by the smart contracts.

Structure

The structure of the transformers is quite similar to The Graph 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;
}

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;
};

Last updated