Note (Updated: 2025-05-01): This page might contain outdated information. For the most up-to-date documentation, please visit the main guide.
Helper Functions
This document provides detailed information about the various helper functions available to simplify the creation of adapters. Each section includes example implementations and links to real adapters using these functions.
Token Tracking Helpers
addTokensReceived
Tracks ERC20 token transfers received by specified addresses. Supports filtering by sender/receiver and custom token transformations. It attempts to use an indexer first for performance, with a fallback to log processing.
import { addTokensReceived } from '../../helpers/token';
const fetch: any = async (options: FetchOptions) => {
const dailyFees = await addTokensReceived({
options,
tokens: ["0x4200000000000000000000000000000000000006"], // WETH on Base
targets: ["0xbcb4a982d3c2786e69a0fdc0f0c4f2db1a04e875"] // Treasury
})
return { dailyFees, dailyRevenue: dailyFees }
}
addGasTokensReceived
Tracks native token transfers (like ETH) received by specified multisig addresses. This helper is particularly useful for protocols that collect fees in the chain's native token.
Fetches token transfers to specified Solana addresses within a given time range, with ability to exclude specific sender addresses or transaction signers.
Retrieves event logs from blockchains based on specified filters like target addresses, event signatures, and topics. Essential for tracking on-chain events.
Creates an adapter for Compound V2-like protocols, taking config parameters and returning an object that tracks fees, revenue, and distribution among holders and suppliers.
import { compoundV2Export } from '../helpers/compound';
export default compoundV2Export({
reserveFactor: 0.1, // 10% of interest goes to protocol
markets: {
[CHAIN.ETHEREUM]: {
comptroller: '0x123...abc',
// ... other market parameters
}
}
});
uniV2Exports / getUniV2LogAdapter
Generates adapter configurations for Uniswap V2-style DEXes across multiple chains.
You can find the full source code for these helper functions in the DeFi Llama GitHub repository:
Exact day timestamp
Some data sources are only able to return data given a 00:00:00 day timestamp. In that case you can use the parameter startOfDay to get the timestamp of the specific day. For example passing 1663718399 (2022-09-20T23:59:59.000Z) timestamp will return 1663632000000 (2022-09-20T00:00:00.000Z)
- Contains functions like addTokensReceived, getETHReceived, etc.