From f47f91d9f4612ed07dc5dcb237bc7eee936b1db9 Mon Sep 17 00:00:00 2001 From: Carl Cervone <42869436+ccerv1@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:45:48 -0400 Subject: [PATCH] fix: dedupe certain contracts and get bridge txns (#1717) * fix: dedupe certain contracts and get bridge txns * fix: linting error --- .../contract_invocation_events_with_l1.sql | 4 +- .../int_derived_contracts.sql | 3 - .../rf4_events_daily_to_project.sql | 79 +++++++++++++------ 3 files changed, 58 insertions(+), 28 deletions(-) diff --git a/warehouse/dbt/macros/models/contract_invocation_events_with_l1.sql b/warehouse/dbt/macros/models/contract_invocation_events_with_l1.sql index 77297b624..5fab80891 100644 --- a/warehouse/dbt/macros/models/contract_invocation_events_with_l1.sql +++ b/warehouse/dbt/macros/models/contract_invocation_events_with_l1.sql @@ -5,9 +5,7 @@ with bridges as ( select distinct artifact_source_id from {{ ref('int_artifacts_in_ossd_by_project') }} - where - artifact_type = 'BRIDGE' - and artifact_type = 'EOA' + where artifact_type = 'BRIDGE' ), transactions as ( diff --git a/warehouse/dbt/models/intermediate/blockchain_artifacts/int_derived_contracts.sql b/warehouse/dbt/models/intermediate/blockchain_artifacts/int_derived_contracts.sql index 8295ad0a7..686870c1c 100644 --- a/warehouse/dbt/models/intermediate/blockchain_artifacts/int_derived_contracts.sql +++ b/warehouse/dbt/models/intermediate/blockchain_artifacts/int_derived_contracts.sql @@ -1,7 +1,4 @@ with contracts_deployed_no_factory as ( - {# - This gets all of the contracts that weren't deployed with a factory - #} select network, deployer_address, diff --git a/warehouse/dbt/models/marts/superchain/rf4_events_daily_to_project.sql b/warehouse/dbt/models/marts/superchain/rf4_events_daily_to_project.sql index 7709dc67d..cd5c95b68 100644 --- a/warehouse/dbt/models/marts/superchain/rf4_events_daily_to_project.sql +++ b/warehouse/dbt/models/marts/superchain/rf4_events_daily_to_project.sql @@ -36,28 +36,63 @@ artifacts as ( artifact_id, artifact_name from {{ ref('artifacts_v1') }} +), + +events_to_project as ( + select + events.bucket_day, + events.project_id, + projects_v1.project_name, + from_artifacts.artifact_name as from_artifact_name, + to_artifacts.artifact_name as to_artifact_name, + events.event_source, + events.event_type, + events.amount, + case + when rf4_trusted_users.is_trusted_user is true + then rf4_trusted_users.address + end as trusted_user_id + from events + left join artifacts as to_artifacts + on events.to_artifact_id = to_artifacts.artifact_id + left join artifacts as from_artifacts + on events.from_artifact_id = from_artifacts.artifact_id + left join {{ ref('projects_v1') }} + on events.project_id = projects_v1.project_id + left join {{ ref('rf4_trusted_users') }} + on from_artifacts.artifact_name = rf4_trusted_users.address + where events.amount > 0 +), + +duped_contracts as ( + select distinct + event_source, + to_artifact_name, + project_name + from events_to_project + where project_name in ('zora', 'aerodrome-finance') +), + +filtered_events as ( + select events_to_project.* + from events_to_project + left join duped_contracts + on + events_to_project.to_artifact_name = duped_contracts.to_artifact_name + and events_to_project.event_source = duped_contracts.event_source + where + duped_contracts.project_name is null + or duped_contracts.project_name = events_to_project.project_name ) select - events.bucket_day, - events.project_id, - projects_v1.project_name, - from_artifacts.artifact_name as from_artifact_name, - to_artifacts.artifact_name as to_artifact_name, - events.event_source, - events.event_type, - events.amount, - case - when rf4_trusted_users.is_trusted_user is true - then rf4_trusted_users.address - end as trusted_user_id -from events -left join artifacts as to_artifacts - on events.to_artifact_id = to_artifacts.artifact_id -left join artifacts as from_artifacts - on events.from_artifact_id = from_artifacts.artifact_id -left join {{ ref('projects_v1') }} - on events.project_id = projects_v1.project_id -left join {{ ref('rf4_trusted_users') }} - on from_artifacts.artifact_name = rf4_trusted_users.address -where events.amount > 0 + bucket_day, + project_id, + project_name, + from_artifact_name, + to_artifact_name, + event_source, + event_type, + amount, + trusted_user_id +from filtered_events