Query editor
WITHREQPAYMENTS AS (SELECTCASEWHEN '{{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" * 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 "to" IN (0x7Ebf48a26253810629C191b56C3212Fd0D211c26 /* EthereumProxy v1 */,0x322F0037d272E980984F89E94Aae43BD0FC065E6 /* EthereumProxy v3 */,0xCa3353a15fCb5C83a1Ff64BFf055781aC5c4d2F4 /* EthConversionProxy v1 */,0x7Ebf48a26253810629C191b56C3212Fd0D211c26 /* EthConversionProxy v2 */)UNIONSELECTCASEWHEN '{{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" * 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 ((MATICtx2."contract_address" = 0x2171a0dc12a9E5b1659feF2BB20E54c84Fa7dB0CAND "topic0" = 0x9f16cbcc523c67a60c450e5ffe4f3b7b6dbe772e7abcadb2686ce029a9a0a2b6)OR (MATICtx2."contract_address" = 0x0DfbEe143b42B41eFC5A6F87bFD1fFC78c2f0aC9AND "topic0" = 0x9f16cbcc523c67a60c450e5ffe4f3b7b6dbe772e7abcadb2686ce029a9a0a2b6)OR (MATICtx2."contract_address" = 0x75740D9b5cA3BCCb356CA7f0D0dB71aBE427a835