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
  • Exports Helpers
  • Token balance queries
  • Solana Helpers
  • Transforming Tokens That Aren't On CoinGecko
  • Getting Block Heights

Was this helpful?

  1. List your project

Functions we've written so you don't have to

PreviousHow to write an SDK adapterNextStaking and Pool2

Last updated 1 year ago

Was this helpful?

Exports Helpers

Exporting empty TVL - if your project has filtered TVL only, here's an easy way to export core TVL as empty.

module.exports = {
    bsc: {
        tvl: () => ({}),
        staking
    }
};

Token balance queries

if you have a known set of tokens and contract addresses, there are few ways to fetch and export it as tvl using sumTokensExport

if single contract and multiple tokens

const { sumTokensExport } = require("./helper/unwrapLPs");

module.exports = {
    fantom: {
        tvl: sumTokensExport({ 
          owner: '0x..., 
          tokens: [ '0x...',...   ],
        }),
    }
};

if there are multiple contracts to look up:

const { sumTokensExport } = require("./helper/unwrapLPs");

module.exports = {
    fantom: {
        tvl: sumTokensExport({ 
          owners: ['0x...', '0x...', ...],
          tokens: [ '0x...',...   ],
        }),
    }
};

if all contracts dont share same set of tokens:

const { sumTokensExport } = require("./helper/unwrapLPs");

module.exports = {
    fantom: {
        tvl: sumTokensExport({ 
          tokensAndOwners: [
            // [tokenAddress, ownerContractAddress]
            ['0x...', '0x...'],
            ['0x...', '0x...'],
          ],
        }),
    }
};

if any of these tokens are LP tokens, set resolveLP: true to resolve them into underlying tokens

Solana Helpers

getTokenBalance is used for getting a solana account's balance of a particular token.

const { getTokenBalance } = require("../helper/solana");

Transforming Tokens That Aren't On CoinGecko

DefiLlama uses a wide variety of sources to price tokens, such as CoinGecko and chain calls to price exotic tokens such as Curve and uniswap LPs. If you find that a token is missing and it's not getting priced in your adapter, just let us know in our discord!

To count the TVL of LP token balances, the positions must be unwrapped into their underlying tokens.

const { sumTokens2 } = require('../helper/unwrapLPs');

const balances = {};
...
return sumTokens2({ balances, tokensAndOwners: [...], api, resolveLP: true })

Getting Block Heights

For lesser known EVM chains sometimes the block height wont be available in the third parameter passed to the adapter's TVL function. In this case you can use getBlock to fetch the block height.

const { getBlock } = require('../helper/http');
block = await getBlock(timestamp, chain, chainBlocks);
DefiLlama-Adapters/arcx.js at main · DefiLlama/DefiLlama-AdaptersGitHub
Example adapter
https://github.com/DefiLlama/DefiLlama-Adapters/blob/main/projects/velaro/index.js
Example adapter
https://github.com/DefiLlama/DefiLlama-Adapters/blob/main/projects/aevo/index.jsgithub.com
Example adapter
DefiLlama-Adapters/index.js at main · DefiLlama/DefiLlama-AdaptersGitHub
Example Solana Adapter
DefiLlama-Adapters/index.js at main · DefiLlama/DefiLlama-AdaptersGitHub
Example Unwrap Uni V2 Adapter
DefiLlama-Adapters/projects/atlendis/index.js at main · DefiLlama/DefiLlama-AdaptersGitHub
Example Get Block Adapter
Logo
Logo
Logo
Logo