Query editor
with fees as (selectdate_trunc('day',block_time) as day,sum(case when token_sold_address = 0x89c49a3fa372920ac23ce757a029e6936c0b8e02 then token_sold_amount * 0.005 else 0 end) as cu_fees,sum(case when token_sold_address = 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 then token_sold_amount * 0.005 else 0 end) as eth_fees,count(*) as num_swapsfrom camelot.tradeswhere blockchain = 'arbitrum'and project_contract_address = 0x75e1a0dda0f7d3ca5d8960875e306533e7259609--and (token_bought_address = 0x89C49A3fA372920aC23ce757A029e6936c0b8e02 or token_sold_address = 0x89C49A3fA372920aC23ce757A029e6936c0b8e02)group by 1order by 1 desc),daily_lp as (selectdate_trunc('day', evt_block_time) as day,sum(case when to = 0x149b5c8d045a5c8f5a3e1069a3a58fa86619b3ae then value/1e18 else 0 end) as lp_in,sum(case when "from" = 0x149b5c8d045a5c8f5a3e1069a3a58fa86619b3ae then value/1e18 else 0 end) as lp_out,sum(case when to = 0x0000000000000000000000000000000000000000 then value/1e18 else 0 end) as lp_burn,sum(case when "from" = 0x0000000000000000000000000000000000000000 then value/1e18 else 0 end) as lp_mintfrom erc20_arbitrum.evt_Transferwhere contract_address = 0x75e1a0dda0f7d3ca5d8960875e306533e7259609--and to <> 0x159e9223128291CE79326b4632572F6ea7A631d2group by 1),days as (selectcast(day as timestamp) as dayfrom unnest(sequence(date('2024-05-06'), cast(now() as date), interval '1' day)) as t(day)),pct_owned as (selectd.day,--sum(coalesce(lp_in,0)) over (order by d.day) as total_in,--sum(coalesce(lp_out,0)) over (order by d.day) as total_out,sum(coalesce(lp_in,0)) over (order by d.day) - sum(coalesce(lp_out,0)) over (order by d.day) as balance,sum(coalesce(lp_mint,0)) over (order by d.day) - sum(coalesce(lp_burn,0)) over (order by d.day) as tot_circ,(sum(coalesce(lp_in,0)) over (order by d.day) - sum(coalesce(lp_out,0)) over (order by d.day)) /(sum(coalesce(lp_mint,0)) over (order by d.day) - sum(coalesce(lp_burn,0)) over (order by d.day) ) as pct_ownfrom days dleft join daily_lp l on d.day = l.day),daily_info as (selectf.day as day,f.cu_fees as tot_f_rbw,f.eth_fees as tot_f_eth,o.pct_own as pct_own,f.cu_fees * o.pct_own as lg_f_rbw, --cu fees based on daily pct_owned of poolf.eth_fees * o.pct_own as lg_f_eth --eth fees based on daily pct_owned of poolfrom fees fleft join pct_owned o on f.day = o.dayorder by 1 desc),summary as (selectdate_trunc('day', day) as month,sum(lg_f_rbw) as lg_rbw_fees,sum(lg_f_eth) as lg_eth_fees,avg(pct_own) as pct_own