diff --git a/macros/contracts/get_contract_deployments.sql b/macros/contracts/get_contract_deployments.sql new file mode 100644 index 00000000..35fd44c8 --- /dev/null +++ b/macros/contracts/get_contract_deployments.sql @@ -0,0 +1,15 @@ +{% macro get_contract_deployments(chain) %} +select + '{{chain}}' as chain, + date_trunc(week, block_timestamp) as date, + count(distinct from_address) as contract_deployers, + count(*) as contracts_deployed +from {{chain}}_flipside.core.fact_traces +where type in ('CREATE', 'CREATE2') +and TRACE_STATUS = 'SUCCESS' +{% if is_incremental() %} + and block_timestamp >= (select max(date) from {{ this }}) +{% endif %} +group by date +order by date desc +{% endmacro %} diff --git a/models/metrics/contracts/fact_arbitrum_contracts.sql b/models/metrics/contracts/fact_arbitrum_contracts.sql index 5911cec0..12199426 100644 --- a/models/metrics/contracts/fact_arbitrum_contracts.sql +++ b/models/metrics/contracts/fact_arbitrum_contracts.sql @@ -1,15 +1,3 @@ -{{ config(materialized="incremental", unique_key="date") }} +{{ config(materialized="incremental", unique_key="date", snowflake_warehouse='ARBITRUM_MD') }} -select - 'arbitrum' as chain, - date_trunc(week, block_timestamp) as date, - count(distinct from_address) as contract_deployers, - count(*) as contracts_deployed -from arbitrum_flipside.core.fact_transactions -where - to_address is null - {% if is_incremental() %} - and block_timestamp >= (select max(date) from {{ this }}) - {% endif %} -group by date -order by date desc +{{get_contract_deployments("arbitrum")}} diff --git a/models/metrics/contracts/fact_base_contracts.sql b/models/metrics/contracts/fact_base_contracts.sql index ec530c72..549cfbd3 100644 --- a/models/metrics/contracts/fact_base_contracts.sql +++ b/models/metrics/contracts/fact_base_contracts.sql @@ -1,15 +1,3 @@ -{{ config(materialized="incremental", unique_key="date") }} +{{ config(materialized="incremental", unique_key="date", snowflake_warehouse='BASE_MD') }} -select - 'base' as chain, - date_trunc(week, block_timestamp) as date, - count(distinct from_address) as contract_deployers, - count(*) as contracts_deployed -from base_flipside.core.fact_transactions -where - to_address is null - {% if is_incremental() %} - and block_timestamp >= (select max(date) from {{ this }}) - {% endif %} -group by date -order by date desc +{{get_contract_deployments("base")}} diff --git a/models/metrics/contracts/fact_ethereum_contracts.sql b/models/metrics/contracts/fact_ethereum_contracts.sql index 5ab8c56b..f85adf0f 100644 --- a/models/metrics/contracts/fact_ethereum_contracts.sql +++ b/models/metrics/contracts/fact_ethereum_contracts.sql @@ -1,15 +1,3 @@ -{{ config(materialized="incremental", unique_key="date") }} +{{ config(materialized="incremental", unique_key="date", snowflake_warehouse='ETHEREUM') }} -select - 'ethereum' as chain, - date_trunc(week, block_timestamp) as date, - count(distinct from_address) as contract_deployers, - count(*) as contracts_deployed -from ethereum_flipside.core.fact_transactions -where - to_address is null - {% if is_incremental() %} - and block_timestamp >= (select max(date) from {{ this }}) - {% endif %} -group by date -order by date desc +{{get_contract_deployments("ethereum")}} diff --git a/models/metrics/contracts/fact_optimism_contracts.sql b/models/metrics/contracts/fact_optimism_contracts.sql index 40227105..9b2de065 100644 --- a/models/metrics/contracts/fact_optimism_contracts.sql +++ b/models/metrics/contracts/fact_optimism_contracts.sql @@ -1,15 +1,3 @@ -{{ config(materialized="incremental", unique_key="date") }} +{{ config(materialized="incremental", unique_key="date", snowflake_warehouse='OPTIMISM_MD') }} -select - 'optimism' as chain, - date_trunc(week, block_timestamp) as date, - count(distinct from_address) as contract_deployers, - count(*) as contracts_deployed -from optimism_flipside.core.fact_transactions -where - to_address is null - {% if is_incremental() %} - and block_timestamp >= (select max(date) from {{ this }}) - {% endif %} -group by date -order by date desc +{{get_contract_deployments("optimism")}}