Query editor
with price as (select symbol , decimals, avg(token_price_usd) as pricefrom dex.prices_latest,tokens.erc20where token_address = 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599and contract_address = 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599and blockchain = 'ethereum'group by 1,2),raw as (select "from" as address, sum(cast(value as double)*-1) as amountfromerc20_ethereum.evt_Transferwhere contract_address = 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599group by 1union allselect "to" as address, sum(cast(value as double)) as amountfrom erc20_ethereum.evt_Transferwhere contract_address = 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599group by 1),evm_raw as (selectcase when address in (0x47c031236e19d024b42f8AE6780E44A573170703,0x489ee077994B6658eAfA855C308275EAd8097C4A,0xAE1ec28d6225dCE2ff787dcb8CE11cF6D3AE064f,0x9ab2De34A33fB459b538c43f251eB825645e8595,0x3e0199792Ce69DC29A0a36146bFa68bd7C8D6633,0x32B7bF19cb8b95C27E644183837813d4b595dcc6) then 'Perps'when address in (0x5c2ed810328349100A66B82b78a1791B101C9D61,0x727354712BDFcd8596a3852Fd2065b3C34F4F770,0xF25212E676D1F7F89Cd72fFEe66158f541246445,0x9c4ec768c28520B50860ea7a15bd7213a9fF58bf,0x686bEF2417b6Dc32C50a3cBfbCC3bb60E1e9a15D,0x69eC552BE56E6505703f0C861c40039e5702037A,0x33865E09A572d4F1CC4d75Afc9ABcc5D3d4d867D,0xD3204E4189BEcD9cD957046A8e4A643437eE0aCC,0xe194c4c5aC32a3C9ffDb358d9Bfd523a0B6d1568,0xC37896BF3EE5a2c62Cdbd674035069776f721668) then 'Lending'when address in (0x4585FE77225b41b697C938B018E2Ac67Ac5a20c0,0x2f5e87C9312fa29aed5c179E456625D79015299c,0xeFF23B4bE1091b53205E35f3AfCD9C7182bf3062,0x50eaEDB835021E4A108B7290636d62E9765cc6d7) then 'Spot Trading' end as type,sum(amount) as amount,sum(amount*price) as valuefrom (select "from" as address, sum(cast(value as double)/1e8*-1) as amountfromevms.erc20_transferswhere((contract_address = 0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f and blockchain = 'arbitrum')or