diff --git a/warehouse/dbt/models/intermediate/funding/int_oss_funding_grants_to_project.sql b/warehouse/dbt/models/intermediate/funding/int_oss_funding_grants_to_project.sql new file mode 100644 index 000000000..6cf527ece --- /dev/null +++ b/warehouse/dbt/models/intermediate/funding/int_oss_funding_grants_to_project.sql @@ -0,0 +1,69 @@ +{# + The most recent view of grants to projects from the oss-funding source. +#} + +{% set oss_funding_url = "https://github.com/opensource-observer/oss-funding" %} + +with grants as ( + select -- noqa: ST06 + CAST(funding_date as timestamp) as `time`, + 'GRANT_RECEIVED_USD' as event_type, + COALESCE(project_url, '{{ oss_funding_url }}') as event_source_id, + 'OSS_FUNDING' as event_source, + LOWER(project_name) as project_name, + case + when funder_name in ('Optimism Foundation') then 'op' + when funder_name in ('Arbitrum Foundation') then 'arbitrumfoundation' + when funder_name in ('Octant') then 'octant-golemfoundation' + when funder_name in ('Gitcoin Grants') then 'gitcoin' + when funder_name in ('DAO Drops (dOrg)') then 'dao-drops-dorgtech' + end as funder_name, + LOWER(project_address) as to_name, + case + when funding_network in ('mainnet', '1.0') then 'ethereum' + when funding_network in ('optimism', '10.0') then 'optimism' + when funding_network in ('arbitrum', '42161.0') then 'arbitrum_one' + when funding_network in ('pgn', '424.0') then 'pgn' + when funding_network in ('polygon', '137.0') then 'polygon' + else 'other' + end as to_namespace, + 'WALLET' as to_type, + LOWER(project_address) as to_artifact_source_id, + LOWER(funder_address) as from_name, + case + when funding_network in ('mainnet', '1.0') then 'ethereum' + when funding_network in ('optimism', '10.0') then 'optimism' + when funding_network in ('arbitrum', '42161.0') then 'arbitrum_one' + when funding_network in ('pgn', '424.0') then 'pgn' + when funding_network in ('polygon', '137.0') then 'polygon' + else 'other' + end as from_namespace, + 'WALLET' as from_type, + LOWER(funder_address) as from_artifact_source_id, + funding_usd as amount + from {{ source('static_data_sources', 'oss_funding') }} +) + +select + grants.time, + grants.event_type, + grants.event_source_id, + grants.event_source, + grants.project_name as to_project_name, + to_projects.project_id as to_project_id, + grants.to_name, + grants.to_namespace, + grants.to_type, + grants.to_artifact_source_id, + grants.funder_name as from_project_name, + from_projects.project_id as from_project_id, + grants.from_name, + grants.from_namespace, + grants.from_type, + grants.from_artifact_source_id, + grants.amount +from grants +inner join {{ ref('projects_v1') }} as to_projects + on grants.project_name = to_projects.project_name +inner join {{ ref('projects_v1') }} as from_projects + on grants.funder_name = from_projects.project_name diff --git a/warehouse/dbt/models/intermediate/metrics/funding/int_funding_metric__grants_received_usd.sql b/warehouse/dbt/models/intermediate/metrics/funding/int_funding_metric__grants_received_usd.sql new file mode 100644 index 000000000..20dc70e96 --- /dev/null +++ b/warehouse/dbt/models/intermediate/metrics/funding/int_funding_metric__grants_received_usd.sql @@ -0,0 +1,16 @@ +{{ + config( + materialized='ephemeral', + ) +}} + +select + to_project_id as project_id, + 'grants_received_usd' as metric, + amount as amount, + 'USD' as unit, + TIMESTAMP_TRUNC(`time`, day) as sample_date +from {{ ref('int_oss_funding_grants_to_project') }} +where + to_project_id is not null + and amount > 0 diff --git a/warehouse/dbt/models/intermediate/metrics/int_metrics.sql b/warehouse/dbt/models/intermediate/metrics/int_metrics.sql index 031edd8c8..d2b44560d 100644 --- a/warehouse/dbt/models/intermediate/metrics/int_metrics.sql +++ b/warehouse/dbt/models/intermediate/metrics/int_metrics.sql @@ -9,3 +9,15 @@ select distinct "TODO" as definition_ref, "UNKNOWN" as aggregation_function from {{ ref('int_timeseries_code_metrics_by_artifact__developers') }} as metrics +union all +select distinct + {{ oso_id('"OSO"', '"oso"', 'metric') }} as metric_id, + "OSO" as metric_source, + "oso" as metric_namespace, + metric as metric_name, + "TODO" as display_name, + "TODO" as description, + null as raw_definition, + "TODO" as definition_ref, + "UNKNOWN" as aggregation_function +from {{ ref('int_funding_metric__grants_received_usd') }} diff --git a/warehouse/dbt/models/intermediate/metrics/int_timeseries_metrics_by_project.sql b/warehouse/dbt/models/intermediate/metrics/int_timeseries_metrics_by_project.sql index 551645bfe..2be89ee47 100644 --- a/warehouse/dbt/models/intermediate/metrics/int_timeseries_metrics_by_project.sql +++ b/warehouse/dbt/models/intermediate/metrics/int_timeseries_metrics_by_project.sql @@ -12,3 +12,11 @@ select metrics.amount as amount, null as unit from {{ ref('int_timeseries_code_metrics__developers') }} as metrics +union all +select + {{ oso_id('"OSO"', '"oso"', 'metric') }} as metric_id, + project_id, + sample_date, + amount, + unit +from {{ ref('int_funding_metric__grants_received_usd') }} diff --git a/warehouse/dbt/models/static_data_sources.yml b/warehouse/dbt/models/static_data_sources.yml index d47fda36f..6c62f731e 100644 --- a/warehouse/dbt/models/static_data_sources.yml +++ b/warehouse/dbt/models/static_data_sources.yml @@ -3,6 +3,8 @@ sources: database: opensource-observer schema: static_data_sources tables: + - name: oss_funding + identifier: oss_funding - name: op_rf4_trusted_addresses identifier: op_rf4_trusted_addresses - name: optimist_nft_holders