Skip to content

Commit

Permalink
Merge branch 'main' into docs/post-refactor-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ccerv1 authored May 22, 2024
2 parents 7ae03cc + 0b3d52d commit a8dd835
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 18 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/warehouse-run-data-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ jobs:
env:
PLAYGROUND_DAYS: 30

# - name: Copy the bigquery tables to cloudsql
# run: |
# poetry run bq2cloudsql
# env:
# DBT_TARGET: production
- name: Copy the bigquery tables to cloudsql
run: |
poetry run bq2cloudsql
env:
DBT_TARGET: production
12 changes: 12 additions & 0 deletions warehouse/dbt/macros/models/factory_deployments.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% macro factory_deployments(network_name, traces="traces") %}
SELECT block_timestamp, transaction_hash, from_address as factory_address, to_address as contract_address,
FROM {{ source(network_name, traces) }}

WHERE LOWER(trace_type) in ("create", "create2") and status = 1
{% if is_incremental() %}
and block_timestamp > TIMESTAMP_SUB(_dbt_max_partition, INTERVAL 1 DAY)
{% else %}
{{ playground_filter("block_timestamp", is_start=False) }}
{% endif %}

{% endmacro %}
3 changes: 3 additions & 0 deletions warehouse/dbt/models/ethereum_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ sources:
tables:
- name: transactions
identifier: transactions

- name: traces
identifier: traces

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% set networks = [
"ethereum", "optimism",
"base", "frax",
"mode", "pgn", "zora"
]
%}
with {% for network in networks %}
{{ network }}_factories_and_deployers as (
select
factories.block_timestamp as block_timestamp,
factories.transaction_hash as transaction_hash,
deployers.deployer_address as deployer_address,
factories.contract_address as contract_address
from {{ ref("stg_%s__factories" % network) }} as factories
inner join {{ ref("stg_%s__deployers" % network) }} as deployers
on factories.factory_address = deployers.contract_address
union all
select
block_timestamp,
transaction_hash,
deployer_address,
contract_address
from {{ ref("stg_%s__deployers" % network) }}
){% if not loop.last %},{% endif %}
{% endfor %}
{% for network in networks %}
{% if not loop.first %}
union all
{% endif %}
select
block_timestamp,
transaction_hash,
"{{ network.upper() }}" as network,
deployer_address,
contract_address
from {{ network }}_factories_and_deployers
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ ossd_blockchain as (
),

all_deployers as (
select
*,
"OPTIMISM" as artifact_namespace,
"OPTIMISM" as artifact_source
from {{ ref("stg_optimism__deployers") }}
union all
select
*,
"MAINNET" as artifact_namespace,
Expand All @@ -102,6 +96,15 @@ all_deployers as (
"ARBITRUM_ONE" as artifact_namespace,
"ARBITRUM_ONE" as artifact_source
from {{ ref("stg_arbitrum__deployers") }}
union all
select
block_timestamp,
transaction_hash,
deployer_address,
contract_address,
UPPER(network) as artifact_namespace,
UPPER(network) as artifact_source
from {{ ref("int_derived_contracts") }}
),

discovered_contracts as (
Expand All @@ -117,8 +120,8 @@ discovered_contracts as (
inner join all_deployers as ad
on
ob.artifact_source_id = ad.deployer_address
and ob.artifact_namespace = ad.artifact_namespace
and ob.artifact_type in ("EOA", "DEPLOYER", "FACTORY")
and UPPER(ob.artifact_namespace) = UPPER(ad.artifact_namespace)
and UPPER(ob.artifact_type) in ("EOA", "DEPLOYER", "FACTORY")
),

all_artifacts as (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}}

select
to_artifact_id,
to_artifact_id as artifact_id,
event_type,
TIMESTAMP_TRUNC(time, day) as bucket_day,
SUM(amount) as amount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
}}

select
to_artifact_id,
artifact_id,
event_type,
TIMESTAMP_TRUNC(bucket_day, month) as bucket_month,
SUM(amount) as amount
from {{ ref('events_daily_to_artifact') }}
group by
to_artifact_id,
artifact_id,
event_type,
TIMESTAMP_TRUNC(bucket_day, month)
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
}}

select
to_artifact_id,
artifact_id,
event_type,
TIMESTAMP_TRUNC(bucket_day, week) as bucket_week,
SUM(amount) as amount
from {{ ref('events_daily_to_artifact') }}
group by
to_artifact_id,
artifact_id,
event_type,
TIMESTAMP_TRUNC(bucket_day, week)
14 changes: 14 additions & 0 deletions warehouse/dbt/models/staging/base/stg_base__factories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
)
}}
{{ factory_deployments("base") }}
14 changes: 14 additions & 0 deletions warehouse/dbt/models/staging/ethereum/stg_ethereum__factories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
)
}}
{{ factory_deployments("ethereum") }}
14 changes: 14 additions & 0 deletions warehouse/dbt/models/staging/frax/stg_frax__deployers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
)
}}
{{ transactions_with_receipts_deployers("frax") }}
14 changes: 14 additions & 0 deletions warehouse/dbt/models/staging/frax/stg_frax__factories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
)
}}
{{ factory_deployments("frax") }}
14 changes: 14 additions & 0 deletions warehouse/dbt/models/staging/mode/stg_mode__factories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
)
}}
{{ factory_deployments("mode") }}
14 changes: 14 additions & 0 deletions warehouse/dbt/models/staging/optimism/stg_optimism__factories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
)
}}
{{ factory_deployments("superchain", traces="optimism_traces") }}
14 changes: 14 additions & 0 deletions warehouse/dbt/models/staging/pgn/stg_pgn__deployers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
)
}}
{{ transactions_with_receipts_deployers("pgn") }}
14 changes: 14 additions & 0 deletions warehouse/dbt/models/staging/pgn/stg_pgn__factories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
)
}}
{{ factory_deployments("pgn") }}
14 changes: 14 additions & 0 deletions warehouse/dbt/models/staging/zora/stg_zora__deployers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
)
}}
{{ transactions_with_receipts_deployers("zora") }}
14 changes: 14 additions & 0 deletions warehouse/dbt/models/staging/zora/stg_zora__factories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
)
}}
{{ factory_deployments("zora") }}

0 comments on commit a8dd835

Please sign in to comment.