Skip to content

Commit

Permalink
add support for native token metadata in dex pipeline (duneanalytics#…
Browse files Browse the repository at this point in the history
…7552)

* add support for native token metadata

* add native address env var
  • Loading branch information
jeff-dude authored Jan 27, 2025
1 parent de83cb5 commit de54ed6
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 10 deletions.
1 change: 1 addition & 0 deletions dbt_subprojects/dex/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ vars:
DBT_ENV_CUSTOM_ENV_S3_BUCKET: "{{ env_var('DBT_ENV_CUSTOM_ENV_S3_BUCKET', 'local') }}"
DBT_ENV_INCREMENTAL_TIME: "{{ env_var('DBT_ENV_INCREMENTAL_TIME', '1') }}"
DBT_ENV_INCREMENTAL_TIME_UNIT: "{{ env_var('DBT_ENV_INCREMENTAL_TIME_UNIT', 'day') }}"
ETH_ERC20_ADDRESS: '0x0000000000000000000000000000000000000000'

# These configurations specify where dbt should look for different types of files.
# You don't need to change these!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ WITH base_trades as (
{{ incremental_predicate('block_time') }}
{% endif %}
)
, tokens_metadata as (
--erc20 tokens
select
blockchain
, contract_address
, symbol
, decimals
from
{{ tokens_erc20_model }}
union all
--native tokens
select
blockchain
, {{var('ETH_ERC20_ADDRESS')}} as contract_address -- 0x00..00
, native_token_symbol as symbol
, 18 as decimals
from {{ source('evms','info') }}
)
, enrichments AS (
SELECT
base_trades.blockchain
Expand Down Expand Up @@ -48,11 +66,11 @@ WITH base_trades as (
FROM
base_trades
LEFT JOIN
{{ tokens_erc20_model }} as erc20_bought
tokens_metadata as erc20_bought
ON erc20_bought.contract_address = base_trades.token_bought_address
AND erc20_bought.blockchain = base_trades.blockchain
LEFT JOIN
{{ tokens_erc20_model }} as erc20_sold
tokens_metadata as erc20_sold
ON erc20_sold.contract_address = base_trades.token_sold_address
AND erc20_sold.blockchain = base_trades.blockchain
)
Expand Down
22 changes: 20 additions & 2 deletions dbt_subprojects/dex/macros/models/enrich_curve_dex_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ WITH base_trades as (
{{ incremental_predicate('block_time') }}
{% endif %}
)
, tokens_metadata as (
--erc20 tokens
select
blockchain
, contract_address
, symbol
, decimals
from
{{ tokens_erc20_model }}
union all
--native tokens
select
blockchain
, {{var('ETH_ERC20_ADDRESS')}} as contract_address -- 0x00..00
, native_token_symbol as symbol
, 18 as decimals
from {{ source('evms','info') }}
)
, enrichments AS (
SELECT
base_trades.blockchain
Expand Down Expand Up @@ -74,11 +92,11 @@ WITH base_trades as (
AND curve_optimism.tx_hash = base_trades.tx_hash
AND curve_optimism.evt_index = base_trades.evt_index
LEFT JOIN
{{ tokens_erc20_model }} as erc20_bought
tokens_metadata as erc20_bought
ON erc20_bought.contract_address = base_trades.token_bought_address
AND erc20_bought.blockchain = base_trades.blockchain
LEFT JOIN
{{ tokens_erc20_model }} as erc20_sold
tokens_metadata as erc20_sold
ON erc20_sold.contract_address = base_trades.token_sold_address
AND erc20_sold.blockchain = base_trades.blockchain
)
Expand Down
23 changes: 20 additions & 3 deletions dbt_subprojects/dex/macros/models/enrich_dex_aggregator_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,24 @@ WITH base_trades as (
{{ incremental_predicate('block_time') }}
{% endif %}
)

, tokens_metadata as (
--erc20 tokens
select
blockchain
, contract_address
, symbol
, decimals
from
{{ tokens_erc20_model }}
union all
--native tokens
select
blockchain
, {{var('ETH_ERC20_ADDRESS')}} as contract_address -- 0x00..00
, native_token_symbol as symbol
, 18 as decimals
from {{ source('evms','info') }}
)
, enrichments AS (
SELECT
base_trades.blockchain
Expand Down Expand Up @@ -50,11 +67,11 @@ WITH base_trades as (
FROM
base_trades
LEFT JOIN
{{ tokens_erc20_model }} as erc20_bought
tokens_metadata as erc20_bought
ON erc20_bought.contract_address = base_trades.token_bought_address
AND erc20_bought.blockchain = base_trades.blockchain
LEFT JOIN
{{ tokens_erc20_model }} as erc20_sold
tokens_metadata as erc20_sold
ON erc20_sold.contract_address = base_trades.token_sold_address
AND erc20_sold.blockchain = base_trades.blockchain
)
Expand Down
23 changes: 20 additions & 3 deletions dbt_subprojects/dex/macros/models/enrich_dex_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,24 @@ WITH base_trades as (
{{ incremental_predicate('block_time') }}
{% endif %}
)

, tokens_metadata as (
--erc20 tokens
select
blockchain
, contract_address
, symbol
, decimals
from
{{ tokens_erc20_model }}
union all
--native tokens
select
blockchain
, {{var('ETH_ERC20_ADDRESS')}} as contract_address -- 0x00..00
, native_token_symbol as symbol
, 18 as decimals
from {{ source('evms','info') }}
)
, enrichments AS (
SELECT
base_trades.blockchain
Expand Down Expand Up @@ -49,11 +66,11 @@ WITH base_trades as (
FROM
base_trades
LEFT JOIN
{{ tokens_erc20_model }} as erc20_bought
tokens_metadata as erc20_bought
ON erc20_bought.contract_address = base_trades.token_bought_address
AND erc20_bought.blockchain = base_trades.blockchain
LEFT JOIN
{{ tokens_erc20_model }} as erc20_sold
tokens_metadata as erc20_sold
ON erc20_sold.contract_address = base_trades.token_sold_address
AND erc20_sold.blockchain = base_trades.blockchain
)
Expand Down

0 comments on commit de54ed6

Please sign in to comment.