Query editor
withliquidations as (withsupported_tokens as (SELECTaccount_bank as bank, account_bankMint as bank_mint, call_block_slotFROM marginfi_solana.marginfi_call_lendingPoolAddBankWHERE account_marginfiGroup = '4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8')SELECTdate_trunc('day', liq.call_block_time) as day, case when tk.token_mint_address = '3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh' then 'WBTC'when tk.token_mint_address = 'bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1' then 'bSOL'when tk.token_mint_address = '7kbnvuGBxxj8AG9qp8Scn56muWGaRaFqxg1FsRp3PaFT' then 'UXD'when tk.token_mint_address = 'RLBxxFkseAZ4RgJH3Sqn8jXxhmGoz9jWxDNJMh8pL7a' then 'RLB'else tk.symbolend as symbol, count(*) as number_of_liquidations, sum(liq.assetAmount/(pow(10,tk.decimals))*COALESCE(p.price,dp.price)) as usd_asset_amount_liquidated, sum(liq.assetAmount/(pow(10,tk.decimals))) as asset_amount_liquidatedFROM marginfi_solana.marginfi_call_lendingAccountLiquidate liqLEFT JOIN supported_tokens st ON st.bank = liq.account_assetBankLEFT JOIN tokens_solana.fungible tk ON tk.token_mint_address = st.bank_mintLEFT JOIN prices.usd p ON p.blockchain = 'solana' and toBase58(contract_address) = tk.token_mint_address and date_trunc('day', liq.call_block_time) = p.minuteLEFT JOIN (SELECT day, token_mint_address, avg(median_price) as price FROM dune.dune.result_dex_prices_solana GROUP BY 1,2 ) dpON dp.token_mint_address = tk.token_mint_address and date_trunc('day', liq.call_block_time) = dp.dayWHERE tk.token_mint_address is not nullAND liq.account_marginfiGroup = '4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8'AND liq.call_block_time > timestamp '{{liquidations_start_date}}'group by 1,2), date_generator as (with time_seq as (SELECTsequence(cast((SELECT min(day) FROM liquidations) as timestamp), date_trunc('day', cast(now() as timestamp)), interval '1' day) as time), days as (SELECTtimes.time as dayFROM time_seqCROSS JOIN unnest(time) as times(time) --this is just doing explode like in spark sql)SELECTday, symbolFROM daysLEFT JOIN (SELECT distinct symbol FROM liquidations) on true)