Query editor
-- Unified trades CTE. ENRICH this so it shows both the sender and the receiverWITH unified_trades AS (SELECTDATE_TRUNC('day', block_time) AS "Timestamp",--block_time AS "Timestamp", -- for granular trade-by-trade datatx_hash AS "Transaction hash",token_bought_symbol AS "Symbol",token_bought_address AS "Address",CASEWHEN project = '1inch LOP' OR t.taker IN ({{MM wallets comma-separated}}) OR t.tx_from IN ({{MM wallets comma-separated}}) THEN 'Buy'WHEN t.maker IN ({{MM wallets comma-separated}}) THEN 'Sell'ELSE 'Buy'END AS "Side",CASEWHEN token_bought_amount = 0 THEN NULLELSE amount_usd / token_bought_amountEND AS "Price",amount_usd AS "Amount",token_bought_amount AS "Quantity",(Project || ' v' || Version) AS "DEX",taker AS "Wallet"FROM dex.trades AS tWHEREt.taker IN ({{MM wallets comma-separated}}) OR t.maker IN ({{MM wallets comma-separated}}) OR t.tx_from IN ({{MM wallets comma-separated}})--AND token_bought_symbol = '{{Token symbol}}'UNION ALLSELECTDATE_TRUNC('day', block_time) AS "Timestamp",--block_time AS "Timestamp",tx_hash AS "Transaction hash",token_sold_symbol AS "Symbol",token_sold_address AS "Address",CASEWHEN project = '1inch LOP' OR t.taker IN ({{MM wallets comma-separated}}) OR t.tx_from IN ({{MM wallets comma-separated}}) THEN 'Sell'WHEN t.maker IN ({{MM wallets comma-separated}}) THEN 'Buy'ELSE 'Sell'END AS "Side",CASEWHEN token_sold_amount = 0 THEN NULLELSE amount_usd / token_sold_amountEND AS "Price",amount_usd AS "Amount", -- Keeping amount positive for 'Sell'token_sold_amount AS "Quantity",(Project || ' v' || Version) AS "DEX",taker AS "Wallet"FROM dex.trades AS tWHEREt.taker IN ({{MM wallets comma-separated}}) OR t.maker IN ({{MM wallets comma-separated}}) OR t.tx_from IN ({{MM wallets comma-separated}})--AND token_sold_symbol = '{{Token symbol}}'),-- Filtered transfers CTEfiltered_transfers AS (SELECTDATE_TRUNC('day', evt_block_time) AS "Timestamp",evt_tx_hash AS "Transaction hash",erc20.symbol AS "Symbol",erc20.contract_address AS "Address",CASEWHEN "to" IN ({{MM wallets comma-separated}}) AND "from" NOT IN ({{MM wallets comma-separated}}) THEN 'Inbound transfer'WHEN "from" IN ({{MM wallets comma-separated}}) AND "to" NOT IN ({{MM wallets comma-separated}}) THEN 'Outbound transfer'