diff --git a/apps/hasura/metadata/databases/cloudsql/tables/contracts_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/contracts_v1.yaml new file mode 100644 index 000000000..8df40878c --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/contracts_v1.yaml @@ -0,0 +1,22 @@ +table: + name: contracts_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/tables.yaml b/apps/hasura/metadata/databases/cloudsql/tables/tables.yaml index 8d3c4689d..08131ab61 100644 --- a/apps/hasura/metadata/databases/cloudsql/tables/tables.yaml +++ b/apps/hasura/metadata/databases/cloudsql/tables/tables.yaml @@ -2,6 +2,7 @@ - "!include artifacts_v1.yaml" - "!include code_metrics_by_project_v1.yaml" - "!include collections_v1.yaml" +- "!include contracts_v1.yaml" - "!include event_indexing_status_by_project_v1.yaml" - "!include event_types_v1.yaml" - "!include events_daily_to_artifact.yaml" diff --git a/warehouse/dbt/models/intermediate/directory/int_contracts.sql b/warehouse/dbt/models/intermediate/directory/int_contracts.sql new file mode 100644 index 000000000..71b131eed --- /dev/null +++ b/warehouse/dbt/models/intermediate/directory/int_contracts.sql @@ -0,0 +1,94 @@ +with deployers as ( + select + *, + 'OPTIMISM' as artifact_source + from {{ ref('stg_optimism__deployers') }} + union all + select + *, + 'BASE' as artifact_source + from {{ ref('stg_base__deployers') }} + union all + select + *, + 'FRAX' as artifact_source + from {{ ref('stg_frax__deployers') }} + union all + select + *, + 'MODE' as artifact_source + from {{ ref('stg_mode__deployers') }} + union all + select + *, + 'ZORA' as artifact_source + from {{ ref('stg_zora__deployers') }} +), + +factories as ( + select + *, + 'OPTIMISM' as artifact_source + from {{ ref('stg_optimism__factories') }} + union all + select + *, + 'BASE' as artifact_source + from {{ ref('stg_base__factories') }} + union all + select + *, + 'FRAX' as artifact_source + from {{ ref('stg_frax__factories') }} + union all + select + *, + 'MODE' as artifact_source + from {{ ref('stg_mode__factories') }} + union all + select + *, + 'ZORA' as artifact_source + from {{ ref('stg_zora__factories') }} +), + +contract_deployments as ( + select + artifact_source, + transaction_hash, + block_timestamp, + deployer_address as root_deployer_address, + deployer_address as created_by_address, + contract_address, + deployer_address as originating_eoa_address, + 'EOA' as creator_type, + case + when contract_address in ( + select distinct factory_address + from factories + ) then 'FACTORY' + else 'CONTRACT' + end as contract_type + from deployers +), + +factory_deployments as ( + select + factories.artifact_source, + factories.transaction_hash, + factories.block_timestamp, + deployers.deployer_address as root_deployer_address, + factories.factory_address as created_by_address, + factories.contract_address, + 'FACTORY' as creator_type, + 'CONTRACT' as contract_type, + COALESCE(factories.originating_address, deployers.deployer_address) + as originating_eoa_address + from factories + inner join deployers + on factories.factory_address = deployers.contract_address +) + +select * from contract_deployments +union all +select * from factory_deployments diff --git a/warehouse/dbt/models/marts/directory/contracts_v1.sql b/warehouse/dbt/models/marts/directory/contracts_v1.sql new file mode 100644 index 000000000..7d91fa070 --- /dev/null +++ b/warehouse/dbt/models/marts/directory/contracts_v1.sql @@ -0,0 +1,17 @@ +{{ + config(meta = { + 'sync_to_db': True + }) +}} + +select + artifact_source, + transaction_hash, + block_timestamp, + root_deployer_address, + created_by_address, + contract_address, + originating_eoa_address, + creator_type, + contract_type +from {{ ref('int_contracts') }}