diff --git a/models/defillama/bronze/bronze__defillama_raises.sql b/models/defillama/bronze/bronze__defillama_raises.sql new file mode 100644 index 0000000..99e5c53 --- /dev/null +++ b/models/defillama/bronze/bronze__defillama_raises.sql @@ -0,0 +1,51 @@ +{{ config( + materialized = 'incremental', + unique_key = 'raise_id', + tags = ['defillama'] +) }} + +WITH protocol_base AS ( + +SELECT + live.udf_api( + 'GET','https://pro-api.llama.fi/{api_key}/api/raises',{},{},'Vault/prod/external/defillama' + ) AS read, + SYSDATE() AS _inserted_timestamp +) + +SELECT + TRY_TO_TIMESTAMP(VALUE:date::STRING) AS funding_date, + VALUE:name::STRING AS project_name, + VALUE:round::STRING AS funding_round, + VALUE:amount::FLOAT AS amount_raised, + VALUE:chains::VARIANT AS chains, + VALUE:sector::STRING AS sector, + VALUE:category::STRING AS category, + VALUE:categoryGroup::STRING AS category_group, + VALUE:source::STRING AS source, + VALUE:leadInvestors::VARIANT AS lead_investors, + VALUE:otherInvestors::VARIANT AS other_investors, + TRY_TO_NUMBER(VALUE:valuation::STRING) AS valuation, + VALUE:defillamaId::STRING AS defillama_id, + MD5(CONCAT( + COALESCE(VALUE:name::STRING, ''), + COALESCE(VALUE:date::STRING, ''), + COALESCE(VALUE:round::STRING, ''), + COALESCE(VALUE:amount::STRING, '') + )) AS raise_id, + _inserted_timestamp +FROM protocol_base, + LATERAL FLATTEN (input=> read :data :raises) + +{% if is_incremental() %} +WHERE raise_id NOT IN ( + SELECT + DISTINCT raise_id + FROM + {{ this }} +) +{% endif %} + +QUALIFY( + ROW_NUMBER() OVER (PARTITION BY raise_id ORDER BY _inserted_timestamp DESC) +) = 1 \ No newline at end of file diff --git a/models/defillama/bronze/bronze__defillama_raises.yml b/models/defillama/bronze/bronze__defillama_raises.yml new file mode 100644 index 0000000..524e097 --- /dev/null +++ b/models/defillama/bronze/bronze__defillama_raises.yml @@ -0,0 +1,24 @@ +version: 2 +models: + - name: bronze__defillama_raises + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - RAISE_ID + + columns: + - name: RAISE_ID + tests: + - not_null + - name: PROJECT_NAME + tests: + - not_null + - name: FUNDING_DATE + tests: + - not_null + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 30 + - name: _INSERTED_TIMESTAMP + tests: + - not_null \ No newline at end of file diff --git a/models/defillama/gold/defillama__ez_investors.sql b/models/defillama/gold/defillama__ez_investors.sql new file mode 100644 index 0000000..4646abe --- /dev/null +++ b/models/defillama/gold/defillama__ez_investors.sql @@ -0,0 +1,29 @@ +{{ config( + materialized = 'view', + persist_docs ={ "relation": true, + "columns": true }, + tags = ['defillama'], + meta={ + 'database_tags':{ + 'table': { + 'PROTOCOL': 'DEFILLAMA' + } + } + } +) }} + +SELECT + investor, + deals, + total_amount, + median_amount, + chains, + top_project_category, + top_round_type, + projects, + defillama_investors_id, + inserted_timestamp, + modified_timestamp, + _inserted_timestamp, + _invocation_id +FROM {{ ref('silver__defillama_investors') }} \ No newline at end of file diff --git a/models/defillama/gold/defillama__ez_investors.yml b/models/defillama/gold/defillama__ez_investors.yml new file mode 100644 index 0000000..cacca9d --- /dev/null +++ b/models/defillama/gold/defillama__ez_investors.yml @@ -0,0 +1,32 @@ +version: 2 +models: + - name: defillama__ez_investors + description: This table contains aggregated information about investors, sourced from Defillama's Raises data, providing easy-to-use metrics. + + columns: + - name: INVESTOR + description: Name of the investor or investment firm. + - name: DEALS + description: Total number of funding deals the investor has participated in. + - name: TOTAL_AMOUNT + description: Total amount invested across all deals (in USD). + - name: MEDIAN_AMOUNT + description: Median investment amount per deal (in USD). + - name: CHAINS + description: Array of blockchain networks the investor has invested in. + - name: TOP_PROJECT_CATEGORY + description: Category of the project representing the investor's largest investment. + - name: TOP_ROUND_TYPE + description: Type of funding round for the investor's largest investment. + - name: PROJECTS + description: Array of project names the investor has invested in. + - name: DEFILLAMA_INVESTORS_ID + description: Generated surrogate key for the table. + - name: INSERTED_TIMESTAMP + description: Timestamp when the record was first inserted. + - name: MODIFIED_TIMESTAMP + description: Timestamp when the record was last modified. + - name: _INSERTED_TIMESTAMP + description: Internal timestamp for data pipeline tracking. + - name: _INVOCATION_ID + description: DBT invocation identifier for lineage tracking. \ No newline at end of file diff --git a/models/defillama/gold/defillama__fact_raises.sql b/models/defillama/gold/defillama__fact_raises.sql new file mode 100644 index 0000000..c5c327f --- /dev/null +++ b/models/defillama/gold/defillama__fact_raises.sql @@ -0,0 +1,35 @@ +{{ config( + materialized = 'view', + persist_docs ={ "relation": true, + "columns": true }, + tags = ['defillama'], + meta={ + 'database_tags':{ + 'table': { + 'PROTOCOL': 'DEFILLAMA' + } + } + } +) }} + +SELECT + funding_date, + project_name, + funding_round, + amount_raised, + chains, + sector, + category, + category_group, + source, + lead_investors, + other_investors, + valuation, + defillama_id, + raise_id, + defillama_raises_id, + inserted_timestamp, + modified_timestamp, + _inserted_timestamp, + _invocation_id +FROM {{ ref('silver__defillama_raises') }} \ No newline at end of file diff --git a/models/defillama/gold/defillama__fact_raises.yml b/models/defillama/gold/defillama__fact_raises.yml new file mode 100644 index 0000000..5f5a026 --- /dev/null +++ b/models/defillama/gold/defillama__fact_raises.yml @@ -0,0 +1,44 @@ +version: 2 +models: + - name: defillama__fact_raises + description: This table contains fact-based information about funding raises for projects tracked by Defillama. + + columns: + - name: FUNDING_DATE + description: Date when the funding round occurred. + - name: PROJECT_NAME + description: Name of the project that received funding. + - name: FUNDING_ROUND + description: Type of funding round (e.g., Series A, Seed, Private, etc.). + - name: AMOUNT_RAISED + description: Amount of money raised in the funding round (in USD). + - name: CHAINS + description: Array of blockchain networks that the project operates on. + - name: SECTOR + description: Industry sector classification of the project. + - name: CATEGORY + description: Specific category classification of the project. + - name: CATEGORY_GROUP + description: Higher-level category grouping for the project. + - name: SOURCE + description: Source of the funding information. + - name: LEAD_INVESTORS + description: Array of lead investors in the funding round. + - name: OTHER_INVESTORS + description: Array of other participating investors in the funding round. + - name: VALUATION + description: Company valuation at the time of the funding round (in USD). + - name: DEFILLAMA_ID + description: DeFiLlama's unique identifier for the project. + - name: RAISE_ID + description: Unique identifier for the specific funding round. + - name: DEFILLAMA_RAISES_ID + description: Generated surrogate key for the table. + - name: INSERTED_TIMESTAMP + description: Timestamp when the record was first inserted. + - name: MODIFIED_TIMESTAMP + description: Timestamp when the record was last modified. + - name: _INSERTED_TIMESTAMP + description: Internal timestamp for data pipeline tracking. + - name: _INVOCATION_ID + description: DBT invocation identifier for lineage tracking. \ No newline at end of file diff --git a/models/defillama/silver/silver__defillama_investors.sql b/models/defillama/silver/silver__defillama_investors.sql new file mode 100644 index 0000000..b960726 --- /dev/null +++ b/models/defillama/silver/silver__defillama_investors.sql @@ -0,0 +1,120 @@ +{{ config( + materialized = 'table', + tags = ['defillama'] +) }} + +WITH investor_deals AS ( + -- Flatten lead investors + SELECT + TRIM(lead_investor.value::STRING) AS investor, + funding_date, + project_name, + funding_round, + amount_raised, + chains, + category, + raise_id, + _inserted_timestamp + FROM {{ ref('silver__defillama_raises') }} r, + LATERAL FLATTEN(input => r.lead_investors) AS lead_investor + WHERE investor IS NOT NULL + AND investor != '' + + UNION ALL + + -- Flatten other investors + SELECT + TRIM(other_investor.value::STRING) AS investor, + funding_date, + project_name, + funding_round, + amount_raised, + chains, + category, + raise_id, + _inserted_timestamp + FROM {{ ref('silver__defillama_raises') }} r, + LATERAL FLATTEN(input => r.other_investors) AS other_investor + WHERE investor IS NOT NULL + AND investor != '' +), + +investor_chains AS ( + -- Flatten chains for each investor deal + SELECT + investor, + funding_date, + project_name, + funding_round, + amount_raised, + TRIM(chains.value::STRING) AS chain, + category, + raise_id, + _inserted_timestamp + FROM investor_deals d, + LATERAL FLATTEN(input => d.chains) AS chains + WHERE chain IS NOT NULL + AND chain != '' +), + +investor_aggregates AS ( + SELECT + investor, + COUNT(DISTINCT raise_id) AS deals, + SUM(amount_raised) AS total_amount, + MEDIAN(amount_raised) AS median_amount, + ARRAY_AGG(DISTINCT chain) AS chains, + ARRAY_AGG(DISTINCT project_name) AS projects, + MAX(_inserted_timestamp) AS _inserted_timestamp + FROM investor_chains + GROUP BY investor +), + +top_deals AS ( + SELECT + investor, + category AS top_project_category, + funding_round AS top_round_type, + ROW_NUMBER() OVER ( + PARTITION BY investor + ORDER BY amount_raised DESC, funding_date DESC + ) AS rn + FROM investor_deals +), + +investor_metrics AS ( + SELECT + a.investor, + a.deals, + a.total_amount, + a.median_amount, + a.chains, + a.projects, + t.top_project_category, + t.top_round_type, + a._inserted_timestamp + FROM investor_aggregates a + LEFT JOIN top_deals t + ON a.investor = t.investor + AND t.rn = 1 +) + +SELECT + investor, + deals, + total_amount, + median_amount, + chains, + top_project_category, + top_round_type, + projects, + {{ dbt_utils.generate_surrogate_key(['investor']) }} AS defillama_investors_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + _inserted_timestamp, + '{{ invocation_id }}' AS _invocation_id +FROM investor_metrics + +QUALIFY( + ROW_NUMBER() OVER (PARTITION BY investor ORDER BY _inserted_timestamp DESC) +) = 1 \ No newline at end of file diff --git a/models/defillama/silver/silver__defillama_investors.yml b/models/defillama/silver/silver__defillama_investors.yml new file mode 100644 index 0000000..5cc166c --- /dev/null +++ b/models/defillama/silver/silver__defillama_investors.yml @@ -0,0 +1,14 @@ +version: 2 +models: + - name: silver__defillama_investors + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - INVESTOR + columns: + - name: INVESTOR + tests: + - not_null + - name: _INSERTED_TIMESTAMP + tests: + - not_null \ No newline at end of file diff --git a/models/defillama/silver/silver__defillama_raises.sql b/models/defillama/silver/silver__defillama_raises.sql new file mode 100644 index 0000000..a204493 --- /dev/null +++ b/models/defillama/silver/silver__defillama_raises.sql @@ -0,0 +1,43 @@ +{{ config( + materialized = 'incremental', + unique_key = ['raise_id'], + tags = ['defillama'] +) }} + +SELECT + funding_date, + project_name, + funding_round, + amount_raised * 1000000 AS amount_raised, + chains, + sector, + category, + category_group, + source, + lead_investors, + other_investors, + valuation, + defillama_id, + raise_id, + {{ dbt_utils.generate_surrogate_key( + ['raise_id'] + ) }} AS defillama_raises_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + _inserted_timestamp, + '{{ invocation_id }}' AS _invocation_id +FROM + {{ ref('bronze__defillama_raises') }} + +{% if is_incremental() %} +WHERE _inserted_timestamp > ( + SELECT + MAX(_inserted_timestamp) + FROM + {{ this }} +) +{% endif %} + +QUALIFY( + ROW_NUMBER() OVER (PARTITION BY raise_id ORDER BY _inserted_timestamp DESC) +) = 1 \ No newline at end of file diff --git a/models/defillama/silver/silver__defillama_raises.yml b/models/defillama/silver/silver__defillama_raises.yml new file mode 100644 index 0000000..32f3d85 --- /dev/null +++ b/models/defillama/silver/silver__defillama_raises.yml @@ -0,0 +1,21 @@ +version: 2 +models: + - name: silver__defillama_raises + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - RAISE_ID + + columns: + - name: RAISE_ID + tests: + - not_null + - name: PROJECT_NAME + tests: + - not_null + - name: FUNDING_DATE + tests: + - not_null + - name: _INSERTED_TIMESTAMP + tests: + - not_null \ No newline at end of file diff --git a/models/doc_descriptions/general/__overview__.md b/models/doc_descriptions/general/__overview__.md index 594e999..c4cc1c2 100644 --- a/models/doc_descriptions/general/__overview__.md +++ b/models/doc_descriptions/general/__overview__.md @@ -43,6 +43,8 @@ Note: These tables ceased updating on Feburary 4th, 2024. - [defillama__fact_protocol_tvl](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__fact_protocol_tvl) - [defillama__fact_pool_yields](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__fact_pool_yields) - [defillama__fact_protocol_fees_revenue](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__fact_protocol_fees_revenue) +- [defillama__fact_raises](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__fact_raises) +- [defillama__ez_investors](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__ez_investors) **DeepNFTValue**