Query editor
with liquidity_pools (pool, address) as (values('DEBT-WBNB', 0x2B26ed331576d5c7Ad6941A1833720D8E967597e),('DEBT-USDT', 0xbe46815e0f0123ad626b82a0166eaa32274104f5),('BGLD-WBNB', 0x7526cC9121Ba716CeC288AF155D110587e55Df8b)),main_query as (select tx_hash, block_date, tx_from, token_bought_symbol, token_sold_symbol, amount_usd, token_pair, token_bought_amount, token_sold_amount,casewhen token_sold_address = 0xc632f90affec7121120275610bf17df9963f181cor token_sold_address = 0x169f715CaE1F94C203366a6890053E817C767B7Cand token_bought_address = 0x55d398326f99059fF775485246999027B3197955or token_bought_address = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095cthen amount_usdend as token_sold_usd,casewhen token_sold_address = 0x55d398326f99059fF775485246999027B3197955or token_sold_address = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095cand token_bought_address = 0xc632f90affec7121120275610bf17df9963f181cor token_bought_address = 0x169f715CaE1F94C203366a6890053E817C767B7Cthen amount_usdend as token_bought_usdfrom dex.tradeswhere project_contract_address in (select address from liquidity_pools)and block_date <= date '2023-09-30'),attribution_query as (select m.block_date,m.tx_from, m.token_bought_usd, m.token_sold_usd, m.token_bought_amount, m.token_sold_amount, m.token_pairfrom main_query m),wbnb_price_data as (select block_date,block_time,tx_hash,token_pair,case when token_bought_symbol = 'WBNB' then token_sold_symbolwhen token_sold_symbol = 'WBNB' then token_bought_symbolelse null end AS counterparty,case when token_bought_symbol = 'WBNB' then 'SELL'when token_sold_symbol = 'WBNB' then 'BUY'else null end as direction,case when token_bought_symbol = 'WBNB' then amount_usd / token_sold_amountwhen token_sold_symbol = 'WBNB' then amount_usd / token_bought_amountelse null end as token_pricefrom dex.tradeswhere project_contract_address in (0x7526cC9121Ba716CeC288AF155D110587e55Df8b -- BGLD-WBNB)),wbnb_final_query as (select block_date,token_pair,counterparty as token,avg(token_price) as bgld_price_usd,'wbnb liquidity pools' as sourcefrom wbnb_price_datawhere block_date != date '2022-12-12'group by block_date, token_pair, counterparty),bgld_join_query as (