Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: adjust fork maps to avoid decoding pipeline #7183

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% macro uniswap_v2_forks_trades(
blockchain = null
, dex_type = 'uni-v2'
, project = null
, version = null
, Pair_evt_Swap = null
, Factory_evt_PairCreated = null
Expand Down Expand Up @@ -55,7 +54,6 @@ WITH evt_swap AS (
, base_trades AS (
SELECT
'{{ blockchain }}' AS blockchain
, '{{project}}' AS project
, '{{ version }}' AS version
, '{{dex_type}}' AS dex_type
, CAST(date_trunc('month', dexs.block_time) AS date) AS block_month
Expand All @@ -77,7 +75,8 @@ WITH evt_swap AS (
)

SELECT base_trades.blockchain
, COALESCE(contracts.namespace, base_trades.project) AS project
, CASE when dex_map.project_name is not NULL then dex_map.project_name else concat('unknown-uni-v2-', cast(varbinary_substring(base_trades.factory_address, 1, 5) as varchar)) end as project
, CASE when dex_map.project_name is not NULL then true else false end as project_status
, base_trades.version
, base_trades.dex_type
, base_trades.factory_address
Expand Down Expand Up @@ -109,16 +108,9 @@ INNER JOIN (
ON transfers.tx_hash = base_trades.tx_hash
AND contains(transfers.contract_addresses, base_trades.token_bought_address)
AND contains(transfers.contract_addresses, base_trades.token_sold_address)
LEFT JOIN (
SELECT
address,
blockchain,
namespace
FROM {{ source('evms', 'contracts') }}
WHERE blockchain = '{{ blockchain }}'
AND namespace IS NOT NULL
) AS contracts
ON base_trades.project_contract_address = contracts.address
AND base_trades.blockchain = contracts.blockchain
LEFT JOIN {{ ref('dex_mapping') }} AS dex_map
ON base_trades.factory_address = dex_map.factory_address
AND base_trades.blockchain = dex_map.blockchain
where block_date >= DATE ('2024-06-01')

{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% macro uniswap_v3_forks_trades(
blockchain = null
, dex_type = 'uni-v3'
, project = null
, version = null
, Pair_evt_Swap = null
, Factory_evt_PoolCreated = null
Expand Down Expand Up @@ -62,7 +61,6 @@ WITH evt_swap AS (
, base_trades AS (
SELECT
'{{ blockchain }}' AS blockchain
, '{{ project }}' AS project
, '{{ version }}' AS version
, '{{dex_type}}' AS dex_type
, CAST(date_trunc('month', dexs.block_time) AS date) AS block_month
Expand All @@ -84,7 +82,8 @@ WITH evt_swap AS (
)

SELECT base_trades.blockchain
, COALESCE(contracts.namespace, base_trades.project) AS project
, CASE when dex_map.project_name is not NULL then dex_map.project_name else concat('unknown-uni-v3-', cast(varbinary_substring(base_trades.factory_address, 1, 5) as varchar)) end as project
, CASE when dex_map.project_name is not NULL then true else false end as project_status
Comment on lines +85 to +86
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// These two lines mark if a project address is recorded in the static mapping.

, base_trades.version
, base_trades.dex_type
, base_trades.factory_address
Expand Down Expand Up @@ -116,16 +115,8 @@ INNER JOIN (
ON transfers.tx_hash = base_trades.tx_hash
AND contains(transfers.contract_addresses, base_trades.token_bought_address)
AND contains(transfers.contract_addresses, base_trades.token_sold_address)
LEFT JOIN (
SELECT
address,
blockchain,
namespace
FROM {{ source('evms', 'contracts') }}
WHERE blockchain = '{{ blockchain }}'
AND namespace IS NOT NULL
) AS contracts
ON base_trades.project_contract_address = contracts.address
AND base_trades.blockchain = contracts.blockchain

LEFT JOIN {{ ref('dex_mapping') }} AS dex_map
ON base_trades.factory_address = dex_map.factory_address
AND base_trades.blockchain = dex_map.blockchain
where block_date >= DATE ('2024-06-01')
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ WITH base_trades as (
SELECT
base_trades.blockchain
, base_trades.project
, base_trades.project_status
, base_trades.version
, base_trades.factory_address
, base_trades.dex_type
Expand Down Expand Up @@ -71,6 +72,7 @@ WITH base_trades as (
SELECT
blockchain
, project
, project_status
, version
, factory_address
, dex_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ WITH base_union AS (
SELECT
blockchain
, project
, project_status
, version
, dex_type
, factory_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
uniswap_v2_forks_trades(
blockchain = 'arbitrum'
, version = '2'
, project = 'null'
, Pair_evt_Swap = ref('uniswap_v2_arbitrum_decoded_pool_evt_swap')
, Factory_evt_PairCreated = ref('uniswap_v2_arbitrum_decoded_factory_evt')
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
uniswap_v3_forks_trades(
blockchain = 'arbitrum'
, version = '3'
, project = 'null'
, Pair_evt_Swap = ref('uniswap_v3_arbitrum_decoded_pool_evt_swap')
, Factory_evt_PoolCreated = ref('uniswap_v3_arbitrum_decoded_factory_evt')
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
version: 2

models:
- name: dex_base_automated_base_trades
description: "all dex trades on base, mass decoded"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index

- name: uniswap_v2_base_decoded_factory_evt
description: >
mass decoding of all forks of uniswap v2 factory contract on base
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- index

- name: uniswap_v2_base_decoded_pool_evt_swap
description: >
mass decoding of all forks of uniswap v2 pool contracts on base
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- index

- name: uniswap_v2_base_automated_base_trades
meta:
blockchain: base
sector: dex
project: uniswap
contributors: 0xboxer
config:
tags: [ 'base', 'dex', 'trades', 'uniswap', 'v2', 'forks' ]
description: "base trades for all forks of uniswap v2 on base"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index

- name: uniswap_v3_base_decoded_factory_evt
description: >
mass decoding of all forks of uniswap v3 factory contract on base
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- index

- name: uniswap_v3_base_decoded_pool_evt_swap
description: >
mass decoding of all forks of uniswap v3 pool contracts on base
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- index

- name: uniswap_v3_base_automated_base_trades
meta:
blockchain: base
sector: dex
project: uniswap
contributors: 0xboxer
config:
tags: [ 'base', 'dex', 'trades', 'uniswap', 'v3', 'forks' ]
description: "base trades for all forks of uniswap v3 on base"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{ config(
schema = 'dex_base'
, alias = 'automated_base_trades'
, materialized = 'view'
)
}}

{% set base_models = [
ref('uniswap_v2_base_automated_base_trades')
, ref('uniswap_v3_base_automated_base_trades')
] %}

WITH base_union AS (
SELECT *
FROM (
{% for base_model in base_models %}
SELECT
blockchain
, project
, project_status
, version
, dex_type
, factory_address
, block_month
, block_date
, block_time
, block_number
, token_bought_amount_raw
, token_sold_amount_raw
, token_bought_address
, token_sold_address
, taker
, maker
, project_contract_address
, tx_hash
, evt_index
FROM
{{ base_model }}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
)
)

{{
add_tx_columns(
model_cte = 'base_union'
, blockchain = 'base'
, columns = ['from', 'to', 'index']
)
}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{ config(
schema = 'uniswap_v2_base',
alias = 'automated_base_trades',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['tx_hash', 'evt_index'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)
}}

{{
uniswap_v2_forks_trades(
blockchain = 'base'
, version = '2'
, Pair_evt_Swap = ref('uniswap_v2_base_decoded_pool_evt_swap')
, Factory_evt_PairCreated = ref('uniswap_v2_base_decoded_factory_evt')
)
}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ config(
schema = 'uniswap_v2_base',
alias = 'decoded_factory_evt',
partition_by = ['block_date'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['tx_hash', 'index'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)
}}

{{uniswap_v2_factory_event_decoding(
logs = source('base', 'logs')
)}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ config(
schema = 'uniswap_v2_base',
alias = 'decoded_pool_evt_swap',
partition_by = ['block_date'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['tx_hash', 'index'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)
}}

{{uniswap_v2_pool_event_decoding(
logs = source('base', 'logs')
)}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{ config(
schema = 'uniswap_v3_base',
alias = 'automated_base_trades',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['tx_hash', 'evt_index'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)
}}

{{
uniswap_v3_forks_trades(
blockchain = 'base'
, version = '3'
, Pair_evt_Swap = ref('uniswap_v3_base_decoded_pool_evt_swap')
, Factory_evt_PoolCreated = ref('uniswap_v3_base_decoded_factory_evt')
)
}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ config(
schema = 'uniswap_v3_base',
alias = 'decoded_factory_evt',
partition_by = ['block_date'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['tx_hash', 'index'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)
}}

{{uniswap_v3_factory_event_decoding(
logs = source('base', 'logs')
)}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ config(
schema = 'uniswap_v3_base',
alias = 'decoded_pool_evt_swap',
partition_by = ['block_date'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['tx_hash', 'index'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)
}}

{{uniswap_v3_pool_event_decoding(
logs = source('base', 'logs')
)}}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{% set models = [
ref('dex_ethereum_automated_base_trades')
, ref('dex_arbitrum_automated_base_trades')
, ref('dex_base_automated_base_trades')
] %}

with base_union as (
Expand All @@ -23,6 +24,7 @@ with base_union as (
SELECT
blockchain
, project
, project_status
, version
, factory_address
, dex_type
Expand Down
Loading
Loading