diff --git a/warehouse/dbt/models/marts/superchain/verification/rf4_contracts_by_app.sql b/warehouse/dbt/models/marts/superchain/verification/rf4_contracts_by_app.sql index a4c438cbf..950264eac 100644 --- a/warehouse/dbt/models/marts/superchain/verification/rf4_contracts_by_app.sql +++ b/warehouse/dbt/models/marts/superchain/verification/rf4_contracts_by_app.sql @@ -1,4 +1,30 @@ -with contracts as ( +{% set networks = ["optimism", "base", "frax", "metal", "mode", "zora"] %} + +{% set union_factory_queries = [] %} + +{% for network in networks %} + + {% set network_upper = network.upper() %} + + {% set factory_table = "stg_" ~ network ~ "__factories" %} + {% set query %} + select + factory_address, + contract_address, + '{{ network_upper }}' as network + from {{ ref(factory_table) }} + {% endset %} + {% do union_factory_queries.append(query) %} + +{% endfor %} + +{% set all_factories = union_factory_queries | join(' union all ') %} + +with factories as ( + {{ all_factories }} +), + +app_contracts as ( select application_id, project_name, @@ -18,6 +44,37 @@ with contracts as ( discovery_method from {{ ref('rf4_agora_contract_discovery') }} where artifact_type = 'CONTRACT' +), + +discovered_contracts as ( + select + app_contracts.application_id, + app_contracts.project_name, + factories.contract_address as address, + factories.network, + 'CONTRACT' as artifact_type, + 'discovered_contract_from_verified_factory' as discovery_method + from factories + left join app_contracts + on + factories.factory_address = app_contracts.address + and factories.network = app_contracts.network +), + +contracts as ( + select + application_id, + address, + network, + discovery_method + from discovered_contracts + union all + select + application_id, + address, + network, + discovery_method + from app_contracts ) select distinct diff --git a/warehouse/dbt/models/marts/superchain/verification/rf4_oso_contract_discovery.sql b/warehouse/dbt/models/marts/superchain/verification/rf4_oso_contract_discovery.sql index e1f6bd202..eb4ef22c7 100644 --- a/warehouse/dbt/models/marts/superchain/verification/rf4_oso_contract_discovery.sql +++ b/warehouse/dbt/models/marts/superchain/verification/rf4_oso_contract_discovery.sql @@ -1,7 +1,7 @@ with projects as ( select apps.application_id, - current_projects.project_name, + apps.project_name, current_projects.blockchain from {{ source('static_data_sources', 'agora_rf4_applications') }} as apps left join