# defillama/defillama-adapters architecture

> Architecture diagram of the GitHub repository defillama/defillama-adapters, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/defillama/defillama-adapters
- Repository: https://github.com/defillama/defillama-adapters

## Overview

DefiLlama Adapters is a collection of project-specific JavaScript adapters that calculate protocol TVL from blockchain data. The principal workflow is an adapter’s chain-specific TVL function gathering balances and positions, using shared helpers to query chain data and resolve LP positions, then returning balances for TVL reporting. The repository also has centralized-exchange adapters and shared support for multiple chains, Bitcoin address books, event logs, caching, and HTTP/GraphQL access. Several adapter and helper relationships below rely on the SOURCE INDEX or README; unsampled implementations are not described in detail.

Main entry points: [`projects/helper/cex.js`](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/cex.js) (CEX balances), [`projects/helper/solana.js`](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/solana.js) (Solana balances), [`projects/helper/unwrapLPs.js`](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/unwrapLPs.js) (LP resolution), [`projects/libre-capital/index.js`](https://github.com/defillama/defillama-adapters/blob/main/projects/libre-capital/index.js) (Libre Capital TVL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_adapters["TVL adapters"]
  node_protocol["Protocol adapters"]
  node_unifarm["Unifarm TVL<br/>[index.js]"]
  node_basedbid["BasedBid TVL<br/>[index.js]"]
  node_libre["Libre Capital TVL<br/>[index.js]"]
end

subgraph group_exchange["Exchange adapters"]
  node_cexprojects["Exchange project adapters"]
  node_cexindex["CEX registry<br/>[index.js]"]
  node_cexhelper["CEX balances<br/>[cex.js]"]
  node_bitcoinbook["Bitcoin address book<br/>[index.js]"]
end

subgraph group_accounting["Balance accounting"]
  node_sumtokens["Token summation<br/>[sumTokens.js]"]
  node_unwrap["LP resolution<br/>[unwrapLPs.js]"]
  node_tokenmap["Token mapping<br/>[tokenMapping.js]"]
  node_ported["Ported tokens<br/>[portedTokens.js]"]
end

subgraph group_chains["Chain access"]
  node_solana["Solana balances<br/>[solana.js]"]
  node_aptos["Aptos queries<br/>[aptos.js]"]
  node_cosmos["Cosmos queries<br/>[cosmos.js]"]
  node_sui["Sui queries<br/>[sui.js]"]
  node_cardano["Cardano queries<br/>[blockfrost.js]"]
  node_bitcoinfetch["Bitcoin fetchers<br/>[fetchers.js]"]
  node_allium["Allium queries<br/>[allium.js]"]
end

subgraph group_support["Shared support"]
  node_cache["Shared cache<br/>[cache.js]"]
  node_logs["Event log retrieval<br/>[getLogs.js]"]
  node_http["HTTP and GraphQL<br/>[http.js]"]
  node_env["Environment config<br/>[env.js]"]
  node_utils["Chain utilities<br/>[utils.js]"]
  node_cexutils["CEX token lookup<br/>[cex.js]"]
  node_graphqlutil["GraphQL cache utility<br/>[graphql.js]"]
  node_staking["Staking helpers<br/>[stakingHelper.js]"]
  node_nft["NFT helpers<br/>[nft.js]"]
end

node_consumer(("TVL runner"))

node_consumer -->|"runs adapter"| node_protocol
node_protocol -.->|"computes balances"| node_sumtokens
node_unifarm -->|"sums tokens"| node_sumtokens
node_basedbid -->|"queries Solana"| node_solana
node_basedbid -->|"resolves positions"| node_unwrap
node_libre -->|"queries Aptos"| node_aptos
node_libre -->|"queries Cosmos"| node_cosmos
node_libre -->|"queries Sui"| node_sui
node_libre -->|"queries Cardano"| node_cardano
node_protocol -.->|"reads events"| node_logs
node_cexindex -->|"uses balances"| node_cexhelper
node_cexprojects -.->|"uses balances"| node_cexhelper
node_cexhelper -->|"sums tokens"| node_sumtokens
node_cexhelper -->|"resolves LPs"| node_unwrap
node_cexhelper -->|"looks up tokens"| node_cexutils
node_cexhelper -->|"uses address book"| node_bitcoinbook
node_bitcoinbook -->|"loads fetchers"| node_bitcoinfetch
node_logs -->|"reads and writes"| node_cache
node_http -->|"reads settings"| node_env
node_solana -->|"transforms balances"| node_ported
node_solana -->|"normalizes tokens"| node_tokenmap
node_solana -->|"makes requests"| node_http
node_solana -->|"queries history"| node_allium
node_utils -->|"makes requests"| node_http
node_utils -->|"reads settings"| node_env
node_utils -.->|"supports aggregation"| node_sumtokens
node_cache -->|"uses GraphQL cache"| node_graphqlutil
node_protocol -.->|"uses staking helpers"| node_staking
node_unwrap -->|"transforms tokens"| node_ported
node_unwrap -->|"normalizes tokens"| node_tokenmap
node_unwrap -->|"uses NFT helpers"| node_nft

click node_protocol "https://github.com/defillama/defillama-adapters/tree/main/projects"
click node_unifarm "https://github.com/defillama/defillama-adapters/blob/main/projects/unifarm/index.js"
click node_basedbid "https://github.com/defillama/defillama-adapters/blob/main/projects/basedbid/index.js"
click node_libre "https://github.com/defillama/defillama-adapters/blob/main/projects/libre-capital/index.js"
click node_cexprojects "https://github.com/defillama/defillama-adapters/tree/main/projects"
click node_cexindex "https://github.com/defillama/defillama-adapters/blob/main/cex/index.js"
click node_cexhelper "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/cex.js"
click node_bitcoinbook "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/bitcoin-book/index.js"
click node_sumtokens "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/sumTokens.js"
click node_unwrap "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/unwrapLPs.js"
click node_tokenmap "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/tokenMapping.js"
click node_ported "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/portedTokens.js"
click node_solana "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/solana.js"
click node_aptos "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/chain/aptos.js"
click node_cosmos "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/chain/cosmos.js"
click node_sui "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/chain/sui.js"
click node_cardano "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/chain/cardano/blockfrost.js"
click node_bitcoinfetch "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/bitcoin-book/fetchers.js"
click node_allium "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/allium.js"
click node_cache "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/cache.js"
click node_logs "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/cache/getLogs.js"
click node_http "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/http.js"
click node_env "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/env.js"
click node_utils "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/utils.js"
click node_cexutils "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/utils/cex.js"
click node_graphqlutil "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/utils/graphql.js"
click node_staking "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/stakingHelper.js"
click node_nft "https://github.com/defillama/defillama-adapters/blob/main/projects/helper/nft.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_protocol,node_unifarm,node_basedbid,node_libre toneBlue
class node_cexprojects,node_cexindex,node_cexhelper,node_bitcoinbook toneAmber
class node_sumtokens,node_unwrap,node_tokenmap,node_ported toneMint
class node_solana,node_aptos,node_cosmos,node_sui,node_cardano,node_bitcoinfetch,node_allium toneRose
class node_cache,node_logs,node_http,node_env,node_utils,node_cexutils,node_graphqlutil,node_staking,node_nft,node_consumer toneIndigo
```

## Components

### TVL adapters

- [Protocol adapters](https://github.com/defillama/defillama-adapters/tree/main/projects): `projects`
- [Unifarm TVL](https://github.com/defillama/defillama-adapters/blob/main/projects/unifarm/index.js): `projects/unifarm/index.js`
- [BasedBid TVL](https://github.com/defillama/defillama-adapters/blob/main/projects/basedbid/index.js): `projects/basedbid/index.js`
- [Libre Capital TVL](https://github.com/defillama/defillama-adapters/blob/main/projects/libre-capital/index.js): `projects/libre-capital/index.js`

### Exchange adapters

- [Exchange project adapters](https://github.com/defillama/defillama-adapters/tree/main/projects): `projects`
- [CEX registry](https://github.com/defillama/defillama-adapters/blob/main/cex/index.js): `cex/index.js`
- [CEX balances](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/cex.js): `projects/helper/cex.js`
- [Bitcoin address book](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/bitcoin-book/index.js): `projects/helper/bitcoin-book/index.js`

### Balance accounting

- [Token summation](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/sumTokens.js): `projects/helper/sumTokens.js`
- [LP resolution](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/unwrapLPs.js): `projects/helper/unwrapLPs.js`
- [Token mapping](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/tokenMapping.js): `projects/helper/tokenMapping.js`
- [Ported tokens](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/portedTokens.js): `projects/helper/portedTokens.js`

### Chain access

- [Solana balances](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/solana.js): `projects/helper/solana.js`
- [Aptos queries](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/chain/aptos.js): `projects/helper/chain/aptos.js`
- [Cosmos queries](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/chain/cosmos.js): `projects/helper/chain/cosmos.js`
- [Sui queries](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/chain/sui.js): `projects/helper/chain/sui.js`
- [Cardano queries](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/chain/cardano/blockfrost.js): `projects/helper/chain/cardano/blockfrost.js`
- [Bitcoin fetchers](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/bitcoin-book/fetchers.js): `projects/helper/bitcoin-book/fetchers.js`
- [Allium queries](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/allium.js): `projects/helper/allium.js`

### Shared support

- [Shared cache](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/cache.js): `projects/helper/cache.js`
- [Event log retrieval](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/cache/getLogs.js): `projects/helper/cache/getLogs.js`
- [HTTP and GraphQL](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/http.js): `projects/helper/http.js`
- [Environment config](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/env.js): `projects/helper/env.js`
- [Chain utilities](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/utils.js): `projects/helper/utils.js`
- [CEX token lookup](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/utils/cex.js): `projects/helper/utils/cex.js`
- [GraphQL cache utility](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/utils/graphql.js): `projects/helper/utils/graphql.js`
- [Staking helpers](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/stakingHelper.js): `projects/helper/stakingHelper.js`
- [NFT helpers](https://github.com/defillama/defillama-adapters/blob/main/projects/helper/nft.js): `projects/helper/nft.js`

### Other components

- **TVL runner**

## Connections

- TVL runner → Protocol adapters: runs adapter (evidence: `README.md`)
- Protocol adapters → Token summation: computes balances (evidence: `projects/satoshi-protocol/index.js`)
- Unifarm TVL → Token summation: sums tokens (evidence: `projects/unifarm/index.js`)
- BasedBid TVL → Solana balances: queries Solana (evidence: `projects/basedbid/index.js`)
- BasedBid TVL → LP resolution: resolves positions (evidence: `projects/basedbid/index.js`)
- Libre Capital TVL → Aptos queries: queries Aptos (evidence: `projects/libre-capital/index.js`)
- Libre Capital TVL → Cosmos queries: queries Cosmos (evidence: `projects/libre-capital/index.js`)
- Libre Capital TVL → Sui queries: queries Sui (evidence: `projects/libre-capital/index.js`)
- Libre Capital TVL → Cardano queries: queries Cardano (evidence: `projects/libre-capital/index.js`)
- Protocol adapters → Event log retrieval: reads events (evidence: `projects/royco-v2/index.js`)
- CEX registry → CEX balances: uses balances (evidence: `cex/index.js`)
- Exchange project adapters → CEX balances: uses balances (evidence: `projects/gate-io/index.js`)
- CEX balances → Token summation: sums tokens (evidence: `projects/helper/cex.js`)
- CEX balances → LP resolution: resolves LPs (evidence: `projects/helper/cex.js`)
- CEX balances → CEX token lookup: looks up tokens (evidence: `projects/helper/cex.js`)
- CEX balances → Bitcoin address book: uses address book (evidence: `projects/helper/cex.js`)
- Bitcoin address book → Bitcoin fetchers: loads fetchers (evidence: `projects/helper/bitcoin-book/index.js`)
- Event log retrieval → Shared cache: reads and writes (evidence: `projects/helper/cache/getLogs.js`)
- HTTP and GraphQL → Environment config: reads settings (evidence: `projects/helper/http.js`)
- Solana balances → Ported tokens: transforms balances (evidence: `projects/helper/solana.js`)
- Solana balances → Token mapping: normalizes tokens (evidence: `projects/helper/solana.js`)
- Solana balances → HTTP and GraphQL: makes requests (evidence: `projects/helper/solana.js`)
- Solana balances → Allium queries: queries history (evidence: `projects/helper/solana.js`)
- Chain utilities → HTTP and GraphQL: makes requests (evidence: `projects/helper/utils.js`)
- Chain utilities → Environment config: reads settings (evidence: `projects/helper/utils.js`)
- Chain utilities → Token summation: supports aggregation
- Shared cache → GraphQL cache utility: uses GraphQL cache (evidence: `projects/helper/cache.js`)
- Protocol adapters → Staking helpers: uses staking helpers (evidence: `projects/gate-io/index.js`)
- LP resolution → Ported tokens: transforms tokens (evidence: `projects/helper/unwrapLPs.js`)
- LP resolution → Token mapping: normalizes tokens (evidence: `projects/helper/unwrapLPs.js`)
- LP resolution → NFT helpers: uses NFT helpers (evidence: `projects/helper/unwrapLPs.js`)
