Query editor
-- Panel 2: Public PnL-- Every buy and sell is public. So is the result.with p as (select from_hex(replace(lower(trim('{{wallet}}')), '0x', '')) as w),quote_tokens as (select t, kind from (values(0x82af49447d8a07e3bd95bd0d56f35241523fbab1, 'ETH'), -- WETH arbitrum(0x4200000000000000000000000000000000000006, 'ETH'), -- WETH base(0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c, 'BNB'), -- WBNB(0x55d398326f99059ff775485246999027b3197955, 'STABLE'), -- USDT bnb(0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, 'STABLE'), -- USDT arbitrum(0xaf88d065e77c8cc2239327c5edb3a432268e5831, 'STABLE'), -- USDC arbitrum(0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, 'STABLE'), -- USDC.e arbitrum(0x833589fcd6edb6e08f4c7c32d4f71b54bda02913, 'STABLE'), -- USDC base(0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d, 'STABLE'), -- USDC bnb(0xe9e7cea3dedca5984780bafc599bd69add087d56, 'STABLE'), -- BUSD bnb(0x8d0d000ee44948fc98c9b98a4fa4921476f08b0d, 'STABLE'), -- USD1 bnb(0xda10009cbd5d07dd0cecc66161fc93d7c9000da1, 'STABLE'), -- DAI arbitrum(0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f, 'OTHER'), -- WBTC arbitrum(0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c, 'OTHER') -- BTCB bnb) as x(t, kind)),trades as (select blockchain, block_time, tx_hash, evt_index,token_bought_address, token_sold_address,token_bought_symbol, token_sold_symbol,token_bought_amount, token_sold_amount, amount_usdfrom dex.tradeswhere taker = (select w from p)and blockchain in ('arbitrum','base','bnb')and block_month >= date_trunc('month', current_date - interval '90' day)and block_date >= current_date - interval '90' day),valued as (select t.*,coalesce(t.amount_usd,-- hardcoded fallback prices (no prices.usd_latest): ETH 2400, BNB 700, stables 1case qs.kindwhen 'ETH' then t.token_sold_amount * 2400.0when 'BNB' then t.token_sold_amount * 700.0when 'STABLE' then t.token_sold_amount * 1.0end,case qb.kindwhen 'ETH' then t.token_bought_amount * 2400.0when 'BNB' then t.token_bought_amount * 700.0when 'STABLE' then t.token_bought_amount * 1.0end) as usd_value,qb.t is not null as bought_is_quote,qs.t is not null as sold_is_quotefrom trades tleft join quote_tokens qb on qb.t = t.token_bought_addressleft join quote_tokens qs on qs.t = t.token_sold_address),legs as (select blockchain, token_bought_address as token, token_bought_symbol as symbol,'buy' as side, usd_value, token_bought_amount as amount, block_timefrom valued where not bought_is_quote