Query editor
/* Dune: @gasweighing & Twitter/X: @Selectrong */with date_parameter as (select casewhen '{{timeframe}}' = 'show all time' then date '2024-12-01' --- sonic launch datewhen '{{timeframe}}' = 'past one year' then now() - interval '1' yearwhen '{{timeframe}}' = 'past six months' then now() - interval '6' monthwhen '{{timeframe}}' = 'past three months' then now() - interval '3' monthwhen '{{timeframe}}' = 'past one month' then now() - interval '1' monthwhen '{{timeframe}}' = 'past two weeks' then now() - interval '14' daywhen '{{timeframe}}' = 'past one week' then now() - interval '7' dayend as start_date), deposited as (select date_trunc('day', block_time) as txn_date, contract_address, 'deposited' as event, bytearray_substring("data", 141, 20) as asset_address, bytearray_to_uint256(bytearray_substring("data", 193, 32)) as asset_amount_raw, bytearray_to_uint256(bytearray_substring("data", 65, 32)) / 1e18 as vault_token_amount, tx_hashfrom sonic.logsjoin date_parameter dp on block_time >= dp.start_datewhere contract_address in (0xa51e7204054464e656b3658e7dbb63d9b0f150f1, 0x2fbeba931563feaab73e8c66d7499c49c8ada224)and topic0 = 0x39e231aec7d812a6b5ca9261d41ea0e91726779c6ad9074cb9a68fa7af4525cb), withdrawn as (select date_trunc('day', block_time) as txn_date, contract_address, 'withdrawn' as event, bytearray_substring("data", 141, 20) as asset_address, bytearray_to_uint256(bytearray_substring("data", 193, 32)) as asset_amount_raw, bytearray_to_uint256(bytearray_substring("data", 33, 32)) / 1e18 as vault_token_amount, tx_hashfrom sonic.logsjoin date_parameter dp on block_time >= dp.start_datewhere contract_address in (0xa51e7204054464e656b3658e7dbb63d9b0f150f1, 0x2fbeba931563feaab73e8c66d7499c49c8ada224)and topic0 = 0xf6f76fa9e624451c5234aa077063a68dad722c8790170478f0b28b3dc3722bcc), merged as (select * from depositedunion allselect * from withdrawn), price_details as (select date_trunc('day', "minute") as mkt_date, symbol, decimals, contract_address, avg(price) as mkt_pricefrom prices.usdwhere blockchain = 'sonic'and contract_address in (0x29219dd400f2bf60e5a23d13be72b486d4038894, --- usdc.e0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, --- ws0x50c42deacd8fc9773493ed674b675be577f2634b --- weth)and (casewhen '{{current_date}}' = 'include'then date_trunc('day', "minute") <= date_trunc('day', current_date)