> ## 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.

# dex.trades

> The `dex.trades` table captures detailed data on decentralized exchange (DEX) trades, recording all raw trade events across various protocols and blockchains.

export const TableSample = ({tableName, tableSchema}) => <>
    <div className="hidden dark:block">
      <iframe src={`https://dune.com/embeds/3419983/5785629?table_schema_t6f0df=${tableSchema}&table_name_t6f0df=${tableName}&darkMode=true`} style={{
  width: '100%',
  height: '500px',
  border: 'none',
  marginTop: '10px'
}} />
    </div>
    <div className="dark:hidden">
      <iframe src={`https://dune.com/embeds/3419983/5785629?table_schema_t6f0df=${tableSchema}&table_name_t6f0df=${tableName}`} style={{
  width: '100%',
  height: '500px',
  border: 'none',
  marginTop: '10px'
}} />
    </div>
  </>;

export const DuneEmbed = ({qID, vID, height = '500px'}) => <>
    <div className="hidden dark:block">
      <iframe src={`https://dune.com/embeds/${qID}/${vID}?darkMode=true`} style={{
  width: '100%',
  height,
  border: 'none',
  marginTop: '10px'
}}></iframe>
    </div>
    <div className="dark:hidden">
      <iframe src={`https://dune.com/embeds/${qID}/${vID}`} style={{
  width: '100%',
  height,
  border: 'none',
  marginTop: '10px'
}}></iframe>
    </div>
  </>;

<Frame caption="This table stores data on dex trades across protocols...">
  <DuneEmbed qID={4319} vID={8411} height={300} />
</Frame>

<Frame caption="... and chains">
  <DuneEmbed qID={2180075} vID={3571504} height={300} />
</Frame>

## Table Description

The `dex.trades` table captures detailed data on trades executed via decentralized exchanges (DEXs). This table captures all raw trade events that happen across all liquidity pools. It provides a comprehensive view of the entire trade execution process, detailing the specific paths and liquidity sources utilized.

## Functional Overview

The `dex.trades` table provides an in-depth view of trades on decentralized exchanges like Uniswap or Curve. This table includes entries for each segment of a trade that passes through different liquidity pools, as well as single-step trades. For example, a user may initiate a trade to swap USDC for PEPE. If this trade is executed through multiple liquidity pools, such as USDC-WETH and WETH-PEPE, the `dex.trades` table will record each segment of the trade as a separate entry. Conversely, a single-step trade, such as directly swapping USDC for ETH, will be recorded as a single entry.

This detailed approach allows for granular analysis of trade execution paths, enabling users to:

* **Analyze Liquidity Sources**: Understand which liquidity pools are used and how they interact in both single-step and multi-step trades.
* **Track Trade Execution Paths**: Follow the exact route a trade takes across different DEXs and liquidity pools.
* **Assess Slippage and Execution Quality**: Evaluate the impact of each step on the overall trade execution, including slippage and price changes.
* **Monitor Market Dynamics**: Gain insights into the behavior and dynamics of different liquidity pools and DEXs over time.

By providing comprehensive trade details, the `dex.trades` table supports advanced analytics and research into DEX trading behavior and liquidity management.

Complementary tables include `dex_aggregator.trades`, in which trade-intents that are routed through aggregators are recorded. The volume routed through aggregators is also recorded in the dex.trades table, one row in dex\_aggregator trades corresponds to one or more rows in dex.trades.

## Coverage

The table covers the following decentralized exchanges and their versions:

<div>
  <DuneEmbed qID={3453733} vID={5803813} height={600} />
</div>

## Table Schema

| Column                     | Type        | Description                                                         |
| -------------------------- | ----------- | ------------------------------------------------------------------- |
| `blockchain`               | `VARCHAR`   | Blockchain on which this trade occurred                             |
| `project`                  | `VARCHAR`   | Name of the DEX on which the trade occurred                         |
| `version`                  | `VARCHAR`   | Version of the DEX protocol/contract                                |
| `block_month`              | `DATE`      | UTC event block month (partition key)                               |
| `block_date`               | `DATE`      | UTC event block date                                                |
| `block_time`               | `TIMESTAMP` | UTC event block time                                                |
| `block_number`             | `BIGINT`    | Block number in which the trade occurred                            |
| `token_bought_symbol`      | `VARCHAR`   | Symbol of the token bought                                          |
| `token_sold_symbol`        | `VARCHAR`   | Symbol of the token sold                                            |
| `token_pair`               | `VARCHAR`   | Symbol pair for the tokens involved, always alphabetical order      |
| `token_bought_amount`      | `DOUBLE`    | Amount of the token bought in display units                         |
| `token_sold_amount`        | `DOUBLE`    | Amount of the token sold in display units                           |
| `token_bought_amount_raw`  | `UINT256`   | Raw amount of the token bought before decimal adjustment            |
| `token_sold_amount_raw`    | `UINT256`   | Raw amount of the token sold before decimal adjustment              |
| `amount_usd`               | `DOUBLE`    | USD value of the trade at time of execution                         |
| `token_bought_address`     | `VARBINARY` | Contract address of the token bought                                |
| `token_sold_address`       | `VARBINARY` | Contract address of the token sold                                  |
| `taker`                    | `VARBINARY` | Address that purchased tokens (can be contract or EOA)              |
| `maker`                    | `VARBINARY` | Address that sold tokens (can be contract or EOA)                   |
| `project_contract_address` | `VARBINARY` | Smart contract address which emitted the event (pool, router, etc.) |
| `tx_hash`                  | `VARBINARY` | Transaction hash                                                    |
| `tx_from`                  | `VARBINARY` | EOA address that sent the trade transaction                         |
| `tx_to`                    | `VARBINARY` | Address called in the first call of this transaction                |
| `evt_index`                | `BIGINT`    | Index of the event in the transaction                               |

## Table Sample

<TableSample tableSchema="dex" tableName="trades" />

## Examples

The following query demonstrates how to use the dex.trades table to calculate the total volume of trades on a weekly basis.

```sql theme={null}
SELECT
  blockchain,
  DATE_TRUNC('week', block_time),
  SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume
FROM
  dex."trades" AS t
WHERE
 block_time > NOW() - INTERVAL '365' day
GROUP BY 1,2
```

<div>
  <DuneEmbed qID={2180075} vID={3571504} height={500} />
</div>

<CardGroup cols={1}>
  <Card title="Dex Dashboard" icon="chart-waterfall" href="https://dune.com/dune/dex-metrics">
    For more examples of how to use the `dex.trades` table, check out this dashboard.
  </Card>
</CardGroup>
