Skip to content

Commit

Permalink
Added more Drift revenue + data (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunny77D authored Dec 12, 2024
1 parent 43e5134 commit dd34d06
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
17 changes: 15 additions & 2 deletions models/projects/drift/core/ez_drift_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ SELECT
fact_drift_prediction_markets.date,
fact_drift_float_borrow_lending_revenue.date,
defillama_data.date,
parsed_log_metrics.date
parsed_log_metrics.date,
fact_drift_amm_revenue.date
) as date,
'drift' AS app,
'DeFi' AS category,
Expand All @@ -45,12 +46,24 @@ SELECT
parsed_log_metrics.spot_fees,
parsed_log_metrics.spot_revenue,
parsed_log_metrics.spot_trading_volume,
total_revenue as excess_pnl_daily_change,
coalesce(float_revenue, 0) +
coalesce(lending_revenue, 0) +
coalesce(parsed_log_metrics.perp_revenue, 0) +
coalesce(parsed_log_metrics.spot_revenue, 0) as old_revenue,
coalesce(float_revenue, 0) +
coalesce(lending_revenue, 0) +
coalesce(parsed_log_metrics.perp_revenue, 0) +
coalesce(parsed_log_metrics.spot_revenue, 0) as revenue,
coalesce(parsed_log_metrics.perp_fees + parsed_log_metrics.spot_fees, 0) as fees
total_revenue - (coalesce(float_revenue, 0) +
coalesce(lending_revenue, 0) +
coalesce(parsed_log_metrics.perp_revenue, 0) +
coalesce(parsed_log_metrics.spot_revenue, 0)) as amm_revenue,
coalesce(parsed_log_metrics.perp_fees + parsed_log_metrics.spot_fees, 0) as fees,
latest_excess_pnl as daily_latest_excess_pnl
FROM price_data
LEFT JOIN {{ ref("fact_drift_amm_revenue") }} as fact_drift_amm_revenue
ON price_data.date = fact_drift_amm_revenue.date
FULL JOIN {{ ref("fact_drift_prediction_markets") }} as fact_drift_prediction_markets
ON price_data.date = fact_drift_prediction_markets.date
FULL JOIN {{ ref("fact_drift_float_borrow_lending_revenue") }} as fact_drift_float_borrow_lending_revenue
Expand Down
16 changes: 16 additions & 0 deletions models/staging/drift/fact_drift_amm_revenue.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{ config(materialized="table") }}

WITH fact_drift_daily_perp_data AS (
SELECT
date
, sum(latest_excess_pnl) as latest_excess_pnl
FROM
{{ref('fact_drift_daily_perp_data')}}
GROUP BY 1
)
SELECT
date
, latest_excess_pnl - LAG(latest_excess_pnl) OVER (ORDER BY date) as total_revenue
, latest_excess_pnl
FROM
fact_drift_daily_perp_data
2 changes: 1 addition & 1 deletion models/staging/drift/fact_drift_daily_perp_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SELECT
AVG(value:oi::float) as daily_avg_open_interest,
AVG(value:oi_net::float) as daily_avg_net_open_interest,
AVG(value:net_user_pnl::float) as daily_avg_net_user_pnl,
AVG(value:excess_pnl::float) as daily_avg_excess_pnl,
MAX_BY(value:excess_pnl::float, TO_TIMESTAMP(value:timestamp::string, 'YYYY/MM/DD HH24:MI:SS')) as latest_excess_pnl,
AVG(value:est_funding_dollars::float) as daily_avg_est_funding_dollars
FROM {{ source("PROD_LANDING", "raw_drift_perp_market_data") }} ,
lateral flatten(input => parse_json(source_json))
Expand Down

0 comments on commit dd34d06

Please sign in to comment.