From 1da6fa44438cec840751ad90e44fe408790a6974 Mon Sep 17 00:00:00 2001 From: Carl Cervone <42869436+ccerv1@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:53:44 -0500 Subject: [PATCH] add: identify proxy interactions (#1597) * add: identify proxy interactions * add: proxy models for base and op * fix: include trace ids and get staging models to work * chore: proxies for other networks * fix: update proxy model to include to_ addresses --- warehouse/dbt/macros/models/known_proxies.sql | 82 +++++++++++++++++++ .../models/staging/base/stg_base__proxies.sql | 19 +++++ .../models/staging/frax/stg_frax__proxies.sql | 19 +++++ .../staging/metal/stg_metal__proxies.sql | 19 +++++ .../models/staging/mode/stg_mode__proxies.sql | 19 +++++ .../optimism/stg_optimism__proxies.sql | 19 +++++ .../models/staging/pgn/stg_pgn__proxies.sql | 19 +++++ .../models/staging/zora/stg_zora__proxies.sql | 19 +++++ 8 files changed, 215 insertions(+) create mode 100644 warehouse/dbt/macros/models/known_proxies.sql create mode 100644 warehouse/dbt/models/staging/base/stg_base__proxies.sql create mode 100644 warehouse/dbt/models/staging/frax/stg_frax__proxies.sql create mode 100644 warehouse/dbt/models/staging/metal/stg_metal__proxies.sql create mode 100644 warehouse/dbt/models/staging/mode/stg_mode__proxies.sql create mode 100644 warehouse/dbt/models/staging/optimism/stg_optimism__proxies.sql create mode 100644 warehouse/dbt/models/staging/pgn/stg_pgn__proxies.sql create mode 100644 warehouse/dbt/models/staging/zora/stg_zora__proxies.sql diff --git a/warehouse/dbt/macros/models/known_proxies.sql b/warehouse/dbt/macros/models/known_proxies.sql new file mode 100644 index 000000000..036cdfaea --- /dev/null +++ b/warehouse/dbt/macros/models/known_proxies.sql @@ -0,0 +1,82 @@ +{% macro known_proxies(network_name, start, traces="traces") %} + +{# + + This model is used to help identify smart contract accounts by looking for transactions that interact with the most widespread proxy contracts. + +#} + +with proxy_contracts as ( + select * + from UNNEST([ STRUCT + ( + 'SAFE' as proxy_type, + '1.4.1' as `version`, + LOWER('0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67') as factory_address + ), + ( + 'SAFE', + '1.3.0', + LOWER('0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC') + ), + ( + 'SAFE', + '1.1.1', + LOWER('0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B') + ), + ( + 'SAFE', + '1.0.0', + LOWER('0x12302fE9c02ff50939BaAaaf415fc226C078613C') + ), + ( + 'ENTRYPOINT', + '0.0.7', + LOWER('0x0000000071727De22E5E9d8BAf0edAc6f37da032') + ), + ( + 'ENTRYPOINT', + '0.0.6', + LOWER('0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789') + ) + ]) + +), +proxy_txns as ( + select + traces.id, + traces.block_timestamp, + traces.transaction_hash, + traces.from_address, + traces.to_address, + proxies.proxy_type, + case + when lower(traces.from_address) = lower(proxies.factory_address) + then traces.from_address + when lower(traces.to_address) = lower(proxies.factory_address) + then traces.to_address + else null + end as proxy_address + from {{ source(network_name, traces) }} as traces + inner join proxy_contracts as proxies + on lower(traces.from_address) = lower(proxies.factory_address) + or lower(traces.to_address) = lower(proxies.factory_address) + where + traces.block_timestamp >= {{ start }} + and traces.status = 1 + and traces.trace_type = 'call' + and traces.call_type != 'staticcall' + and traces.from_address != traces.to_address +) +select + id, + block_timestamp, + transaction_hash, + proxy_type, + proxy_address, + from_address, + to_address +from proxy_txns +where proxy_address is not null + +{% endmacro %} \ No newline at end of file diff --git a/warehouse/dbt/models/staging/base/stg_base__proxies.sql b/warehouse/dbt/models/staging/base/stg_base__proxies.sql new file mode 100644 index 000000000..1c8563246 --- /dev/null +++ b/warehouse/dbt/models/staging/base/stg_base__proxies.sql @@ -0,0 +1,19 @@ +{{ + config( + materialized='incremental', + partition_by={ + "field": "block_timestamp", + "data_type": "timestamp", + "granularity": "day", + }, + unique_key="id", + on_schema_change="append_new_columns", + incremental_strategy="insert_overwrite" + ) +}} +{% if is_incremental() %} + {% set start = "TIMESTAMP_SUB(_dbt_max_partition, INTERVAL 1 DAY)" %} +{% else %} + {% set start = "'1970-01-01'" %} +{% endif %} +{{ known_proxies("base", start) }} diff --git a/warehouse/dbt/models/staging/frax/stg_frax__proxies.sql b/warehouse/dbt/models/staging/frax/stg_frax__proxies.sql new file mode 100644 index 000000000..e03208d76 --- /dev/null +++ b/warehouse/dbt/models/staging/frax/stg_frax__proxies.sql @@ -0,0 +1,19 @@ +{{ + config( + materialized='incremental', + partition_by={ + "field": "block_timestamp", + "data_type": "timestamp", + "granularity": "day", + }, + unique_key="id", + on_schema_change="append_new_columns", + incremental_strategy="insert_overwrite" + ) +}} +{% if is_incremental() %} + {% set start = "TIMESTAMP_SUB(_dbt_max_partition, INTERVAL 1 DAY)" %} +{% else %} + {% set start = "'1970-01-01'" %} +{% endif %} +{{ known_proxies("frax", start) }} diff --git a/warehouse/dbt/models/staging/metal/stg_metal__proxies.sql b/warehouse/dbt/models/staging/metal/stg_metal__proxies.sql new file mode 100644 index 000000000..61d1da9be --- /dev/null +++ b/warehouse/dbt/models/staging/metal/stg_metal__proxies.sql @@ -0,0 +1,19 @@ +{{ + config( + materialized='incremental', + partition_by={ + "field": "block_timestamp", + "data_type": "timestamp", + "granularity": "day", + }, + unique_key="id", + on_schema_change="append_new_columns", + incremental_strategy="insert_overwrite" + ) +}} +{% if is_incremental() %} + {% set start = "TIMESTAMP_SUB(_dbt_max_partition, INTERVAL 1 DAY)" %} +{% else %} + {% set start = "'1970-01-01'" %} +{% endif %} +{{ known_proxies("metal", start) }} diff --git a/warehouse/dbt/models/staging/mode/stg_mode__proxies.sql b/warehouse/dbt/models/staging/mode/stg_mode__proxies.sql new file mode 100644 index 000000000..3accfa11d --- /dev/null +++ b/warehouse/dbt/models/staging/mode/stg_mode__proxies.sql @@ -0,0 +1,19 @@ +{{ + config( + materialized='incremental', + partition_by={ + "field": "block_timestamp", + "data_type": "timestamp", + "granularity": "day", + }, + unique_key="id", + on_schema_change="append_new_columns", + incremental_strategy="insert_overwrite" + ) +}} +{% if is_incremental() %} + {% set start = "TIMESTAMP_SUB(_dbt_max_partition, INTERVAL 1 DAY)" %} +{% else %} + {% set start = "'1970-01-01'" %} +{% endif %} +{{ known_proxies("mode", start) }} diff --git a/warehouse/dbt/models/staging/optimism/stg_optimism__proxies.sql b/warehouse/dbt/models/staging/optimism/stg_optimism__proxies.sql new file mode 100644 index 000000000..110e4615c --- /dev/null +++ b/warehouse/dbt/models/staging/optimism/stg_optimism__proxies.sql @@ -0,0 +1,19 @@ +{{ + config( + materialized='incremental', + partition_by={ + "field": "block_timestamp", + "data_type": "timestamp", + "granularity": "day", + }, + unique_key="id", + on_schema_change="append_new_columns", + incremental_strategy="insert_overwrite" + ) +}} +{% if is_incremental() %} + {% set start = "TIMESTAMP_SUB(_dbt_max_partition, INTERVAL 1 DAY)" %} +{% else %} + {% set start = "'1970-01-01'" %} +{% endif %} +{{ known_proxies("superchain", start, traces="optimism_traces") }} diff --git a/warehouse/dbt/models/staging/pgn/stg_pgn__proxies.sql b/warehouse/dbt/models/staging/pgn/stg_pgn__proxies.sql new file mode 100644 index 000000000..9f3ddc86e --- /dev/null +++ b/warehouse/dbt/models/staging/pgn/stg_pgn__proxies.sql @@ -0,0 +1,19 @@ +{{ + config( + materialized='incremental', + partition_by={ + "field": "block_timestamp", + "data_type": "timestamp", + "granularity": "day", + }, + unique_key="id", + on_schema_change="append_new_columns", + incremental_strategy="insert_overwrite" + ) +}} +{% if is_incremental() %} + {% set start = "TIMESTAMP_SUB(_dbt_max_partition, INTERVAL 1 DAY)" %} +{% else %} + {% set start = "'1970-01-01'" %} +{% endif %} +{{ known_proxies("pgn", start) }} diff --git a/warehouse/dbt/models/staging/zora/stg_zora__proxies.sql b/warehouse/dbt/models/staging/zora/stg_zora__proxies.sql new file mode 100644 index 000000000..ecc50ad36 --- /dev/null +++ b/warehouse/dbt/models/staging/zora/stg_zora__proxies.sql @@ -0,0 +1,19 @@ +{{ + config( + materialized='incremental', + partition_by={ + "field": "block_timestamp", + "data_type": "timestamp", + "granularity": "day", + }, + unique_key="id", + on_schema_change="append_new_columns", + incremental_strategy="insert_overwrite" + ) +}} +{% if is_incremental() %} + {% set start = "TIMESTAMP_SUB(_dbt_max_partition, INTERVAL 1 DAY)" %} +{% else %} + {% set start = "'1970-01-01'" %} +{% endif %} +{{ known_proxies("zora", start) }}