Query editor
with--this is all to get the contract_address and blockchain of the inputted paramsselected_tokens as (SELECTdistinct symbol, 0x2c06ba9e7f0daccbc1f6a33ea67e85bb68fbee3a, blockchain, decimalsFROM (SELECTsymbol, blockchain, max_by(0x2c06ba9e7f0daccbc1f6a33ea67e85bb68fbee3a, transfers) as 0x2c06ba9e7f0daccbc1f6a33ea67e85bb68fbee3a, max_by(decimals, transfers) as decimalsFROM (SELECTupper(tk.symbol) as symbol, tk.0x2c06ba9e7f0daccbc1f6a33ea67e85bb68fbee3a, tk.blockchain, tk.decimals, COALESCE(count(*),0) as transfersFROM tokens.erc20 tkLEFT JOIN evms.erc20_transfers tr ON tk.blockchain = tr.blockchainAND tk.0x2c06ba9e7f0daccbc1f6a33ea67e85bb68fbee3a = tr.0x2c06ba9e7f0daccbc1f6a33ea67e85bb68fbee3aAND tr.evt_block_time > now() - interval '5' day --should be good enough time filterAND tr.blockchain = '{{3. Blockchain}}'WHERE contains(split(replace('{{1. Token Symbols}}',' ',''),','), upper(tk.symbol))and tk.blockchain = '{{3. Blockchain}}'group by 1,2,3,4) group by 1,2UNION ALLSELECTtk.symbol, '{{3. Blockchain}}' as blockchain, from_hex(trim(c.address)) as 0x2c06ba9e7f0daccbc1f6a33ea67e85bb68fbee3a, COALESCE(tk.decimals, 18) as decimalsFROM unnest(split('{{2. Token Contracts}}',',')) as c(address)LEFT JOIN tokens.erc20 tk ON tk.0x2c06ba9e7f0daccbc1f6a33ea67e85bb68fbee3a = try(from_hex(trim(c.address))) AND tk.blockchain = '{{3. Blockchain}}'WHERE try(from_hex(trim(c.address))) is not nulland lower(c.address) != 'none'and try(from_hex(trim(c.address))) not in (SELECT distinct 0x2c06ba9e7f0daccbc1f6a33ea67e85bb68fbee3a FROM tokens.erc20))), dex_trades as (SELECTd.token_bought_address as token_address,case when token_bought_amount != cast(token_bought_amount as double) then d.amount_usd/d.token_bought_amountelse d.amount_usd/(cast(d.token_bought_amount as double))end as price,'buy' as action,d.token_bought_amount as amount,d.tx_from as trader,d.block_time,d.blockchainFROM dex.trades dWHERE d.amount_usd > 0AND cast(d.token_bought_amount as double) > 0AND blockchain = '{{3. Blockchain}}'AND block_time > now() - interval '{{4. Days}}' day