DeFi Llama
  • List your project
    • DefiLlama and our methodology
    • How to list a DeFi project
    • How to add a new Blockchain
    • How to write an SDK adapter
    • Functions we've written so you don't have to
      • Staking and Pool2
      • Fork helpers
      • General EVM contract calls
    • What to include as TVL?
    • How to update a project
    • How to write dimensions adapters
    • Emissions dashboard
      • Protocol Files
      • Emission Sections
      • Testing
    • Oracles TVS
  • analysts
    • Data Definitions
    • Custom columns
  • Chainlist
    • How to change Ethereum's RPC
    • Add a new RPC endpoint
  • FAQs
    • Frequently Asked Questions
  • Coin Prices API
  • Pricing
Powered by GitBook
On this page
  • Balance Calls
  • Custom Contract Calls

Was this helpful?

  1. List your project
  2. Functions we've written so you don't have to

General EVM contract calls

Balance Calls

use sumTokens2 method from helper to return token balances

For example, you have a vault with USDC and ETH tokens in it in arbitrum



const { sumTokensExport, sumTokens } = require('./helper/unwrapLPs')

const owner = '0x...' // vault address
const tokens = [
  '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC
  '0x0000000000000000000000000000000000000000', // ETH
]

module.exports = {
  arbitrum: {
    tvl: sumTokensExport({ owner, tokens })
  }
}

// or 

module.exports = {
  arbitrum: {
    tvl: async (api) => {
      return sumTokens2({ owner, tokens, api, })
    }
  }
}

Custom Contract Calls

Contract calls are the most common ways of recording TVL.

const response = await api.call({<params>})

Often after a single contract call you'll also want to add the balance to your balances object, which can be easily done with sumSingleBalance.

await sdk.util.sumSingleBalance(balances, tokenAddress, balanceOfToken);

When you have lots of calls to functions with the same ABI, it's easier to use multiCall and sumMultiBalanceOf.

const tokensInacBTC = [
  '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
  '0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D'
];

const acBTCTokenHolder = '0x73FddFb941c11d16C827169Bb94aCC227841C396';

const underlyingacBTC = await api.multiCall({
  calls: tokensInacBTC.map(token => ({
    target: token,
    params: [acBTCTokenHolder]
  })),
  abi: 'erc20:balanceOf',
  withMetadata: true,
});

sdk.util.sumMultiBalanceOf(balances, underlyingacBTC);
PreviousFork helpersNextWhat to include as TVL?

Last updated 1 year ago

Was this helpful?

DefiLlama-Adapters/index.js at main · DefiLlama/DefiLlama-AdaptersGitHub
Example ERC20 Token Balance Adapter
DefiLlama-Adapters/index.js at main · DefiLlama/DefiLlama-AdaptersGitHub
DefiLlama-Adapters/index.js at main · DefiLlama/DefiLlama-AdaptersGitHub
Example MultiCall Adapter
Logo
Logo
Logo