Query editor
with index as (selectt1.day,t1.vault_address,name,asset_token,debt_token,user_address,supplied_amount_cumulative,supplied_amount_cumulative_usd,borrow_amount_cumulative,borrow_amount_cumulative_usd,lp_amount_cumulativefrom (select *from dune."0xpibs".result_euler_finance_daily_datawhere blockchain = 'sonic'-- and day >= timestamp '2024-12-16 00:00:00') t1left join (selecttf."to" as user_address,min(min(date_trunc('day', tf.evt_block_time))) over (partition by tf."to") as min_day,max(max(date_trunc('day', tf.evt_block_time))) over (partition by tf."to") as max_dayfrom erc20_sonic.evt_transfer tfwhere tf.contract_address in (select distinct contract_address from euler_v2_sonic.evault_evt_evaultcreatedunion all select dtoken from euler_v2_sonic.evault_evt_evaultcreated)-- and tf.evt_block_time >= timestamp '2024-12-16 00:00:00'group by 1) t2on t1.day >= min_day),logs as (select *from sonic.logswhere topic0 = 0x67cb2734834e775d6db886bf16ac03d7273b290223ee5363354b385ec5b643b0and logs.block_time >= timestamp '2024-12-16 00:00:00'),transfers as (select *from erc20_sonic.evt_transferwhere contract_address in (select distinct debt_token from index union select distinct vault_address from index)),missing_tokens (contract_address, symbol, decimals) as (values(0xbe27993204ec64238f71a527b4c4d5f4949034c3, 'PT-wstkscUSD-29MAY2025', 6),(0x46eb02b9f47634c4fab3110cc7adc1c6311dfac1, 'PT-wOS-29MAY2025', 18),(0x420df605d062f8611efb3f203bf258159b8fffde, 'PT-stS-29MAY2025', 18),(0xa2161e75edf50d70544e6588788a5732a3105c00, 'PT-wstkscETH-29MAY2025', 18),(0x2fd7ccda50ed88fe17e15f3d5d8d51da4ccb43f3, 'scUSDUSDC', 18),(0xff11f56281247ead18db76fd23b252156738fa94, 'scETH/WETH', 18)),debt_total as (selectt1.day,t1.debt_token,sum(sum(amount)) over (partition by t1.debt_token order by t1.day) as amount_cumulativefrom (select *from dune."0xpibs".result_euler_finance_daily_datawhere blockchain = 'sonic') t1left join (selectdate_trunc('day', evt_block_time) as day,contract_address,sum(case when "from" = 0x0000000000000000000000000000000000000000 then 1 else - 1 end * cast(value as double)) as amountfrom transferswhere contract_address in (select distinct debt_token from index)and ("from" = 0x0000000000000000000000000000000000000000or "to" = 0x0000000000000000000000000000000000000000)