Spock Analytics
  • Introduction
  • The Spock Thesis
  • Spock Analytics
    • Explore: The Data Warehouse for DApps
    • Probe: Strategic Data Reports
    • Engage: Improve User Conversion and Retention
  • Spock API
    • Build Custom Campaigns Using On-chain Data
    • Decipher Web3 Wallets Landscape
  • Guides
    • Maximize NFT Lending: Strategies For NFTFi DApps
    • 10x NFT Borrower Engagement: Strategies For NFTFi DApps
    • Offer Gas Refunds to Newly Converted Users
    • Boost Your Liquidity Providers Conversion Rate
    • Increase Transaction Submissions by 15% Using Probe
  • Configuration
    • Onboarding
    • Contracts
    • SDK
      • API Reference
      • Supporting Wallets
      • NPM Package
      • Example Application
      • SDK Code
    • Adapter
      • Transformers
      • TVL Extractors
      • How to code an adapter?
      • Functions we have written so you don't have to
        • Multicall
        • Sum Balances
      • GitHub repo
  • Pricing
    • Explore & Probe
    • Engage
    • Pricing Calculations & FAQs
  • Data Catalog
    • Wallet
    • Global
    • This Protocol
    • Session
    • Other Protocols
    • Transaction
Powered by GitBook
On this page
  • Structure
  • Event Handler
  1. Configuration
  2. Adapter

Transformers

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

PreviousAdapterNextTVL Extractors

Last updated 1 year ago

Structure

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

Property
Type
Description

address

optional

Contract address, if undefined will sync all the events of given signatures in event handlers

getAddresses

optional

If you have a mapping of contract addresses and want to sync events for all those addresses

contract

required

The interface of contract generated by typechain through contract ABI

eventHandlers

required

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

startBlock

required

Block number from which the syncing of contract events will start

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

The Graph