Skip to content

Commit

Permalink
rf4: updates to eigentrust models
Browse files Browse the repository at this point in the history
  • Loading branch information
ccerv1 committed May 23, 2024
1 parent 0f45038 commit 93c8bc7
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ select
events.event_source,
events.event_type,
events.amount,
rf4_trusted_users.user_id as trusted_user_id
case
when rf4_trusted_users.is_trusted_user is true
then rf4_trusted_users.user_id
end as trusted_user_id
from events
left join {{ ref('artifacts_v1') }} as to_artifacts
on events.to_artifact_id = to_artifacts.artifact_id
Expand Down
60 changes: 50 additions & 10 deletions warehouse/dbt/models/marts/superchain/rf4_trusted_users.sql
Original file line number Diff line number Diff line change
@@ -1,41 +1,81 @@
with eigentrust_top_users as (
{# draft model for testing #}
select farcaster_id
select CAST(farcaster_id as string) as farcaster_id
from {{ ref('stg_karma3__globaltrust') }}
where
snapshot_time = '2024-05-01'
snapshot_time = '2024-05-21'
and strategy_id = 1
order by eigentrust_rank desc
limit 50000
),

web_of_trust as (
select CAST(fof_id as string) as farcaster_id
from (
select
l2.peer_farcaster_id as fof_id,
COUNT(distinct l1.peer_farcaster_id) as edge_count
from {{ ref('stg_karma3__localtrust') }} as l1
left join {{ ref('stg_karma3__localtrust') }} as l2
on l1.peer_farcaster_id = l2.farcaster_id
where
l1.farcaster_id = 5650
and l1.strategy_id = 1
and l2.strategy_id = 1
group by l2.peer_farcaster_id
)
where edge_count > 1
),

user_model as (
select
artifacts_by_user.user_id,
artifacts_by_user.user_source,
artifacts_by_user.user_source_id,
artifacts_by_user.artifact_name,
CAST(
eigentrust_top_users.farcaster_id
is not null as bool
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(
passport_scores.evidence_rawscore
>= passport_scores.evidence_threshold as bool
web_of_trust.farcaster_id is not null
as int64
) as vitalik_verification,
CAST(
COALESCE(
passport_scores.evidence_rawscore
>= passport_scores.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
left join eigentrust_top_users
on artifacts_by_user.user_source_id = eigentrust_top_users.farcaster_id
left join web_of_trust
on artifacts_by_user.user_source_id = web_of_trust.farcaster_id
)

select
user_id,
user_source,
user_source_id,
artifact_name
artifact_name,
farcaster_prepermissionless,
eigentrust_verification,
vitalik_verification,
passport_verification,
(
farcaster_prepermissionless
+ eigentrust_verification
+ vitalik_verification
+ passport_verification
>= 1
) as is_trusted_user
from user_model
where
passport_verification is true
or eigentrust_verification is true
13 changes: 12 additions & 1 deletion warehouse/dbt/models/staging/karma3/stg_karma3__globaltrust.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
for Farcaster IDs
#}

{{
config(
materialized='table',
partition_by={
"field": "snapshot_time",
"data_type": "timestamp",
"granularity": "day"
}
)
}}

select
strategy_id,
CAST(i as string) as farcaster_id,
i as farcaster_id,
CAST(v as numeric) as eigentrust_rank,
CAST(date as timestamp) as snapshot_time
from {{ source("karma3", "globaltrust") }}
20 changes: 18 additions & 2 deletions warehouse/dbt/models/staging/karma3/stg_karma3__localtrust.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
{#
Get all Karma3 EigenTrust scores
for Farcaster IDs
for Farcaster IDs - Local Trust
#}

{{
config(
materialized='table',
partition_by={
"field": "farcaster_id",
"data_type": "int64",
"range": {
"start": 0,
"end": 1000000,
"interval": 25000
}
}
)
}}

select
strategy_id,
CAST(i as string) as farcaster_id,
i as farcaster_id,
j as peer_farcaster_id,
CAST(v as numeric) as eigentrust_rank,
CAST(date as timestamp) as snapshot_time
from {{ source("karma3", "localtrust") }}

0 comments on commit 93c8bc7

Please sign in to comment.