Query editor
WITH all_inflows as (SELECTblock_time ,'Inflow' as action,'ETH' as symbol,(1e0*value)/1e18 as amount_raw,(1e0*value)/1e18 * (select price from prices.usd_latest where contract_address=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2) as amount_usd,"from" ,"to" ,"hash"FROM ethereum.transactions as tmainWHERE "to" = 0x50DF5a2217588772471B84aDBbe4194A2Ed39066AND value > 0UNION ALLSELECTevt_block_time as block_time,'Inflow' as action,b.symbol as symbol,value/power(10,decimals) as amount_raw,(value/power(10,decimals)) * b.price as amount_usd,"from" ,"to" ,evt_tx_hash as "hash"FROM erc20_ethereum.evt_Transfer aLEFT JOIN prices.usd_latest b on a.contract_address = b.contract_addressWHERE "to" = 0x50DF5a2217588772471B84aDBbe4194A2Ed39066),last_transfer_to_socket as (SELECT * FROM (SELECT *, row_number() over (partition by victim order by block_time desc) as orderingFROM (SELECTblock_time ,"from" as victim,"hash"FROM ethereum.transactions as tmainWHERE "to" = 0x3a23F943181408EAC424116Af7b7790c94Cb97a5AND "from" in (select "from" from all_inflows)AND "hash" NOT IN (select distinct "hash" from all_inflows) --remove exploit txUNION ALLSELECTevt_block_time as block_time,"from" as victim,evt_tx_hash as "hash"FROM erc20_ethereum.evt_Transfer aWHERE "to" = 0x50DF5a2217588772471B84aDBbe4194A2Ed39066AND "from" in (select "from" from all_inflows)AND "evt_tx_hash" NOT IN (select distinct "hash" from all_inflows) --remove exploit txORDER BY block_time)a)bWHERE ordering = 1 --most recent transferorder by block_time DESC),