Query editor
WITH bounds AS (SELECT CAST(date_trunc('month',current_date) AS DATE) AS current_month,CAST(date_add('month',-2,date_trunc('month',current_date)) AS DATE) AS start_month,CAST(date_add('month',1,date_trunc('month',current_date)) AS DATE) AS end_month), months AS (SELECT m AS sale_month FROM bounds CROSS JOIN UNNEST(sequence(start_month,current_month,INTERVAL '1' MONTH)) AS u(m)), cash AS (SELECT tr.tx_hash,tr.block_time,tr.block_date,tr."from" AS sender,tr."to" AS recipient,tr.contract_address AS asset,tr.token_standard,tr.amount_raw,CAST(tr.amount AS DECIMAL(38,18)) AS amount,CAST(tr.amount_usd AS DECIMAL(38,12)) AS usdFROM tokens.transfers tr CROSS JOIN bounds bWHERE tr.blockchain='abstract' AND tr.block_month>=b.start_month AND tr.block_month<b.end_monthAND tr.block_date>=b.start_month AND tr.block_date<b.end_monthAND tr.amount_raw>UINT256 '0'AND tr."to" IN (0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644,0x10919961a413610cad2f3d73dc94b3f44146a5f1,0x1bc6507e9cdcb90ad6193f57cc09701722e158a6)AND tr."from" NOT IN (0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644,0x10919961a413610cad2f3d73dc94b3f44146a5f1,0x1bc6507e9cdcb90ad6193f57cc09701722e158a6)AND tr.token_standard IN ('native','erc20')), primary_calls AS (SELECT call_tx_hash AS tx_hash,COUNT(*) AS calls,MAX(_tokenId) AS token_id,SUM(_pricePerToken*_quantity) AS quoted_raw,COUNT_IF(_currency<>0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee) AS other_currencyFROM moodymadness_abstract.moodymadnessassets_call_claim CROSS JOIN bounds bWHERE contract_address=0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644 AND call_successAND call_block_date>=b.start_month AND call_block_date<b.end_month GROUP BY 1), tc_calls AS (SELECT call_tx_hash AS tx_hash,COUNT(*) AS calls,SUM(amount) AS units,MAX(nonce) AS nonce,MAX(tokenContract) AS token_contract,MAX(tokenId) AS token_id,MAX(tokenType) AS token_type,COUNT_IF(tokenContract=0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644 AND tokenId=200 AND tokenType=3) AS bd_calls,COUNT_IF(tokenContract=0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644 AND tokenId=200 AND tokenType=3AND amount IN (UINT256 '75000',UINT256 '180000',UINT256 '412500',UINT256 '975000')) AS pack_callsFROM moodydrops_abstract.tokenclaim_call_claimtoken CROSS JOIN bounds bWHERE contract_address=0x10919961a413610cad2f3d73dc94b3f44146a5f1 AND call_successAND call_block_date>=b.start_month AND call_block_date<b.end_month GROUP BY 1), tc_events AS (SELECT evt_tx_hash AS tx_hash,COUNT(*) AS events,SUM(amount) AS units,MAX(nonce) AS nonce,MAX(tokenContract) AS token_contract,MAX(tokenId) AS token_id,MAX(tokenType) AS token_typeFROM moodydrops_abstract.tokenclaim_evt_tokenclaimed CROSS JOIN bounds bWHERE contract_address=0x10919961a413610cad2f3d73dc94b3f44146a5f1AND evt_block_date>=b.start_month AND evt_block_date<b.end_month GROUP BY 1), native_payments AS (SELECT tx_hash,recipient,MIN(block_time) AS block_time,SUM(amount_raw) AS raw_amount,SUM(amount) AS amount,SUM(usd) AS usd,COUNT_IF(usd IS NULL) AS missing_pricesFROM cash WHERE token_standard='native' GROUP BY 1,2), royalty_events AS (SELECT e.evt_tx_hash AS tx_hash,CASE WHEN json_extract_scalar(c,'$.itemType')='0' THEN 0x000000000000000000000000000000000000800aELSE from_hex(substr(json_extract_scalar(c,'$.token'),3)) END AS asset,SUM(CAST(json_extract_scalar(c,'$.amount') AS UINT256)) AS raw_amountFROM opensea_abstract.seaport_evt_orderfulfilled eCROSS JOIN bounds b CROSS JOIN UNNEST(e.consideration) AS u(c)WHERE e.contract_address=0x0000000000000068f116a894984e2db1123eb395AND e.evt_block_date>=b.start_month AND e.evt_block_date<b.end_monthAND json_extract_scalar(c,'$.recipient')='0x1bc6507e9cdcb90ad6193f57cc09701722e158a6'AND json_extract_scalar(c,'$.itemType') IN ('0','1')AND e.offerer<>0x1bc6507e9cdcb90ad6193f57cc09701722e158a6GROUP BY 1,2), recipient_payments AS (SELECT tx_hash,asset,MIN(block_time) AS block_time,SUM(amount_raw) AS raw_amount,SUM(amount) AS amount,SUM(usd) AS usd,COUNT_IF(usd IS NULL) AS missing_pricesFROM cash WHERE recipient=0x1bc6507e9cdcb90ad6193f57cc09701722e158a6