Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions dbt_subprojects/dex/models/trades/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,75 @@ models:
- &evt_index
name: evt_index
description: "Index of the event in the transaction. Can be used to uniquely identify the order of trades within in a transaction"

- name: dex_evm_trades
meta:
blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, kaia, optimism, polygon, scroll, zksync, linea, blast, sei, ronin, flare, boba, sonic, corn, berachain, sophon
sector: dex
short_description: DEX trades data across all EVM-compatible networks. Use this model when you need to query EVM DEX trades specifically, or use dex_multichain.trades if you need data from both EVM and non-EVM chains. This model contains the same data as dex.trades
contributors: kryptaki
config:
tags: [ 'dex', 'trades', 'evm']
description: '{{ doc("dex_trades_doc") }}'
columns:
- <<: *blockchain
- <<: *project
- <<: *version
- <<: *block_month
- <<: *block_date
- <<: *block_time
- <<: *block_number
- <<: *token_bought_symbol
- <<: *token_sold_symbol
- <<: *token_pair
- <<: *token_bought_amount
- <<: *token_sold_amount
- <<: *token_bought_amount_raw
- <<: *token_sold_amount_raw
- <<: *amount_usd
- <<: *token_bought_address
- <<: *token_sold_address
- <<: *taker
- <<: *maker
- <<: *project_contract_address
- <<: *tx_hash
- <<: *tx_from
- <<: *tx_to
- <<: *evt_index

- name: dex_multichain_trades
meta:
blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, kaia, optimism, polygon, scroll, zksync, linea, blast, sei, ronin, flare, boba, sonic, corn, berachain, sophon, solana
sector: dex
short_description: Detailed data on trades executed via decentralized exchanges (DEXs) across EVM-compatible chains and Solana. For EVM-only trades, use dex_evm.trades, and for Solana-only trades, use dex_solana.trades.
contributors: kryptaki
config:
tags: [ 'dex', 'trades', 'multichain']
description: >
Multichain DEX trades table combining EVM and Solana trades with standardized column names for cross-chain analysis.
columns:
- <<: *blockchain
- <<: *block_time
- <<: *block_date
- <<: *block_month
- name: block_number
description: "Block number in which the trade occurred. On Solana, this is the block slot."
- name: tx_id
description: "The hash of the transaction that this trade was included in (VARCHAR). On Solana, this is the tx_id."
- name: trader_id
description: "Address of the account which purchased tokens (VARCHAR). On EVM chains, this is the taker address."
- <<: *project
- name: executing_contract_address
description: "Address of the contract or program that executed the swap (VARCHAR). On Solana, this is the program_main_id (e.g. Pump.fun AMM or Raydium Liquidity Pool V4). On EVM chains this is the project_contract_address (which can be a pool contract, router/aggregator contract, singleton manager, or other contract associated with the DEX)."
- <<: *token_pair
- <<: *token_bought_symbol
- <<: *token_sold_symbol
- <<: *token_bought_amount
- <<: *token_sold_amount
- <<: *token_bought_amount_raw
- <<: *token_sold_amount_raw
- <<: *amount_usd
- name: token_bought_id
description: "Contract address of the token bought (VARCHAR). For EVM chains, this is token_bought_address. For Solana, this is token_bought_mint_address."
- name: token_sold_id
description: "Contract address of the token sold (VARCHAR). For EVM chains, this is token_sold_address. For Solana, this is token_sold_mint_address."
10 changes: 10 additions & 0 deletions dbt_subprojects/dex/models/trades/dex_evm_trades.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{ config(
schema = 'dex_evm'
, alias = 'trades'
, materialized = 'view'
)
}}

SELECT *
FROM {{ ref('dex_trades') }}

60 changes: 60 additions & 0 deletions dbt_subprojects/dex/models/trades/dex_multichain_trades.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{ config(
schema = 'dex_multichain'
, alias = 'trades'
, materialized = 'view'
)
}}

WITH

evm_trades AS (
SELECT
blockchain,
block_time,
block_date,
block_month,
block_number,
CAST(tx_hash AS VARCHAR) AS tx_id,
CAST(taker AS VARCHAR) AS trader_id,
project,
CAST(project_contract_address AS VARCHAR) AS executing_contract_address,
token_pair,
token_bought_symbol,
token_sold_symbol,
token_bought_amount,
token_sold_amount,
token_bought_amount_raw,
token_sold_amount_raw,
amount_usd,
CAST(token_bought_address AS VARCHAR) AS token_bought_id,
CAST(token_sold_address AS VARCHAR) AS token_sold_id
FROM {{ ref('dex_evm_trades') }}
),

solana_trades AS (
SELECT
'solana' AS blockchain,
block_time,
block_date,
block_month,
block_slot AS block_number,
tx_id,
trader_id,
project,
project_main_id AS executing_contract_address,
token_pair,
token_bought_symbol,
token_sold_symbol,
token_bought_amount,
token_sold_amount,
token_bought_amount_raw,
token_sold_amount_raw,
amount_usd,
token_bought_mint_address AS token_bought_id,
token_sold_mint_address AS token_sold_id
FROM {{ source('dex_solana', 'trades') }}
)

SELECT * FROM evm_trades
UNION ALL
SELECT * FROM solana_trades;