Query editor
withinch_hr as (select date_trunc('hour', minute) as hr, avg(price) as inch_usdfrom prices.usd where blockchain='ethereum' and contract_address = 0x111111111117dc0aa78b770fa6a738034120c302and minute >= now() - interval '{{days}}' day group by 1),inch_last as (select inch_usd from inch_hr order by hr desc limit 1),erc as (select blockchain, contract_address, symbol from (select blockchain, contract_address, symbol,row_number() over (partition by blockchain, contract_address order by symbol) rnfrom tokens.erc20 where blockchain in ('ethereum','robinhood')) where rn=1),swaps as (select 'ethereum' as chain, block_time, bytearray_substring(data,45,20) as maker,bytearray_substring(data,109,20) as token_in, bytearray_substring(data,141,20) as token_out,bytearray_to_uint256(bytearray_substring(data,161,32)) as amount_in,bytearray_to_uint256(bytearray_substring(data,193,32)) as amount_outfrom ethereum.logswhere topic0 = 0x54bc5c027d15d7aa8ae083f994ab4411d2f223291672ecd3a344f3d92dcaf8b2and contract_address = 0x111111338c5091e8440b67b168bae16a668ac0deand block_time >= now() - interval '{{days}}' dayunion allselect 'robinhood', block_time, bytearray_substring(data,45,20),bytearray_substring(data,109,20), bytearray_substring(data,141,20),bytearray_to_uint256(bytearray_substring(data,161,32)),bytearray_to_uint256(bytearray_substring(data,193,32))from robinhood.logswhere topic0 = 0x54bc5c027d15d7aa8ae083f994ab4411d2f223291672ecd3a344f3d92dcaf8b2and contract_address = 0x111111338c5091e8440b67b168bae16a668ac0deand block_time >= now() - interval '{{days}}' day),tagged as (select s.chain, s.block_time, s.maker,case when ti.symbol='1INCH' then cast(s.amount_in as double)/1e18when to2.symbol='1INCH' then cast(s.amount_out as double)/1e18 end as inch_amt,upper(case when ti.symbol='1INCH' then to2.symbol when to2.symbol='1INCH' then ti.symbol end) as pair_symfrom swaps sleft join erc ti on ti.blockchain=s.chain and ti.contract_address=s.token_inleft join erc to2 on to2.blockchain=s.chain and to2.contract_address=s.token_out),val as (select t.chain, t.maker, t.pair_sym,t.inch_amt * coalesce(h.inch_usd,(select inch_usd from inch_last),0.08) as usd,casewhen t.pair_sym in ('WETH','STETH','WSTETH','WEETH','OSETH','RETH','CBETH','ETHX','EZETH','RSETH','TETH') then 'ETH & LST'when t.pair_sym in ('USDT','USDC','GHO','USDS','DAI','USDE','PYUSD','USDG','CRVUSD','RLUSD','SUSDE','USDTB','SDAI') then 'Stablecoins'when t.pair_sym in ('WBTC','CBBTC','TBTC','LBTC','BTC.B','EBTC','FBTC','KBTC') then 'BTC'when t.pair_sym in ('UNI','AAVE','LINK','LDO','ONDO','WLD','ENA','DEXE','WLFI','SKY','VIRTUAL') then 'DeFi'when t.pair_sym in ('PAXG','XAUT','NVDAON','TSLAON','AAPLON','SPYON','METAON','AMZNON','CRCLON','GOOGLON','QQQON','NVDAX','TSLAX','AAPLX','SPYX','METAX','AMZNX','SYRUPUSDC','SYRUPUSDT','USDY','NVDA','TSLA','AAPL','SPY','META','AMZN') then 'RWA'end as categoryfrom tagged tleft join inch_hr h on h.hr = date_trunc('hour', t.block_time)where t.inch_amt is not null),pair_agg as (select chain, category, pair_sym, sum(usd) as volume_usd, count(*) as fills, count(distinct maker) as makers