Query editor
WITHREQPAYMENTS AS (SELECT'MATIC' AS Currency,tok1."contract_address",CASEWHEN '{{aggregation period}}' = 'day' THEN DATE_TRUNC('day', MATICtx."block_time")WHEN '{{aggregation period}}' = 'week' THEN DATE_TRUNC('week', MATICtx."block_time")WHEN '{{aggregation period}}' = 'month' THEN DATE_TRUNC('month', MATICtx."block_time")WHEN '{{aggregation period}}' = 'hour' THEN DATE_TRUNC('hour', MATICtx."block_time")END AS time,(MATICtx."value" / CAST(POWER(10, tok1.decimals) AS DOUBLE)) AS Amount,((MATICtx."value" * usd1.price) / CAST(POWER(10, tok1.decimals) AS DOUBLE)) AS Amount_USDFROMpolygon.transactions AS MATICtxLEFT JOIN tokens.erc20 AS tok1 ON tok1."symbol" = 'MATIC'LEFT JOIN prices.usd AS usd1 ON usd1."contract_address" = tok1."contract_address"AND usd1."minute" = DATE_TRUNC('minute', MATICtx."block_time")WHEREusd1.blockchain = 'polygon'AND tok1.blockchain = 'polygon'AND MATICtx."block_time" > CURRENT_TIMESTAMP - INTERVAL '{{x}}' {{last x}}AND MATICtx."to" IN (0x7Ebf48a26253810629C191b56C3212Fd0D211c26 /* EthereumProxy v1 */,0x322F0037d272E980984F89E94Aae43BD0FC065E6 /* EthereumProxy v3 */,0xCa3353a15fCb5C83a1Ff64BFf055781aC5c4d2F4 /* EthConversionProxy v1 */,0x7Ebf48a26253810629C191b56C3212Fd0D211c26 /* EthConversionProxy v2 */)UNIONSELECTtok2."symbol" AS Currency,tok2."contract_address",CASEWHEN '{{aggregation period}}' = 'day' THEN DATE_TRUNC('day', ERC20."evt_block_time")WHEN '{{aggregation period}}' = 'week' THEN DATE_TRUNC('week', ERC20."evt_block_time")WHEN '{{aggregation period}}' = 'month' THEN DATE_TRUNC('month', ERC20."evt_block_time")WHEN '{{aggregation period}}' = 'hour' THEN DATE_TRUNC('hour', ERC20."evt_block_time")END AS time,(ERC20."value" / CAST(POWER(10, tok2.decimals) AS DOUBLE)) AS Amount,((ERC20."value" * usd2.price) / CAST(POWER(10, tok2.decimals) AS DOUBLE)) AS Amount_USDFROMpolygon."logs" AS MATICtx2LEFT JOIN erc20_polygon.evt_Transfer AS erc20 ON MATICtx2."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") /* 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 */WHEREusd2.blockchain = 'polygon'AND tok2.blockchain = 'polygon'AND MATICtx2."block_time" > CURRENT_TIMESTAMP - INTERVAL '{{x}}' {{last x}}AND (