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

# 鏈分組

> Cubes 如何被組織到 EVM、Solana 與 Trading Chain Groups 中

## 概述

ChainStream GraphQL 將其 25 個 Cube 劃分為三個 **鏈組（Chain Groups）**。每個組代表一類區塊鏈生態，決定可用的 Cube、`network` 引數如何生效，以及存在哪些鏈特有欄位。

```graphql theme={null}
type ChainStream {
  EVM(network: Network!, dataset: Dataset, aggregates: Aggregates) { ... }
  Solana(network: SolanaNetwork, dataset: Dataset, aggregates: Aggregates) { ... }
  Trading(dataset: Dataset, aggregates: Aggregates) { ... }
}
```

***

## EVM

**EVM** 組包含適用於所有 EVM 相容鏈的 Cube。查詢時 **必須** 提供 `network` 引數以指定鏈。

### 可用網路

| 網路 ID     | 區塊鏈             |
| :-------- | :-------------- |
| `eth`     | Ethereum        |
| `bsc`     | BNB Chain (BSC) |
| `polygon` | Polygon         |

<Warning>
  **Polygon 資料可用性：** 目前僅有 **預測市場** 相關 Cube（`PredictionTrades`、`PredictionManagements`、`PredictionSettlements`）在 Polygon 上有資料。其他 Cube（DEXTrades、Blocks、Transfers 等）正在部署中 —— 對它們的查詢可能返回錯誤。
</Warning>

### Cubes

**與 Solana 共用：**
`DEXTrades`、`DEXTradeByTokens`、`Transfers`、`BalanceUpdates`、`DEXPoolEvents`、`TokenSupplyUpdates`、`Blocks`、`Transactions`、`TransactionBalances`、`DEXPools`、`TokenHolders`、`WalletTokenPnL`

**僅 EVM：**

* `Events` — 智慧合約事件日誌（已解碼的 topic 與 data）
* `Calls` — 內部呼叫追蹤（CALL、DELEGATECALL、CREATE 等）
* `MinerRewards` — 出塊獎勵明細（靜態、動態、叔塊、銷燬手續費等）
* `DEXPoolSlippages` — 池子價格滑點分析
* `Uncles` — 叔塊資料（主要為以太坊 PoW 歷史）
* `PredictionTrades` — 預測市場交易 *（主要為 Polygon）*
* `PredictionManagements` — 預測市場管理事件 *（主要為 Polygon）*
* `PredictionSettlements` — 預測市場結算 *（主要為 Polygon）*

### 示例查詢

```graphql theme={null}
query {
  EVM(network: eth, dataset: combined) {
    DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
    ) {
      Block { Time Number }
      Transaction { Hash }
      Trade {
        Buy { Currency { SmartContract Symbol } Amount PriceInUSD }
        Sell { Currency { SmartContract Symbol } Amount }
        Dex { ProtocolName }
      }
    }
  }
}
```

***

## Solana

**Solana** 組包含 Solana 鏈上的 Cube。`network` 引數可用，接受 `solana` 作為值。該引數為可選，預設值為 `solana`。

### Cubes

**與 EVM 共用：**
`DEXTrades`、`DEXTradeByTokens`、`Transfers`、`BalanceUpdates`、`DEXPoolEvents`、`TokenSupplyUpdates`、`Blocks`、`Transactions`、`TransactionBalances`、`DEXPools`、`TokenHolders`、`WalletTokenPnL`

**僅 Solana：**

* `Instructions` — 程式指令資料（程式地址、方法、賬戶、日誌）
* `InstructionBalanceUpdates` — 指令級別的餘額變動
* `Rewards` — 驗證者與質押獎勵
* `DEXOrders` — DEX 訂單簿事件（限價單、撤單、成交）

### 示例查詢

```graphql theme={null}
query {
  Solana(dataset: realtime) {
    DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
    ) {
      Block { Time Slot }
      Transaction { Hash }
      Trade {
        Buy { Currency { MintAddress Symbol } Amount PriceInUSD }
        Sell { Currency { MintAddress Symbol } Amount }
        Dex { ProgramAddress ProtocolName }
      }
    }
  }
}
```

### 跨鏈欄位命名

下表列出各鏈的慣用欄位名。但 Record 型別會包含 **所有鏈欄位的並集** —— 每個 Cube 的 Record 中同時存在 `MintAddress` 與 `SmartContract`，底層資料一致。任意鏈上均可使用其中任一名稱。

| 概念     | 慣用（Solana）           | 慣用（EVM）         | 跨鏈通用？ |
| :----- | :------------------- | :-------------- | :---- |
| 代幣地址   | `MintAddress`        | `SmartContract` | 各鏈均可  |
| 交易 ID  | `Signature` / `Hash` | `Hash`          | 各鏈均可  |
| 區塊標識   | `Slot`               | `Number`        | 各鏈均可  |
| 程式/合約  | `ProgramAddress`     | `SmartContract` | 各鏈均可  |
| 手續費支付方 | `FeePayer`           | `From`          | 各鏈均可  |

<Tip>
  因此你可以用 **同一套查詢模板** 跨鏈查詢而無需改欄位名。例如 `Currency { MintAddress }` 在 Solana 與 EVM 查詢中均可使用。
</Tip>

***

## Trading

**Trading** 組提供 **跨鏈預聚合** 的交易分析資料。它將各支援鏈的資料合併為統一物化檢視，並透過 `chain` 維度做篩選。

### Cubes

* `Pairs` — OHLC K 線（開高低收、成交量、成交筆數）
* `Tokens` — 按代幣的交易統計（成交量、買賣拆分、獨立交易者數）

### 與 EVM / Solana 組的主要區別

1. **無 `network` 引數** — Trading 組跨鏈彙總資料，請在資料內用 `chain` 維度按網路過濾。
2. **跨鏈資料** — 單次查詢可同時返回 `sol`、`eth`、`bsc` 等。
3. **預聚合** — 資料來自 DWM 層，按分鐘粒度物化。

### 示例：跨鏈 OHLC

```graphql theme={null}
query {
  Trading(aggregates: yes) {
    Pairs(
      where: { Token: { Address: { is: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" } } }
      limit: {count: 60}
      orderBy: {descending: Block_Time}
    ) {
      Token { Address }
      Market { Network }
      Interval { Time }
      Price { Ohlc { Open High Low Close } }
      Volume { Usd Native }
      Stats { TradeCount BuyCount SellCount }
    }
  }
}
```

### 示例：按鏈的代幣成交統計

```graphql theme={null}
query {
  Trading {
    Tokens(
      where: {
        Token: { Address: { is: "0xdac17f958d2ee523a2206206994597c13d831ec7" } }
        Market: { Network: { is: "eth" } }
      }
      limit: {count: 30}
      orderBy: {descending: Block_Time}
    ) {
      Interval { Time }
      Volume { Usd BuyVolumeUSD SellVolumeUSD }
      Stats { TradeCount UniqueBuyers UniqueSellers }
    }
  }
}
```

***

## 鏈組對比

| 特性                  | EVM                                                            | Solana                                                   | Trading      |
| :------------------ | :------------------------------------------------------------- | :------------------------------------------------------- | :----------- |
| **`network` 引數**    | 必填（`eth`、`bsc`、`polygon`）                                      | 可選（`solana`，預設 `solana`）                                 | 不需要（跨鏈）      |
| **獨有 Cube**         | Events、Calls、MinerRewards、Uncles、DEXPoolSlippages、Prediction\* | Instructions、InstructionBalanceUpdates、Rewards、DEXOrders | Pairs、Tokens |
| **資料粒度**            | 逐事件（DWD）+ 聚合（DWM/DWS）                                          | 逐事件 + 指令級                                                | 預聚合（DWM）     |
| **`dataset` 支援**    | 是（多數 Cube）                                                     | 是（多數 Cube）                                               | 是            |
| **`aggregates` 支援** | 是                                                              | 是                                                        | 是            |

***

## 相關文件

<CardGroup cols={2}>
  <Card title="資料 Cubes" icon="cubes" href="/zh-Hant/graphql/schema/cubes">
    全部 25 個 Cube 的欄位結構與使用場景詳解。
  </Card>

  <Card title="Dataset 與 Aggregates" icon="database" href="/zh-Hant/graphql/schema/dataset-aggregates">
    控制資料來源範圍與預聚合行為。
  </Card>
</CardGroup>
