> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dune.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Lending

> Curated DeFi lending datasets across 15+ EVM chains on Dune

Dune's lending tables provide standardized data on DeFi lending protocol activity — supply (deposit/withdraw), borrow (borrow/repay/liquidation), and flash loans — across 15+ EVM chains. All major lending protocols are aggregated into a single schema.

<Info>
  **Maintained by:** Dune · **Refresh:** \~20 min · **Chains:** 15 EVM chains
</Info>

<Card title="Get This Data" icon="database" href="https://dune.com/enterprise?dataset=lending">
  Access lending data via API, Datashare, or the Dune App.
</Card>

## Available Tables

<CardGroup cols={2}>
  <Card title="lending.supply" icon="database" href="/data-catalog/curated/lending/supply">
    All supply-side transactions: deposits, withdrawals, and supply-side liquidations
  </Card>

  <Card title="lending.borrow" icon="database" href="/data-catalog/curated/lending/borrow">
    All borrow-side transactions: borrows, repayments, and borrow-side liquidations
  </Card>

  <Card title="lending.flashloans" icon="database" href="/data-catalog/curated/lending/flashloans">
    All flash loan transactions across lending protocols
  </Card>

  <Card title="lending.info" icon="database" href="/data-catalog/curated/lending/info">
    Static lookup of lending protocol metadata
  </Card>
</CardGroup>

## When to Use These Tables

* Track supply and borrow volumes across DeFi lending protocols
* Analyze liquidation events and at-risk positions
* Monitor flash loan activity and fees
* Compare lending protocol market share across chains
* Build lending analytics dashboards for protocol teams or investors

## Coverage

**Chains (15):** Arbitrum, Avalanche C-Chain, Base, BNB Chain, Celo, Ethereum, Fantom, Gnosis, Linea, Optimism, Polygon, Scroll, Sonic, zkSync, Unichain

**Protocols:** Aggregated from all integrated lending protocols including Aave, Compound, and others. Use `SELECT DISTINCT project FROM lending.supply` for the current list.

## Query Performance

**Partition keys:**

* `lending.supply`: `blockchain`, `project`, `block_month`
* `lending.borrow`: `blockchain`, `project`, `block_month`
* `lending.flashloans`: `blockchain`, `project`

Always include `blockchain` and `block_month` (or a `block_time` range) in your WHERE clause.

```sql theme={null}
-- ✅ Good: filters on partition keys
SELECT * FROM lending.supply
WHERE blockchain = 'ethereum'
  AND block_month >= DATE '2025-01-01'
  AND project = 'aave'

-- ❌ Slow: no partition filters
SELECT * FROM lending.supply
WHERE symbol = 'USDC'
```

## Methodology

Lending tables are maintained by Dune ([source code](https://github.com/duneanalytics/spellbook)). They aggregate data from protocol-specific base models (`lending_base_supply`, `lending_base_borrow`, `lending_base_flashloans`), which decode on-chain events from each protocol's smart contracts. Token amounts are decimal-adjusted and joined with Dune's price feeds (`prices.minute`, `prices.hour`, `prices.day`) for USD values.

## Example Queries

**Daily supply volume by protocol on Ethereum:**

```sql theme={null}
SELECT
  date_trunc('day', block_time) AS day,
  project,
  SUM(amount_usd) AS supply_volume_usd
FROM lending.supply
WHERE blockchain = 'ethereum'
  AND block_month >= DATE '2025-01-01'
  AND transaction_type = 'deposit'
GROUP BY 1, 2
ORDER BY 1 DESC, 3 DESC
```

**Top borrowers by total USD borrowed (last 30 days):**

```sql theme={null}
SELECT
  borrower,
  SUM(amount_usd) AS total_borrowed_usd,
  COUNT(*) AS num_borrows
FROM lending.borrow
WHERE blockchain = 'ethereum'
  AND block_time >= NOW() - INTERVAL '30' DAY
  AND transaction_type = 'borrow'
GROUP BY 1
ORDER BY 2 DESC
LIMIT 20
```

**Flash loan volume by chain:**

```sql theme={null}
SELECT
  blockchain,
  project,
  SUM(amount_usd) AS flashloan_volume_usd,
  COUNT(*) AS num_flashloans
FROM lending.flashloans
WHERE block_time >= NOW() - INTERVAL '7' DAY
GROUP BY 1, 2
ORDER BY 3 DESC
```

## Related Tables

* `dex.flashloans` — Flash loans from DEX protocols (Balancer, Uniswap, dYdX) as opposed to lending-native flash loans
* `prices.day` / `prices.hour` / `prices.minute` — Token price feeds
* `tokens.erc20` — Token metadata (symbols, decimals)

<CardGroup cols={2}>
  <Card title="Enterprise Data Solutions" icon="building" href="https://dune.com/enterprise">
    Need custom lending datasets or dedicated support? Talk to our enterprise team.
  </Card>

  <Card title="Build Custom Models" icon="code" href="/api-reference/connectors/overview">
    Build private lending analytics pipelines with the dbt Connector.
  </Card>
</CardGroup>
