Query editor
with date_parameter as (select casewhen '{{timeframe}}' = 'show all time' then date '2024-12-01'when '{{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), liquidation as (select date_trunc('day', block_time) as txn_date, tx_hash as txn_hash, bytearray_substring(topic1, 13, 20) as collateral_asset, bytearray_substring(topic2, 13, 20) as debt_asset, bytearray_substring(topic3, 13, 20) as user_address, bytearray_to_uint256(bytearray_substring(data, 1, 32)) as debt_to_cover_amount_raw, bytearray_to_uint256(bytearray_substring(data, 33, 32)) as liquidated_collateral_amount_raw, concat('0x', lower( to_hex( bytearray_substring(data, 77, 20)))) as liquidator, (bytearray_to_uint256(bytearray_substring(data, 97, 32)) = 1) as receive_atokenfrom sonic.logsjoin date_parameter dp on block_time >= dp.start_datewhere contract_address = 0x5362dbb1e601abf3a4c14c22ffeda64042e5eaa3and topic0 = 0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286and (casewhen '{{current_date}}' = 'include'then date_trunc('day', block_time) <= date_trunc('day', current_date)elsedate_trunc('day', block_time) < date_trunc('day', current_date)end)), asset_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)elsedate_trunc('day', "minute") < date_trunc('day', current_date)end)group by 1, 2, 3, 4), pricing as (select l.txn_date, l.txn_hash