Skip to content

Commit

Permalink
dbt: refactor int_all_artifacts and int_derived_contracts (#1674)
Browse files Browse the repository at this point in the history
* refactor: contracts_v1 and int_contracts

* refactor: directory models

* refactor: int derived contracts including proxy deployers

* fix: contracts v0 model

* fix: materialize metrics table

* fix attempt: Materialize all onchain metrics

---------

Co-authored-by: Reuven V. Gonzales <[email protected]>
  • Loading branch information
ccerv1 and ravenac95 authored Jun 19, 2024
1 parent cc513c0 commit 4faaaab
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 307 deletions.
2 changes: 1 addition & 1 deletion apps/hasura/metadata/databases/cloudsql/tables/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- "!include artifacts_v1.yaml"
- "!include code_metrics_by_project_v1.yaml"
- "!include collections_v1.yaml"
- "!include contracts_v1.yaml"
- "!include contracts_v0.yaml"
- "!include event_indexing_status_by_project_v1.yaml"
- "!include event_types_v1.yaml"
- "!include events_daily_to_artifact.yaml"
Expand Down
4 changes: 4 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ models:
+materialized: view
marts:
+materialized: table
intermediate:
metrics:
onchain:
+materialized: table


sources:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ with factories_and_deployers as (
factories.transaction_hash,
factories.network,
factories.originating_address as deployer_address,
deployers.deployer_address as factory_deployer_address,
factories.contract_address as contract_address
from {{ ref("int_factories") }} as factories
inner join {{ ref("int_deployers") }} as deployers
Expand All @@ -17,16 +16,36 @@ with factories_and_deployers as (
transaction_hash,
network,
deployer_address,
null as factory_deployer_address,
contract_address
from {{ ref("int_deployers") }}
),

factories_and_proxies as (
select
factories.block_timestamp,
factories.transaction_hash,
factories.network,
proxies.address as deployer_address,
factories.contract_address as contract_address
from {{ ref("int_factories") }} as factories
inner join {{ ref("int_proxies") }} as proxies
on
factories.originating_address = proxies.address
and factories.network = proxies.network
)

select
block_timestamp,
transaction_hash,
network,
deployer_address,
factory_deployer_address,
contract_address
from factories_and_deployers
union all
select
block_timestamp,
transaction_hash,
network,
deployer_address,
contract_address
from factories_and_proxies
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{# any from address coming out of a proxy #}

{% 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`,
lower(proxy_address) as proxy_address,
'{{ network_upper }}' as network,
min(block_timestamp) as created_date
from {{ ref(table_name) }}
where proxy_address != to_address
group by
to_address,
proxy_address
{% endset %}

{% do union_queries.append(query) %}
{% endfor %}

{% set final_query = union_queries | join(' union all ') %}

with proxies as (
{{ final_query }}
)

select
{{ oso_id("network", "address") }} as artifact_id,
address,
proxy_address,
network,
created_date
from proxies
Loading

0 comments on commit 4faaaab

Please sign in to comment.