Query editor
with base as (selectaccount_owner,sum(total_gains) as sum_gains,avg(total_gains -(-coalesce(adds_x, 0) * (price_usd_x_at_close - price_usd_x_at_open) +-coalesce(adds_y, 0) * (price_usd_y_at_close - price_usd_y_at_open))) as avg_gains_vs_hodl,sum(total_gains -(-coalesce(adds_x, 0) * (price_usd_x_at_close - price_usd_x_at_open) +-coalesce(adds_y, 0) * (price_usd_y_at_close - price_usd_y_at_open))) as sum_gains_vs_hodl,coalesce(sum(claimed_fees_usd), 0) as sum_claimed_fees_usd,coalesce(sum(adds_x_usd), 0) + coalesce(sum(adds_y_usd), 0) as sum_adds_usd,coalesce(sum(removals_x_usd), 0) + coalesce(sum(removals_y_usd), 0) as sum_removals_usd,count(*) filter (where total_gains > 0) as winning_positions,count(*) as total_positions,count(distinct account_position) as positions,max(date_closed) as last_datefrom dune.kagren0.result_dlmm_pn_l_v_4_gains_by_positionwhere(('{{History}}' = '30 days' and date_closed >= current_date - interval '30' day )or ('{{History}}' = '90 days' and date_closed >= current_date - interval '90' day )or '{{History}}' = 'Beginning of time')and price_null_count = 0group by account_owner),base_72h_ago as (selectaccount_ownerfrom dune.kagren0.result_dlmm_pn_l_v_4_gains_by_positionwheredate_closed <= current_date - interval '72' hourand (('{{History}}' = '30 days' and date_closed >= current_date - interval '30' day - interval '72' hour)or ('{{History}}' = '90 days' and date_closed >= current_date - interval '90' day - interval '72' hour)or '{{History}}' = 'Beginning of time')and price_null_count = 0group by account_owner),exclusions as (selectaccount_owner,count(distinct account_position) as bugged_positionsfrom dune.kagren0.result_dlmm_pn_l_v_4_gains_by_positionwhere price_null_count > 0group by account_owner),scoring_base as (selectaccount_owner,sum_gains,sum_claimed_fees_usd,