Skip to main content
Schema: flow.defi Table: fact_dex_swaps Type: View

Description

Records all decentralized exchange (DEX) swap transactions on the Flow blockchain. Captures the full context of each swap, including trader, pool, token in/out, amounts, and protocol metadata. Data is sourced from on-chain swap events and normalized for analytics, supporting both single-pool and multi-hop swaps.

Key Use Cases

  • Analyze DEX trading activity and swap volume
  • Track user participation and trading behavior
  • Attribute swaps to specific pools and protocols
  • Support price impact, slippage, and liquidity analysis
  • Power DeFi dashboards and market research

Important Relationships

  • Linked to defi__ez_dex_swaps for enriched analytics (adds token symbols, USD values)
  • Can be joined with defi__dim_swap_pool_labels for pool metadata
  • Protocol attribution via platform and contract_address fields
  • Token-level analytics via token_in/token_out and amounts

Commonly-used Fields

  • tx_id: Unique transaction identifier for swap event
  • block_timestamp: When the swap occurred
  • contract_address: DEX pool contract address
  • swap_index: Order of swap in multi-hop transactions
  • trader: Account address of the swap initiator
  • token_out / token_in: Token contract addresses swapped out/in
  • amount_out / amount_in: Amounts swapped (decimal adjusted)
  • platform: Name of the DEX protocol

Columns

Column NameData TypeDescription
TX_IDTEXTThe unique identifier (hash) for a transaction on the Flow blockchain. Data type: STRING. Each transaction is assigned a cryptographic hash that ensures its uniqueness and immutability. Used for joining transaction data across tables, tracing transaction execution, and verifying transaction integrity. Example: ‘e3f1c2d4…’. Essential for transaction-level analytics, debugging, and cross-referencing with block and event data.
BLOCK_TIMESTAMPTIMESTAMP_NTZThe timestamp (in UTC) when the block or transaction was recorded on the Flow blockchain. Data type: TIMESTAMP_NTZ. This field is essential for time-series analysis, ordering events, and joining with other tables by time. For example, a block with block_height 100,000 may have a block_timestamp of ‘2023-01-01 12:00:00’. Used for analytics on network activity, transaction throughput, and historical state reconstruction.
BLOCK_HEIGHTNUMBERBlock height is the unique, sequential integer assigned to each block as it is added to the Flow blockchain. It serves as the primary identifier for block ordering and is used to reference the position of a block within the chain. Data type: INTEGER. Block height is essential for joining block, transaction, and event tables, and for analyzing blockchain growth over time. For example, block height 100,000 refers to the 100,000th block produced on Flow. This field is critical for time-series analytics, chain reorganization analysis, and historical state reconstruction.
CONTRACT_ADDRESSTEXTThe smart contract address of the DEX swap pool or liquidity pool involved in the transaction. Data type: STRING. This field identifies the specific contract facilitating the swap, which is essential for protocol attribution, pool-level analytics, and tracing liquidity movements. For Metapier swaps, all pools may use the same master contract (e.g., ‘A.609e10301860b683.PierPair’), so the ‘pool_id’ is required to differentiate between pools. Example: ‘A.609e10301860b683.PierPair’ for Metapier, or a unique contract address for other DEXs. Important for understanding liquidity routing, protocol usage, and swap path analysis.
SWAP_INDEXNUMBERThe position of the swap within a transaction, indicating the order of execution in multi-hop or multi-pool swaps. Data type: NUMBER (integer). The first swap in a transaction is indexed at 0. If a transaction routes through multiple pools, each swap is assigned an incrementing index (e.g., 0, 1, 2). Used to reconstruct swap paths, analyze routing strategies, and understand complex DeFi trades. Example: A single-pool swap has swap_index 0; a two-pool route has swaps with indices 0 and 1. Important for path analysis, DEX routing analytics, and multi-hop trade reconstruction.
TRADERTEXTThe account address of the trader performing the swap action.
PLATFORMTEXTThe name of the protocol, platform, or DEX where the event (swap, trade, or other DeFi action) occurred. Data type: STRING. Used to attribute activity to a specific protocol (e.g., ‘blocto’, ‘metapier’, ‘topshot_marketplace’) for analytics, filtering, and reporting. This field is essential for protocol-level analysis, market share tracking, and understanding user behavior across DeFi platforms. Example: ‘blocto’ for BloctoSwap, ‘metapier’ for Metapier DEX. Important for protocol attribution, competitive analysis, and cross-platform comparisons.
ORIGIN_FROM_ADDRESSTEXTThe address from which the token is withdrawn (“token out”) in a DEX swap. Data type: STRING. For the first swap in a transaction, this is typically the trader’s address; for subsequent swaps in a multi-hop route, it may be a pool address. Used to trace token flow and participant roles in swaps. Example: ‘0x1cf0e2f2f715450’ (trader) or a pool address for later hops. Important for swap path analysis and wallet attribution.
TOKEN_OUTTEXTThe smart contract address for the token being swapped out of the trader’s wallet (or previous pool) in a DEX swap. Data type: STRING. Used to identify the specific token being sent out, supporting token-level analytics and swap path tracing. Example: ‘A.1654653399040a61.FlowToken’. Directionality is always from the trader to the pool or next hop in multi-pool swaps.
AMOUNT_OUTFLOATThe amount of tokens sent out from the trader’s wallet (or previous pool) in a DEX swap. Data type: NUMBER (decimal adjusted). Represents the quantity of the “out” token in the swap, from the trader’s perspective. Used for volume analysis, price impact, and swap path tracing. Example: 50.0 (for 50 tokens swapped out). Directionality is always from the trader to the pool or next hop in multi-pool swaps.
ORIGIN_TO_ADDRESSTEXTThe address receiving the token being swapped in (“token in”) during a DEX swap. Data type: STRING. For the initial deposit, this is typically the pool address; for the final swap, it is usually the trader’s address. Used to trace token flow, swap completion, and participant roles. Example: pool address for intermediate hops, trader address for final destination. Important for swap path analysis and wallet attribution.
TOKEN_INTEXTThe smart contract address for the token that is being swapped into the traders wallet.
Token OUT / IN is from the perspective of the trader. So, an out token is leaving the wallet while the in token is being deposited to the wallet. This perspective is not changing for multi-pool trades - think of it directionally, the tokens continue flowing from out to in. Out of wallet, into pool, out of pool, into (another pool / wallet), with the final movement being tokens into final wallet.
AMOUNT_INFLOATThe amount of tokens received by the trader (or next pool) in a DEX swap. Data type: NUMBER (decimal adjusted). Represents the quantity of the “in” token in the swap, from the trader’s perspective. Used for volume analysis, price impact, and swap path tracing. Example: 49.5 (for 49.5 tokens received). Directionality is always from the pool to the trader or next hop in multi-pool swaps.
FACT_DEX_SWAPS_IDTEXTpk_id is a surrogate primary key, uniquely generated for each row in the table. Data type: STRING or INTEGER (implementation-specific). This field ensures every record is uniquely identifiable, even if the source data lacks a natural primary key. Used for efficient joins, deduplication, and as a reference in downstream models. Example: an auto-incremented integer or a UUID string. Essential for maintaining data integrity and supporting dbt tests for uniqueness.
INSERTED_TIMESTAMPTIMESTAMP_NTZThe UTC timestamp when the record was first created and inserted into this table. Data type: TIMESTAMP_NTZ. Used for ETL auditing, tracking data freshness, and identifying when data was loaded or updated in the analytics pipeline. Example: ‘2023-01-01 12:00:00’. This field is critical for monitoring data latency, troubleshooting ETL issues, and supporting recency tests in dbt.
MODIFIED_TIMESTAMPTIMESTAMP_NTZThe UTC timestamp when this record was last updated or modified by an internal ETL or dbt process. Data type: TIMESTAMP_NTZ. Used for change tracking, ETL auditing, and identifying the most recent update to a record. Example: ‘2023-01-02 15:30:00’. This field is important for troubleshooting data issues, monitoring pipeline health, and supporting recency or freshness tests in dbt.