Query editor
with all_purchase as (select sum(value/1e18) as stablecoin_purchase_amount, "from" as userfrom erc20_bnb.evt_Transferwhere contract_address in (0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56, 0x55d398326f99059fF775485246999027B3197955) --usdc, usdt contractand evt_tx_hash in (select tx_hashfrom bnb.logswhere topic0 = 0x2499a5330ab0979cc612135e7883ebc3cd5c9f7a8508f042540c34723348f632)and "to" in ({{sale_contract_bsc}})group by 2unionselect sum(value/1e6) as stablecoin_purchase_amount, "from" as userfrom erc20_arbitrum.evt_Transferwhere contract_address in (0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9, 0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8) --usdc, usdt contractand evt_tx_hash in (select tx_hashfrom arbitrum.logswhere topic0 = 0x2499a5330ab0979cc612135e7883ebc3cd5c9f7a8508f042540c34723348f632)and "to" in ({{sale_contract_arb}})group by 2),transfer_out as (select sum(value/1e18) as total_amount_transfer_out, "from" as userfrom erc20_bnb.evt_Transferwhere contract_address = {{sale_token_address_bsc}}and "from" in (select user from all_purchase)group by 2unionselect sum(value/1e18) as total_amount_transfer_out, "from" as userfrom erc20_arbitrum.evt_Transferwhere contract_address = {{sale_token_address_arb}}and "from" in (select user from all_purchase)group by 2),transfer_in as (select sum(value/1e18) as total_amount_transfer_in, "to" as userfrom erc20_bnb.evt_Transferwhere contract_address = {{sale_token_address_bsc}}and "to" in (select user from all_purchase)group by 2unionselect sum(value/1e18) as total_amount_transfer_in, "to" as userfrom erc20_arbitrum.evt_Transferwhere contract_address = {{sale_token_address_arb}}and "to" in (select user from all_purchase)group by 2),sell as (select sum(value/1e18) as total_amount_sell, "from" as userfrom erc20_bnb.evt_Transferwhere contract_address = {{sale_token_address_bsc}}and evt_tx_hash in (select tx_hashfrom bnb.logswhere topic0 = 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822) --swap hashand "from" in (select user from all_purchase)group by 2unionselect sum(value/1e18) as amount_sell, "from" as userfrom erc20_arbitrum.evt_Transfer