Query editor
WITH registered_pools AS (SELECTDISTINCT poolAddress AS pool_addressFROMbeethoven_X_v2_sonic.Vault_evt_PoolRegisteredUNIONSELECTDISTINCT pool AS pool_addressFROMbeethoven_X_v3_sonic.Vault_evt_PoolRegistered),swap_fees AS(SELECT'sonic' AS blockchain,contract_address,tx_hash,tx_index,index,block_time,block_number,swap_fee_percentage / 1e18 AS swap_fee_percentage,ROW_NUMBER() OVER (PARTITION BY contract_address ORDER BY block_number DESC) AS rnFROM beets.pools_fees)SELECTt.block_time AS "timestamp",146 AS chain_id,t.block_number,t.evt_index AS log_index,t.tx_hash AS transaction_hash,t.tx_from AS user_address,t.tx_to AS taker_address,t.tx_from AS maker_address,t.token_pair AS pair_name,t.project_contract_address AS pool_address,COALESCE(t1.underlying_token, t.token_sold_address) AS input_token_address,COALESCE(t1.underlying_token_symbol, t.token_sold_symbol) AS input_token_symbol,t.token_sold_amount AS input_token_amount,COALESCE(t2.underlying_token, t.token_bought_address) AS output_token_address,COALESCE(t2.underlying_token_symbol, t.token_bought_symbol) AS output_token_symbol,t.token_bought_amount AS output_token_amount,0 AS spot_price_after_swap,COALESCE(t.amount_usd, 0) AS swap_amount_usd,COALESCE(s.swap_fee_percentage * amount_usd, 0) AS fees_usd,0 AS sqrt_price_x96FROM beets.trades tLEFT JOIN swap_fees s ON t.project_contract_address = s.contract_addressLEFT JOIN balancer_v3.erc4626_token_mapping t1 ON t1.erc4626_token = t.token_sold_addressLEFT JOIN balancer_v3.erc4626_token_mapping t2 ON t2.erc4626_token = t.token_bought_addressAND s.rn = 1WHERE t.block_time > TIMESTAMP '{{timestamp}}'