Query editor
with zyb_addresses as (select 0xeB16239E886422852b5a2B1B86d910eB72663B4a as pool, 'WBTC-USDC' as pair, array[0x82af49447d8a07e3bd95bd0d56f35241523fbab1, 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8] as pathunion allselect 0x8b8149dd385955dc1ce77a4be7700ccd6a212e65 as pool, 'WETH-USDC' as pair, array[0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f, 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8] as pathunion allselect 0x969f7699fbb9c79d8b61315630cdeed95977cfb8 as pool, 'Threepool' as pair, array[0xda10009cbd5d07dd0cecc66161fc93d7c9000da1, 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8] as pathunion allselect 0xf69223b75d9cf7c454bb44e30a3772202bee72cf as pool, 'ZYB-WETH' as pair, array[0x3b475f6f2f41853706afc9fa6a6b8c5df1a2724c, 0x82af49447d8a07e3bd95bd0d56f35241523fbab1] as pathunion allselect 0x3ec0eddcd1e25025077327886a78133589082fb2 as pool, 'ZYB-USDC' as pair, array[0x3b475f6f2f41853706afc9fa6a6b8c5df1a2724c, 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8] as pathunion allselect 0x252cd7185db7c3689a571096d5b57d45681aa080 as pool, 'DAI-USDC' as pair, array[0xda10009cbd5d07dd0cecc66161fc93d7c9000da1, 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8] as path-- union all-- select 0xf942e32861ee145963503ddb69fc3b0237f0888c as pool, 'USDT-USDC' as pair, array[0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8] as path),pair_fees as (select distinct contract_address as pool_address,cast(output_0 as double) / 1000 as feefrom zyberswap_arbitrum.ZyberPair_call_swapFeewhere call_success = true),recasted as (select date_trunc('day', evt_block_time) as dt,contract_address,cast(amount0In as double) as amount0In,cast(amount0Out as double) as amount0Out,cast(amount1In as double) as amount1In,cast(amount1Out as double) as amount1Outfrom zyberswap_arbitrum.ZyberPair_evt_Swap swap),grouped as (select swap.dt,swap.contract_address as pool_address,zyb.pair,zyb.path,sum(casewhen swap.amount0In > swap.amount1In then swap.amount0In / 1e18when swap.amount0In < swap.amount1In then swap.amount1In / 1e18else swap.amount0In / 1e18end) as input,sum(casewhen swap.amount0Out > swap.amount1Out then swap.amount0Out / 1e18when swap.amount0Out < swap.amount1Out then swap.amount1Out / 1e18-- when swap.amount0Out < swap.amount1Out AND zyb.pool = 0x252cd7185db7c3689a571096d5b57d45681aa080 then swap.amount0In / 1e18-- when swap.amount0Out > swap.amount1Out AND zyb.pool = 0x252cd7185db7c3689a571096d5b57d45681aa080 then swap.amount1In / 1e6else swap.amount0Out / 1e18end) as output,sum(casewhen swap.amount0In > swap.amount1In then swap.amount0In / 1e18 * feewhen swap.amount0In < swap.amount1In then swap.amount1In/ 1e18 * fee-- when swap.amount0In < swap.amount1In AND zyb.pool = 0x252cd7185db7c3689a571096d5b57d45681aa080 then swap.amount0In / 1e18 * fee-- when swap.amount0In > swap.amount1In AND zyb.pool = 0x252cd7185db7c3689a571096d5b57d45681aa080 then swap.amount1In / 1e6 * feeelse swap.amount0Out / 1e18 * feeend) as fee