Query editor
/* select*from dune.lagunagames12_team.dataset_erc20_transfers*/WITH cu_in_lg AS (select date_trunc('day',cast(block_timestamp as timestamp)) as day, sum(value_raw/1e18) as cufrom dune.lagunagames12_team.dataset_erc20_transferswhere contract_address = 0x89C49A3fA372920aC23ce757A029e6936c0b8e02 -- CUand to_address = 0x94f557dDdb245b11d031F57BA7F2C4f28C4A203e --Game Bank Addressand from_address in (0x03675e71e11b96ab4965c03044585ddcdb20e26f,0xb16bbba07851dd3d58846f923730ff816c12a2c7--Add LG wallets)group by 1),days AS (selectcast(day as timestamp) as dayFROM unnest(sequence(date('2024-05-01'), cast(now() as date), interval '1' day)) as t(day)),cu_in_players AS (select date_trunc('day',cast(block_timestamp as timestamp)) as day, sum(value_raw/1e18) as cu, count(*) as txs, count(distinct(from_address)) as unique_addressesfrom dune.lagunagames12_team.dataset_erc20_transferswhere contract_address = 0x89C49A3fA372920aC23ce757A029e6936c0b8e02 -- CUand to_address = 0x94f557dDdb245b11d031F57BA7F2C4f28C4A203e --Game Bank Addressand from_address not IN (0x03675e71e11b96ab4965c03044585ddcdb20e26f,0xb16bbba07851dd3d58846f923730ff816c12a2c7 --cu addresses)group by 1),cu_out_players AS (select date_trunc('day',cast(block_timestamp as timestamp)) as day, -1*sum(value_raw/1e18) as cu, count(*) as txs, count(distinct(to_address)) as unique_addressesfrom dune.lagunagames12_team.dataset_erc20_transferswhere contract_address = 0x89C49A3fA372920aC23ce757A029e6936c0b8e02 -- CUand from_address = 0x94f557dDdb245b11d031F57BA7F2C4f28C4A203e --Game Bank Address--and to not IN (0x3491edaa671cd03c64300614d82fec86972f7b12)group by 1),cu_out_lg AS (select date_trunc('day',cast(block_timestamp as timestamp)) as day, -1 * sum(value_raw/1e18) as cu from dune.lagunagames12_team.dataset_erc20_transferswhere contract_address = 0x89C49A3fA372920aC23ce757A029e6936c0b8e02 -- CUand to_address = 0x149B5C8D045A5C8F5a3e1069A3A58Fa86619B3ae --Treasuryand from_address = 0x94f557dDdb245b11d031F57BA7F2C4f28C4A203e --Game Bank Addressgroup by 1--order by 1 desc)selectd.day as day,coalesce(ilg.cu,0) as cu_into_gb_lg,coalesce(i.cu,0) as cu_stashin_players,coalesce(i.txs,0) as cu_stashin_txs,coalesce(i.unique_addresses,0) as unique_add_stashin,coalesce(o.cu,0) as cu_stashout_players,coalesce(o.txs,0) as cu_stashout_txs,coalesce(o.unique_addresses,0) as unique_add_stashout,coalesce(olg.cu,0) as cu_to_treasury,coalesce(i.cu,0) + coalesce(o.cu,0) as daily_net_stash_amt,sum(coalesce(ilg.cu,0)) over (order by d.day) + sum(coalesce(i.cu,0)) over (order by d.day) +sum(coalesce(o.cu,0)) over (order by d.day) + sum(coalesce(olg.cu,0)) over (order by d.day) as cu_bank_balance