diff --git a/warehouse/dbt/macros/models/contract_invocation_events_with_l1.sql b/warehouse/dbt/macros/models/contract_invocation_events_with_l1.sql index 21f4e051c..a5c285a01 100644 --- a/warehouse/dbt/macros/models/contract_invocation_events_with_l1.sql +++ b/warehouse/dbt/macros/models/contract_invocation_events_with_l1.sql @@ -52,6 +52,10 @@ contract_invocations as ( COUNT(*) as total_count, SUM(case when receipt_status = 1 then 1 else 0 end) as success_count from all_transactions + where to_artifact_id not in ( + select artifact_id + from {{ ref('int_safes') }} + ) group by time, to_artifact_id, diff --git a/warehouse/dbt/models/intermediate/directory/int_safes.sql b/warehouse/dbt/models/intermediate/directory/int_safes.sql new file mode 100644 index 000000000..88701ad68 --- /dev/null +++ b/warehouse/dbt/models/intermediate/directory/int_safes.sql @@ -0,0 +1,41 @@ +{{ + config( + materialized='table' + ) +}} + +{% set networks = ["optimism", "base", "frax", "metal", "mode", "zora"] %} + +{% set union_queries = [] %} + +{% for network in networks %} + {% set table_name = "stg_" ~ network ~ "__proxies" %} + {% set network_upper = network.upper() %} + + {% set query %} + select + lower(to_address) as `address`, + '{{ network_upper }}' as network, + min(block_timestamp) as created_date + from {{ ref(table_name) }} + where + proxy_type = "SAFE" + and proxy_address != to_address + group by to_address + {% endset %} + + {% do union_queries.append(query) %} +{% endfor %} + +{% set final_query = union_queries | join(' union all ') %} + +with safes as ( + {{ final_query }} +) + +select + {{ oso_id("network", "address") }} as artifact_id, + address, + network, + created_date +from safes