Query editor
with cex as (-- Bybit moreselect 'Bybit' as cex_name, 0x88a1493366d48225fc3cefbdae9ebb23e323ade3 as addressunion all-- okx moreselect 'OKX' as cex_name, element as addressfrom UNNEST(ARRAY[0x539c92186f7c6cc4cbf443f26ef84c595babbca1,0x868dab0b8e21ec0a48b726a1ccf25826c78c6d7f,0xbfbbfaccd1126a11b8f84c60b09859f80f3bd10f,0x313eb1c5e1970eb5ceef6aebad66b07c7338d369,0x9723b6d608d4841eb4ab131687a5d4764eb30138,0x96fdc631f02207b72e5804428dee274cf2ac0bcd,0x06d3a30cbb00660b85a30988d197b1c282c6dcb6,0x07cff3c78dc9bd2378b89b92f01254703861c2e4,0x75231f58b43240c9718dd58b4967c5114342a86c]) AS t (element)union allselect cex_name, addressfrom cex.addresseswhere cex_name in ('Binance') -- ('OKX','Binance','Bybit') -- 'Binance US'), base_tf_data as (selectdate_trunc('day',et.evt_block_time) as dt,et.contract_address as contract_address,"to" as wallet_address,et.value as value,cex.cex_name as cex_namefrom erc20_ethereum.evt_Transfer et inner join cexon et."from" = cex.addresswhere et.evt_block_time >= NOW()-INTERVAL '{{day_ago}}' dayand et."to" not in (select address from cex)and value > 0union allselectdate_trunc('day',et.block_time) as dt,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 as contract_address,"to" as wallet_address,et.value as value,cex.cex_name as cex_namefrom ethereum.transactions et inner join cexon et."from" = cex.addresswhere et.block_date >= NOW()-INTERVAL '{{day_ago}}' dayand et."to" not in (select address from cex)and value > 0), agg_data as (selectdt,wallet_address,cex_name,contract_address,sum(value) as valuefrom base_tf_datagroup by dt, wallet_address, cex_name, contract_address), token_prices as (SELECT date_trunc('day', usd.minute) as dt,contract_address,avg(usd.price) as avg_price,max(usd.decimals) as decimalsFROM prices.usd as usdwhere usd.minute >= (now() - INTERVAL '{{day_ago}}' day)