Query editor
with REQPAYMENTS as (select'ETH' as Currency, DATE_TRUNC('{{aggregation period}}', ETHtx."block_time") as Time, (ETHtx."value" / CAST(POWER(10, tok1.decimals) as DOUBLE)) as Amount, ((ETHtx."value" * usd1."price") / CAST(POWER(10, tok1."decimals") as DOUBLE)) as Amount_USDfrom ethereum.transactions as ETHtxleft join tokens.erc20 as tok1 on tok1."symbol" = 'WETH'left join prices.usd as usd1 on usd1."contract_address" = tok1."contract_address"and usd1."minute" = DATE_TRUNC('minute', ETHtx."block_time")where usd1.blockchain = 'ethereum'and tok1.blockchain = 'ethereum'and ETHtx."block_time" > CURRENT_TIMESTAMP - INTERVAL '{{x}}' {{last x}}and "to" in (0x37A8f5F64f2a84f2377481537F04D2A59C9f59B6 /* EthereumProxy v1 */, 0x322F0037d272E980984F89E94Aae43BD0FC065E6 /* EthereumProxy v3 */, 0xCa3353a15fCb5C83a1Ff64BFf055781aC5c4d2F4 /* EthConversionProxy v1 */, 0x7Ebf48a26253810629C191b56C3212Fd0D211c26 /* EthConversionProxy v2 */)unionselecttok2."symbol" as Currency, DATE_TRUNC('{{aggregation period}}', ERC20."evt_block_time") as Time, (ERC20."value" / CAST(POWER(10, tok2.decimals) as DOUBLE)) as Amount, casewhen not usd2.SYMBOL is nullthen ((ERC20."value" * usd2."price") / CAST(POWER(10, tok2."decimals") as DOUBLE))else((ERC20."value" * usd_dex."median_price") / CAST(POWER(10, tok2."decimals") as DOUBLE))end as Amount_USDfrom ethereum."logs" as ETHtx2left join erc20_ethereum.evt_Transfer as erc20 on ETHtx2."tx_hash" = ERC20."evt_tx_hash"and ERC20."to" <> 0x35d0e078755cd84d3e0656caab417dee1d7939c7left join tokens.erc20 as tok2 on tok2."contract_address" = ERC20."contract_address"left join prices.usd as usd2 on usd2."contract_address" = ERC20."contract_address"and usd2."minute" = DATE_TRUNC('minute', ERC20."evt_block_time")left join dex.prices as usd_dex on usd_dex."contract_address" = ERC20."contract_address"and usd_dex."hour" = DATE_TRUNC('hour', ERC20."evt_block_time") /* here needs the contract address to be specified along with its payment function in topic1 (TransferWithReferenceAndFee, TransferWithConversionAndReference, TransferWithReference). This can be found in the eventlog of a transaction on Etherscan for example */where usd2.blockchain = 'ethereum'and tok2.blockchain = 'ethereum'and ETHtx2."block_time" > CURRENT_TIMESTAMP - INTERVAL '{{x}}' {{last x}}and ((ETHtx2."contract_address" = 0x370DE27fdb7D1Ff1e1BaA7D11c5820a324Cf623Cand "topic0" = 0x9f16cbcc523c67a60c450e5ffe4f3b7b6dbe772e7abcadb2686ce029a9a0a2b6)or (ETHtx2."contract_address" = 0xe72Ecea44b6d8B2b3cf5171214D9730E86213cA2and "topic0" = 0x96d0d1d75923f40b50f6fe74613b2c23239149607848fbca3941fee7ac041cdc)or (ETHtx2."contract_address" = 0x5f821c20947ff9be22e823edc5b3c709b33121b3and "topic0" = 0x4d4e9dbb7207a31cc25529ccb52e52ddba30ded7734e32691d13da66df7f81da)or (ETHtx2."contract_address" = 0x8433Ed02A32154Aa0edbae12b1C8816205d6D02cand "topic0" = 0x9f16cbcc523c67a60c450e5ffe4f3b7b6dbe772e7abcadb2686ce029a9a0a2b6)or (ETHtx2."contract_address" = 0x3b4837C9F4A606b71e61FD56Db6241781194df92and "topic0" = 0x96d0d1d75923f40b50f6fe74613b2c23239149607848fbca3941fee7ac041cdc)))selectR1.currency, R1.time