From edfadf913583e7ac50932c508d1f0d5b906390a8 Mon Sep 17 00:00:00 2001 From: alexwes Date: Mon, 19 Aug 2024 17:49:48 -0400 Subject: [PATCH] Adding complete Lido data models (#405) --- macros/get_treasury_balance.sql | 139 ++++++++++++++++++ macros/metrics/get_coingecko_metrics.sql | 22 ++- models/projects/lido/core/ez_lido_metrics.sql | 109 ++++++++++++++ .../lido/core/ez_lido_metrics_by_chain.sql | 118 ++++++++++++--- .../lido/core/ez_lido_metrics_by_token.sql | 109 ++++++++++++++ .../lido/raw/fact_ldo_tokenholder_count.sql | 11 ++ .../lido/raw/fact_lido_dao_treasury.sql | 11 ++ .../lido/raw/fact_lido_fees_revs_expenses.sql | 71 +++++++++ .../lido/raw/fact_lido_token_incentives.sql | 37 +++++ 9 files changed, 602 insertions(+), 25 deletions(-) create mode 100644 macros/get_treasury_balance.sql create mode 100644 models/projects/lido/core/ez_lido_metrics.sql create mode 100644 models/projects/lido/core/ez_lido_metrics_by_token.sql create mode 100644 models/projects/lido/raw/fact_ldo_tokenholder_count.sql create mode 100644 models/projects/lido/raw/fact_lido_dao_treasury.sql create mode 100644 models/projects/lido/raw/fact_lido_fees_revs_expenses.sql create mode 100644 models/projects/lido/raw/fact_lido_token_incentives.sql diff --git a/macros/get_treasury_balance.sql b/macros/get_treasury_balance.sql new file mode 100644 index 00000000..f6590ed0 --- /dev/null +++ b/macros/get_treasury_balance.sql @@ -0,0 +1,139 @@ +{% macro get_treasury_balance(chain, addresses)%} + +WITH dates AS ( + SELECT + DISTINCT DATE(hour) AS date + FROM + {{ chain }}_flipside.price.ez_prices_hourly + WHERE + symbol = 'UNI' +), +tokens AS ( + SELECT + DISTINCT LOWER(contract_address) AS token_address + FROM + {{ chain }}_flipside.core.ez_token_transfers + WHERE + {% if addresses is string %} LOWER(to_address) = '{{ addresses }}' + {% elif addresses | length > 1 %} LOWER(to_address) in {{addresses}} + {% endif %} +), +sparse_balances AS ( + SELECT + DATE(block_timestamp) AS date, + user_address, + contract_address, + MAX_BY(balance, block_timestamp) / 1e18 AS balance_daily + FROM + {{ chain }}_flipside.core.fact_token_balances + WHERE + LOWER(contract_address) IN ( + SELECT + token_address + FROM + tokens + ) + AND + {% if addresses is string %} LOWER(user_address) = '{{ addresses }}' + {% elif addresses | length > 1 %} LOWER(user_address) in {{addresses}} + {% endif %} + GROUP BY + 1, + 2, + 3 +), +full_balances AS ( + SELECT + d.date, + {% if addresses is string %} + '{{ addresses }}' AS user_address, + {% else %} + ta.address AS user_address, + {% endif %} + t.token_address AS contract_address, + COALESCE( + LAST_VALUE(sb.balance_daily) IGNORE NULLS OVER ( + PARTITION BY + {% if addresses is string %} + '{{ addresses }}' + {% else %} + ta.address + {% endif %}, + t.token_address + ORDER BY + d.date ROWS BETWEEN UNBOUNDED PRECEDING + AND CURRENT ROW + ), + 0 + ) AS balance_daily + FROM + dates d + {% if addresses is string %} + CROSS JOIN (SELECT '{{ addresses }}' AS address) ta + {% else %} + CROSS JOIN (SELECT unnest({{ addresses }}) AS address) ta + {% endif %} + CROSS JOIN tokens t + LEFT JOIN sparse_balances sb ON d.date = sb.date + AND + {% if addresses is string %} + '{{ addresses }}' = sb.user_address + {% else %} + ta.address = sb.user_address + {% endif %} + AND t.token_address = sb.contract_address +), +daily_prices AS ( + SELECT + DATE(hour) AS date, + token_address, + symbol, + AVG(price) AS avg_daily_price, + MAX(decimals) as decimals + FROM + {{ chain }}_flipside.price.ez_prices_hourly + WHERE + token_address IN ( + SELECT + token_address + FROM + tokens + ) + GROUP BY + 1, + 2, + 3 +), +full_table as ( + SELECT + fb.date, + fb.user_address, + fb.contract_address, + dp.symbol, + fb.balance_daily as balance_daily, + COALESCE(dp.avg_daily_price, 0) AS avg_daily_price, + fb.balance_daily * COALESCE(dp.avg_daily_price, 0) AS usd_balance + FROM + full_balances fb + LEFT JOIN daily_prices dp ON fb.date = dp.date + AND fb.contract_address = dp.token_address -- AND dp.decimals is not null + -- and dp.decimals > 0 + WHERE + symbol is not null +) +SELECT + date, + symbol as token, + SUM(balance_daily) as native_balance, + SUM(usd_balance) as usd_balance +FROM + full_table +WHERE + USD_BALANCE > 1 +GROUP BY + 1 + , 2 +ORDER BY + 1 DESC + +{% endmacro %} \ No newline at end of file diff --git a/macros/metrics/get_coingecko_metrics.sql b/macros/metrics/get_coingecko_metrics.sql index 8e8a1019..9cebfec1 100644 --- a/macros/metrics/get_coingecko_metrics.sql +++ b/macros/metrics/get_coingecko_metrics.sql @@ -1,9 +1,12 @@ {% macro get_coingecko_metrics(coingecko_id) %} select - date as date, - shifted_token_price_usd as price, - shifted_token_market_cap as market_cap, - t2.total_supply * price as fdmc + date as date + , shifted_token_price_usd as price + , shifted_token_market_cap as market_cap + , t2.total_supply * price as fdmc + , shifted_token_h24_volume_usd / market_cap as token_turnover_circulating + , shifted_token_h24_volume_usd / fdmc as token_turnover_fdv + , shifted_token_h24_volume_usd as token_volume from {{ ref("fact_coingecko_token_date_adjusted_gold") }} t1 inner join ( @@ -18,10 +21,13 @@ and date < dateadd(day, -1, to_date(sysdate())) union select - dateadd('day', -1, to_date(sysdate())) as date, - token_current_price as price, - token_market_cap as market_cap, - coalesce(token_max_supply, token_total_supply) * price as fdmc + dateadd('day', -1, to_date(sysdate())) as date + , token_current_price as price + , token_market_cap as market_cap + , coalesce(token_max_supply, token_total_supply) * price as fdmc + , token_total_volume / market_cap as token_turnover_circulating + , token_total_volume / fdmc as token_turnover_fdv + , token_total_volume as token_volume from {{ ref("fact_coingecko_token_realtime_data") }} where token_id = '{{ coingecko_id }}' {% endmacro %} diff --git a/models/projects/lido/core/ez_lido_metrics.sql b/models/projects/lido/core/ez_lido_metrics.sql new file mode 100644 index 00000000..3151ab2e --- /dev/null +++ b/models/projects/lido/core/ez_lido_metrics.sql @@ -0,0 +1,109 @@ +{{ + config( + materialized="table", + snowflake_warehouse="LIDO", + database="lido", + schema="core", + alias="ez_metrics", + ) +}} + +with + fees_revenue_expenses as ( + SELECT + date + , block_rewards + , mev_priority_fees + , total_staking_yield as fees + , operating_expenses + , protocol_revenue + , primary_supply_side_revenue + , secondary_supply_side_revenue + , total_supply_side_revenue + FROM {{ ref('fact_lido_fees_revs_expenses') }} + ) + , staked_eth_metrics as ( + select + date + , num_staked_eth + , amount_staked_usd + from {{ ref('fact_lido_staked_eth_count_with_USD_and_change') }} + ) + , treasury_cte as ( + SELECT + date + , sum(usd_balance) as treasury_value + FROM + {{ ref('fact_lido_dao_treasury') }} + GROUP BY 1 + ) + , treasury_native_cte as ( + SELECT + date + , sum(native_balance) as treasury_native + FROM + {{ ref('fact_lido_dao_treasury') }} + where token = 'LDO' + GROUP BY 1 + ) + , net_treasury_cte as ( + SELECT + date + , sum(usd_balance) as net_treasury_value + FROM {{ ref('fact_lido_dao_treasury') }} + where token <> 'LDO' + group by 1 + ) + , token_incentives_cte as ( + SELECT + date + , sum(amount_usd) as token_incentives + FROM + {{ ref('fact_lido_token_incentives') }} + GROUP BY 1 + ) + , price_data as ( + {{ get_coingecko_metrics('lido-dao') }} + ) + , tokenholder_cte as ( + SELECT + date, + token_holder_count + FROM + {{ ref('fact_ldo_tokenholder_count')}} + ) +select + s.date + , COALESCE(f.mev_priority_fees, 0) as mev_priority_fees + , COALESCE(f.block_rewards, 0) as block_rewards + , COALESCE(f.fees, 0) as fees + , COALESCE(f.primary_supply_side_revenue, 0) as primary_supply_side_revenue + , COALESCE(f.secondary_supply_side_revenue, 0) as secondary_supply_side_revenue + , COALESCE(f.total_supply_side_revenue, 0) as total_supply_side_revenue + , COALESCE(f.protocol_revenue, 0) as protocol_revenue + , COALESCE(f.operating_expenses, 0) as operating_expenses + , COALESCE(ti.token_incentives, 0) as token_incentives + , COALESCE(f.protocol_revenue, 0) - COALESCE(f.operating_expenses, 0) - COALESCE(ti.token_incentives, 0) as protocol_earnings + , COALESCE(t.treasury_value, 0) as treasury_value + , COALESCE(tn.treasury_native, 0) as treasury_native + , COALESCE(nt.net_treasury_value, 0) as net_treasury_value + , COALESCE(s.amount_staked_usd, 0) as net_deposits + , COALESCE(s.num_staked_eth, 0) as outstanding_supply + , COALESCE(s.amount_staked_usd, 0) as tvl + , COALESCE(s.amount_staked_usd, 0) as amount_staked_usd + , COALESCE(s.num_staked_eth, 0) as num_staked_eth + , COALESCE(p.fdmc, 0) as fdmc + , COALESCE(p.market_cap, 0) as market_cap + , COALESCE(p.token_volume, 0) as token_volume + , COALESCE(p.token_turnover_fdv, 0) as token_turnover_fdv + , COALESCE(p.token_turnover_circulating, 0) as token_turnover_circulating + , COALESCE(th.token_holder_count, 0) as token_holder_count +from staked_eth_metrics s +left join fees_revenue_expenses f using(date) +left join treasury_cte t using(date) +left join treasury_native_cte tn using(date) +left join net_treasury_cte nt using(date) +left join token_incentives_cte ti using(date) +left join price_data p using(date) +left join tokenholder_cte th using(date) +where s.date < current_date() \ No newline at end of file diff --git a/models/projects/lido/core/ez_lido_metrics_by_chain.sql b/models/projects/lido/core/ez_lido_metrics_by_chain.sql index c200f3de..aefbf4fb 100644 --- a/models/projects/lido/core/ez_lido_metrics_by_chain.sql +++ b/models/projects/lido/core/ez_lido_metrics_by_chain.sql @@ -9,24 +9,108 @@ }} with - staked_eth_metrics as ( + fees_revenue_expenses as ( + SELECT + date + , block_rewards + , mev_priority_fees + , total_staking_yield as fees + , operating_expenses + , protocol_revenue + , primary_supply_side_revenue + , secondary_supply_side_revenue + , total_supply_side_revenue + FROM {{ ref('fact_lido_fees_revs_expenses') }} + ) + , token_incentives_cte as ( + SELECT + date + , sum(amount_usd) as token_incentives + FROM + {{ ref('fact_lido_token_incentives') }} + GROUP BY 1 + ) + , staked_eth_metrics as ( select - date, - 'ethereum' as chain, - num_staked_eth, - amount_staked_usd, - num_staked_eth_net_change, - amount_staked_usd_net_change + date + , num_staked_eth + , amount_staked_usd + , num_staked_eth_net_change + , amount_staked_usd_net_change from {{ ref('fact_lido_staked_eth_count_with_USD_and_change') }} ) + , treasury_cte as ( + SELECT + date + , sum(usd_balance) as treasury_value + FROM + {{ ref('fact_lido_dao_treasury') }} + GROUP BY 1 + ) + , treasury_native_cte as ( + SELECT + date + , sum(native_balance) as treasury_native + FROM + {{ ref('fact_lido_dao_treasury') }} + where token = 'LDO' + GROUP BY 1 + ) + , net_treasury_cte as ( + SELECT + date + , sum(usd_balance) as net_treasury_value + FROM {{ ref('fact_lido_dao_treasury') }} + where token <> 'LDO' + group by 1 + ) + , price_data as ( + {{ get_coingecko_metrics('lido-dao') }} + ) + , tokenholder_cte as ( + SELECT + date, + token_holder_count + FROM + {{ ref('fact_ldo_tokenholder_count')}} + ) select - staked_eth_metrics.date, - 'lido' as app, - 'DeFi' as category, - staked_eth_metrics.chain, - staked_eth_metrics.num_staked_eth, - staked_eth_metrics.amount_staked_usd, - staked_eth_metrics.num_staked_eth_net_change, - staked_eth_metrics.amount_staked_usd_net_change -from staked_eth_metrics -where staked_eth_metrics.date < to_date(sysdate()) + s.date + , 'lido' as app + , 'DeFi' as category + , 'ethereum' as chain + , COALESCE(s.num_staked_eth, 0) as num_staked_eth + , COALESCE(s.amount_staked_usd, 0) as amount_staked_usd + , COALESCE(s.num_staked_eth_net_change, 0) as num_staked_eth_net_change + , COALESCE(s.amount_staked_usd_net_change, 0) as amount_staked_usd_net_change + , COALESCE(f.mev_priority_fees, 0) as mev_priority_fees + , COALESCE(f.block_rewards, 0) as block_rewards + , COALESCE(f.fees, 0) as fees + , COALESCE(f.primary_supply_side_revenue, 0) as primary_supply_side_revenue + , COALESCE(f.secondary_supply_side_revenue, 0) as secondary_supply_side_revenue + , COALESCE(f.total_supply_side_revenue, 0) as total_supply_side_revenue + , COALESCE(f.protocol_revenue, 0) as protocol_revenue + , COALESCE(f.operating_expenses, 0) as operating_expenses + , COALESCE(ti.token_incentives, 0) as token_incentives + , COALESCE(f.protocol_revenue, 0) - COALESCE(f.operating_expenses, 0) - COALESCE(ti.token_incentives, 0) as protocol_earnings + , COALESCE(t.treasury_value, 0) as treasury_value + , COALESCE(tn.treasury_native, 0) as treasury_native + , COALESCE(nt.net_treasury_value, 0) as net_treasury_value + , COALESCE(s.amount_staked_usd, 0) as net_deposits + , COALESCE(s.num_staked_eth, 0) as outstanding_supply + , COALESCE(s.amount_staked_usd, 0) as tvl + , COALESCE(p.fdmc, 0) as fdmc + , COALESCE(p.market_cap, 0) as market_cap + , COALESCE(p.token_volume, 0) as token_volume + , COALESCE(p.token_turnover_fdv, 0) as token_turnover_fdv + , COALESCE(p.token_turnover_circulating, 0) as token_turnover_circulating + , COALESCE(th.token_holder_count, 0) as token_holder_count +from staked_eth_metrics s +left join fees_revenue_expenses f using(date) +left join treasury_cte t using(date) +left join treasury_native_cte tn using(date) +left join net_treasury_cte nt using(date) +left join token_incentives_cte ti using(date) +left join price_data p using(date) +left join tokenholder_cte th using(date) +where s.date < current_date() \ No newline at end of file diff --git a/models/projects/lido/core/ez_lido_metrics_by_token.sql b/models/projects/lido/core/ez_lido_metrics_by_token.sql new file mode 100644 index 00000000..fa214fa7 --- /dev/null +++ b/models/projects/lido/core/ez_lido_metrics_by_token.sql @@ -0,0 +1,109 @@ +{{ + config( + materialized="table", + snowflake_warehouse="LIDO", + database="lido", + schema="core", + alias="ez_metrics_by_token", + ) +}} + +WITH + fees AS ( + SELECT + date + , 'ETH' AS token + , block_rewards_native + , mev_priority_fees_native + , total_staking_yield_native AS fees + FROM {{ ref('fact_lido_fees_revs_expenses') }} + ) + , revenues_expenses AS ( + SELECT + date + , 'stETH' AS token + , operating_expenses_native + , protocol_revenue_native + , primary_supply_side_revenue_native + , secondary_supply_side_revenue_native + , total_supply_side_revenue_native + FROM {{ ref('fact_lido_fees_revs_expenses') }} + ) + , token_incentives_cte AS ( + SELECT + date + , token + , amount_native AS token_incentives_native + FROM + {{ ref('fact_lido_token_incentives') }} + ) + , eth_deposited AS ( + SELECT + date + , 'ETH' AS token + , num_staked_eth + FROM {{ ref('fact_lido_staked_eth_count_with_USD_and_change') }} + ) + , steth_outstanding AS ( + SELECT + date + , 'stETH' AS token + , num_staked_eth AS outstanding_supply_native + FROM {{ ref('fact_lido_staked_eth_count_with_USD_and_change') }} + ) + , treasury_cte AS ( + SELECT + date + , token + , SUM(native_balance) AS treasury_value_native + FROM + {{ ref('fact_lido_dao_treasury') }} + GROUP BY 1, 2 + ) + , treasury_native_cte AS ( + SELECT + date + , token + , SUM(native_balance) AS treasury_native + FROM + {{ ref('fact_lido_dao_treasury') }} + WHERE token = 'LDO' + GROUP BY 1, 2 + ) + , net_treasury_cte AS ( + SELECT + date + , token + , SUM(native_balance) AS net_treasury_value_native + FROM {{ ref('fact_lido_dao_treasury') }} + WHERE token <> 'LDO' + GROUP BY 1, 2 + ) +SELECT + date + , token + , COALESCE(f.mev_priority_fees_native, 0) AS mev_priority_fees + , COALESCE(f.block_rewards_native, 0) AS block_rewards + , COALESCE(f.fees, 0) AS fees + , COALESCE(primary_supply_side_revenue_native, 0) AS primary_supply_side_revenue + , COALESCE(secondary_supply_side_revenue_native, 0) AS secondary_supply_side_revenue + , COALESCE(total_supply_side_revenue_native, 0) AS total_supply_side_revenue + , COALESCE(protocol_revenue_native, 0) AS protocol_revenue + , COALESCE(operating_expenses_native, 0) AS operating_expenses + , COALESCE(ti.token_incentives_native, 0) AS token_incentives + , COALESCE(protocol_revenue_native, 0) - COALESCE(operating_expenses_native, 0) - COALESCE(ti.token_incentives_native, 0) AS protocol_earnings + , COALESCE(t.treasury_value_native, 0) AS treasury_value + , COALESCE(tn.treasury_native, 0) AS treasury_native + , COALESCE(nt.net_treasury_value_native, 0) AS net_treasury_value + , COALESCE(s.num_staked_eth, 0) AS net_deposits + , COALESCE(sto.outstanding_supply_native, 0) AS outstanding_supply + , COALESCE(s.num_staked_eth, 0) AS tvl +FROM fees f +FULL JOIN revenues_expenses e USING (date, token) +FULL JOIN treasury_cte t USING(date, token) +FULL JOIN treasury_native_cte tn USING(date, token) +FULL JOIN net_treasury_cte nt USING(date, token) +FULL JOIN token_incentives_cte ti USING(date, token) +LEFT JOIN steth_outstanding sto USING(date, token) +LEFT JOIN eth_deposited s USING(date, token) +WHERE date < CURRENT_DATE() \ No newline at end of file diff --git a/models/projects/lido/raw/fact_ldo_tokenholder_count.sql b/models/projects/lido/raw/fact_ldo_tokenholder_count.sql new file mode 100644 index 00000000..b37fe7c0 --- /dev/null +++ b/models/projects/lido/raw/fact_ldo_tokenholder_count.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized="table", + snowflake_warehouse="LIDO", + database="lido", + schema="raw", + alias="fact_ldo_tokenholder_count", + ) +}} + +{{ token_holders('ethereum', '0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32', '2020-12-17')}} diff --git a/models/projects/lido/raw/fact_lido_dao_treasury.sql b/models/projects/lido/raw/fact_lido_dao_treasury.sql new file mode 100644 index 00000000..f243875b --- /dev/null +++ b/models/projects/lido/raw/fact_lido_dao_treasury.sql @@ -0,0 +1,11 @@ +{{ + config( + materialized="table", + snowflake_warehouse="LIDO", + database="lido", + schema="raw", + alias="fact_lido_dao_treasury", + ) +}} + +{{ get_treasury_balance('ethereum', '0x3e40d73eb977dc6a537af587d48316fee66e9c8c')}} \ No newline at end of file diff --git a/models/projects/lido/raw/fact_lido_fees_revs_expenses.sql b/models/projects/lido/raw/fact_lido_fees_revs_expenses.sql new file mode 100644 index 00000000..7ce49547 --- /dev/null +++ b/models/projects/lido/raw/fact_lido_fees_revs_expenses.sql @@ -0,0 +1,71 @@ +{{ + config( + materialized="table", + snowflake_warehouse="LIDO", + database="lido", + schema="raw", + alias="fact_fees_revs_expenses", + ) +}} + +with steth_prices as ( + SELECT + hour, + price as price + FROM + ethereum_flipside.price.ez_prices_hourly + WHERE token_address = lower('0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84') +) +, fees_revs_expenses as ( + select + date(block_timestamp) as date + , 'ethereum' as chain + , 'stETH' as token + , sum(raw_amount_precise::number / 1e18 * 20) as total_staking_yield_native + , sum(raw_amount_precise::number / 1e18 * p.price * 20) as total_staking_yield_usd + from + ethereum_flipside.core.fact_token_transfers t + left join steth_prices p on date_trunc('hour', t.block_timestamp) = p.hour + where + contract_address = lower('0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84') + and from_address = lower('0x0000000000000000000000000000000000000000') + and to_address = lower('0x3e40d73eb977dc6a537af587d48316fee66e9c8c') + and origin_function_signature <> lower('0xf98a4eca') + group by 1 +) +, mev as ( + SELECT + date(hour) as date + , COALESCE(pc_dbt_db.prod.HEX_TO_INT(data)::number,0) / 1e18 as mev_priority_fees_amount_eth + , COALESCE(pc_dbt_db.prod.HEX_TO_INT(data)::number,0) / 1e18 * COALESCE(p.price, 0) as mev_priority_fees_amount_usd + FROM + ethereum_flipside.core.fact_event_logs l + LEFT JOIN ethereum_flipside.price.ez_prices_hourly p ON p.hour = date_trunc('hour', l.block_timestamp) + AND p.symbol = 'ETH' AND is_native = True + WHERE + topics [0] = '0xd27f9b0c98bdee27044afa149eadcd2047d6399cb6613a45c5b87e6aca76e6b5' +) +SELECT + f.date + -- NATIVE + , 'ETH' as symbol + , COALESCE(f.total_staking_yield_native, 0) - COALESCE(m.mev_priority_fees_amount_eth, 0) AS block_rewards_native + , COALESCE(m.mev_priority_fees_amount_eth, 0) AS mev_priority_fees_native + , COALESCE(f.total_staking_yield_native, 0) AS total_staking_yield_native + , COALESCE(f.total_staking_yield_native, 0) * 0.05 as operating_expenses_native + , COALESCE(f.total_staking_yield_native, 0) * 0.10 as protocol_revenue_native + , block_rewards_native * 0.90 as primary_supply_side_revenue_native + , mev_priority_fees_amount_eth * 0.90 as secondary_supply_side_revenue_native + , total_staking_yield_native * 0.90 as total_supply_side_revenue_native + -- USD + , COALESCE(f.total_staking_yield_usd, 0) - COALESCE(m.mev_priority_fees_amount_usd, 0) AS block_rewards + , COALESCE(m.mev_priority_fees_amount_usd, 0) AS mev_priority_fees + , COALESCE(f.total_staking_yield_usd, 0) AS total_staking_yield + , COALESCE(f.total_staking_yield_usd, 0) * 0.05 as operating_expenses + , COALESCE(f.total_staking_yield_usd, 0) * 0.10 as protocol_revenue + , block_rewards * 0.90 as primary_supply_side_revenue + , mev_priority_fees * 0.90 as secondary_supply_side_revenue + , total_staking_yield * 0.90 as total_supply_side_revenue +FROM + fees_revs_expenses f +LEFT JOIN mev m ON m.date = f.date \ No newline at end of file diff --git a/models/projects/lido/raw/fact_lido_token_incentives.sql b/models/projects/lido/raw/fact_lido_token_incentives.sql new file mode 100644 index 00000000..15a083d3 --- /dev/null +++ b/models/projects/lido/raw/fact_lido_token_incentives.sql @@ -0,0 +1,37 @@ +{{ + config( + materialized="table", + snowflake_warehouse="LIDO", + database="lido", + schema="raw", + alias="fact_lido_token_incentives", + ) +}} + +with ldo_prices as ( + SELECT + hour + , price + , token_address + , symbol + FROM ethereum_flipside.price.ez_prices_hourly + WHERE token_address in ( + lower('0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32'), + lower('0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84') + ) +) +select + date(p.hour) as date + , symbol as token + , sum(coalesce(t.raw_amount_precise::number / 1e18,0)) as amount_native + , sum(coalesce(t.raw_amount_precise::number / 1e18 * p.price,0)) as amount_usd +from ldo_prices p +LEFT JOIN ethereum_flipside.core.fact_token_transfers t + ON p.hour = DATE_TRUNC('hour', t.block_timestamp) + AND p.token_address = t.contract_address + AND t.from_address IN ( + LOWER('0x87d93d9b2c672bf9c9642d853a8682546a5012b5'), + LOWER('0x753D5167C31fBEB5b49624314d74A957Eb271709') + ) + and contract_address in (lower('0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32'), lower('0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84')) +GROUP BY 1, 2 \ No newline at end of file