Query editor
select*from(selectcasewhen tx_count =2 and buy_token_eth < 0 AND sell_to_eth > 0 AND is_equal_amount=1 then 'Simple Sandwich'else 'Complex Sandwich'end as mev_type, casewhen base_trading_type='SELL' then 'Coin_Base_Sandwich'else 'ETH_Base_Sandwich'end as Sandwich_type,*from(SELECTtoken_pair,block_number,COUNT(*) AS trading_count,COUNT(distinct tx_hash) AS tx_count,ARRAY_AGG(DISTINCT tx_hash) AS unique_tx_hashes,SUM(sell_to_eth) AS sell_to_eth,SUM(buy_token_eth) AS buy_token_eth,SUM(sell_to_eth) + SUM(buy_token_eth) AS revenue,SUM(CASE WHEN trading_type = 'SELL' THEN sell_token_amount ELSE 0 END) as sell_token_amount,SUM(CASE WHEN trading_type = 'BUY' THEN buy_token_amount ELSE 0 END) as buy_token_amount,case when (ABS(SUM(CASE WHEN trading_type = 'SELL' THEN sell_token_amount ELSE 0 END) / ABS(SUM(CASE WHEN trading_type = 'BUY' THEN buy_token_amount ELSE 0 END))) -1) <=0 and (ABS(SUM(CASE WHEN trading_type = 'SELL' THEN sell_token_amount ELSE 0 END) / ABS(SUM(CASE WHEN trading_type = 'BUY' THEN buy_token_amount ELSE 0 END))) -1) >=-0.1 then 1 else 0 end as is_equal_amount,max(base_trading_type) as base_trading_typeFROM(select*,FIRST_VALUE(trading_type) OVER (PARTITION BY token_pair, block_number ORDER BY index) AS base_trading_typefrom(SELECT*,CASE WHEN token_bought_symbol = 'WETH' THEN 'SELL' ELSE 'BUY' END AS trading_type,CASE WHEN token_bought_symbol = 'WETH' THEN token_bought_amount ELSE 0 END AS sell_to_eth,CASE WHEN token_bought_symbol != 'WETH' THEN token_sold_amount * (-1) ELSE 0 END AS buy_token_eth,CASE WHEN token_bought_symbol = 'WETH' THEN token_sold_amount ELSE 0 END AS sell_token_amount,CASE WHEN token_bought_symbol != 'WETH' THEN token_bought_amount ELSE 0 END AS buy_token_amountFROM dex.tradesWHERE blockchain = 'ethereum'AND tx_to = {{wallet}}and tx_from=0xae2fc483527b8ef99eb5d9b44875f005ba1fae13-- AND tx_hash IN (SELECT evt_tx_hash FROM sandwich_mev_detail GROUP BY 1)and date(block_time)= timestamp '{{stat_date}}'ORDER BY block_number, token_pair, evt_index) aleft join(selecthash,indexfrom ethereum.transactions)bon a.tx_hash=b.hash