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 48887a4e4..29bb4bdf7 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 @@ -42,7 +42,7 @@ select events.amount, case when rf4_trusted_users.is_trusted_user is true - then rf4_trusted_users.user_id + then rf4_trusted_users.address end as trusted_user_id from events left join {{ ref('artifacts_v1') }} as to_artifacts @@ -52,6 +52,6 @@ left join {{ ref('artifacts_v1') }} as from_artifacts 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.artifact_name + on from_artifacts.artifact_name = rf4_trusted_users.address where to_artifacts.artifact_type = 'CONTRACT' diff --git a/warehouse/dbt/models/marts/superchain/rf4_trusted_users.sql b/warehouse/dbt/models/marts/superchain/rf4_trusted_users.sql index 32638b538..5c4473d57 100644 --- a/warehouse/dbt/models/marts/superchain/rf4_trusted_users.sql +++ b/warehouse/dbt/models/marts/superchain/rf4_trusted_users.sql @@ -1,6 +1,19 @@ -with eigentrust_top_users as ( +with farcaster_users as ( + select + fid as farcaster_id, + address, + CAST( + fid < '20939' + as int64 + ) as farcaster_prepermissionless + from {{ ref('stg_farcaster__addresses') }} +), + +eigentrust_top_users as ( {# draft model for testing #} - select CAST(farcaster_id as string) as farcaster_id + select + 1 as eigentrust_verification, + CAST(farcaster_id as string) as farcaster_id from {{ ref('stg_karma3__globaltrust') }} where snapshot_time = '2024-05-21' @@ -10,7 +23,10 @@ with eigentrust_top_users as ( ), web_of_trust as ( - select CAST(fof_id as string) as farcaster_id + {# draft model for testing #} + select + 1 as vitalik_verification, + CAST(fof_id as string) as farcaster_id from ( select l2.peer_farcaster_id as fof_id, @@ -27,55 +43,79 @@ web_of_trust as ( where edge_count > 1 ), -user_model as ( +optimist_nft_holders as ( select - artifacts_by_user.user_id, - artifacts_by_user.user_source, - artifacts_by_user.user_source_id, - artifacts_by_user.artifact_name, - CAST( - artifacts_by_user.user_source_id < '20939' - as int64 - ) as farcaster_prepermissionless, - CAST( - eigentrust_top_users.farcaster_id is not null - as int64 - ) as eigentrust_verification, - CAST( - web_of_trust.farcaster_id is not null - as int64 - ) as vitalik_verification, + optimist_address as address, + 1 as optimist_nft_verification + from {{ source("static_data_sources", "optimist_nft_holders") }} +), + +passport_scores as ( + select + passport_address as address, + 1 as passport_user, CAST( - COALESCE( - passport_scores.evidence_rawscore - >= passport_scores.evidence_threshold, - false - ) - as int64 + COALESCE(evidence_rawscore >= evidence_threshold, false) as int64 ) as passport_verification - from {{ ref('int_artifacts_by_user') }} as artifacts_by_user - left join {{ ref('stg_passport__scores') }} as passport_scores - on artifacts_by_user.artifact_name = passport_scores.passport_address + from {{ ref('stg_passport__scores') }} +), + +all_addresses as ( + select distinct address + from ( + select address from farcaster_users + union all + select address from passport_scores + union all + select address from optimist_nft_holders + ) +), + +trusted_user_model as ( + select + all_addresses.address, + CAST(farcaster_users.farcaster_id is not null as int64) + as farcaster_user, + COALESCE(farcaster_users.farcaster_prepermissionless, 0) + as farcaster_prepermissionless, + COALESCE(eigentrust_top_users.eigentrust_verification, 0) + as eigentrust_verification, + COALESCE(web_of_trust.vitalik_verification, 0) + as vitalik_verification, + COALESCE(passport_scores.passport_user, 0) + as passport_user, + COALESCE(passport_scores.passport_verification, 0) + as passport_verification, + COALESCE(optimist_nft_holders.optimist_nft_verification, 0) + as optimist_nft_verification + from all_addresses + left join farcaster_users + on all_addresses.address = farcaster_users.address left join eigentrust_top_users - on artifacts_by_user.user_source_id = eigentrust_top_users.farcaster_id + on farcaster_users.farcaster_id = eigentrust_top_users.farcaster_id left join web_of_trust - on artifacts_by_user.user_source_id = web_of_trust.farcaster_id + on farcaster_users.farcaster_id = web_of_trust.farcaster_id + left join passport_scores + on all_addresses.address = passport_scores.address + left join optimist_nft_holders + on all_addresses.address = optimist_nft_holders.address ) select - user_id, - user_source, - user_source_id, - artifact_name, + address, + farcaster_user, farcaster_prepermissionless, eigentrust_verification, vitalik_verification, + passport_user, passport_verification, + optimist_nft_verification, ( - farcaster_prepermissionless + farcaster_user + + farcaster_prepermissionless + eigentrust_verification + vitalik_verification + passport_verification - >= 1 - ) as is_trusted_user -from user_model + + optimist_nft_verification + ) > 1 as is_trusted_user +from trusted_user_model diff --git a/warehouse/dbt/models/static_data_sources.yml b/warehouse/dbt/models/static_data_sources.yml new file mode 100644 index 000000000..b82b29562 --- /dev/null +++ b/warehouse/dbt/models/static_data_sources.yml @@ -0,0 +1,7 @@ +sources: + - name: static_data_sources + database: opensource-observer + schema: static_data_sources + tables: + - name: optimist_nft_holders + identifier: optimist_nft_holders \ No newline at end of file