Query editor
WITH paid_claims AS (SELECTcall_tx_hash AS tx_hash,_currency AS currency_address,SUM(_pricePerToken * _quantity) AS quoted_rawFROM moodymadness_abstract.moodymadnessassets_call_claimWHERE contract_address = 0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644AND call_successAND _pricePerToken > UINT256 '0'AND call_block_date >= DATE '2025-01-01'GROUP BY 1, 2),contract_flows AS (SELECTtx_hash,contract_address AS payment_token_address,MAX(token_standard) AS token_standard,SUM(amount_raw) FILTER (WHERE "to" = 0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644) AS incoming_raw,SUM(amount_raw) FILTER (WHERE "from" = 0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644) AS outgoing_raw,SUM(amount_usd) FILTER (WHERE "to" = 0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644) AS incoming_usd,SUM(amount_usd) FILTER (WHERE "from" = 0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644) AS outgoing_usdFROM tokens.transfersWHERE blockchain = 'abstract'AND block_date >= DATE '2025-01-01'AND ("to" = 0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644OR "from" = 0x35ffe9d966e35bd1b0e79f0d91e438701ea1c644)GROUP BY 1, 2),reconciled AS (SELECTCOALESCE(p.tx_hash, f.tx_hash) AS tx_hash,p.quoted_raw,f.incoming_raw,f.outgoing_raw,f.incoming_usd,f.outgoing_usd,CASEWHEN p.tx_hash IS NULL THEN 'NON_CLAIM_CONTRACT_FLOW'WHEN f.tx_hash IS NULL THEN 'MISSING_CASH_FLOW'WHEN f.incoming_raw = p.quoted_raw AND f.outgoing_raw = p.quoted_raw THEN 'EXACTLY_RECONCILED'ELSE 'VALUE_MISMATCH'END AS cash_flow_statusFROM paid_claims pFULL OUTER JOIN contract_flows fON f.tx_hash = p.tx_hashAND ((p.currency_address = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee AND f.token_standard = 'native')OR p.currency_address = f.payment_token_address))SELECTCOUNT_IF(quoted_raw IS NOT NULL) AS paid_claim_transactions,COUNT_IF(cash_flow_status = 'EXACTLY_RECONCILED') AS exactly_reconciled_transactions,COUNT_IF(cash_flow_status = 'MISSING_CASH_FLOW') AS missing_cash_flow_transactions,COUNT_IF(cash_flow_status = 'VALUE_MISMATCH') AS value_mismatch_transactions,COUNT_IF(cash_flow_status = 'NON_CLAIM_CONTRACT_FLOW') AS non_claim_contract_flow_transactions,ROUND(COALESCE(SUM(incoming_usd) FILTER (WHERE cash_flow_status = 'NON_CLAIM_CONTRACT_FLOW'), 0), 2) AS non_claim_incoming_usd,ROUND(COALESCE(SUM(outgoing_usd) FILTER (WHERE cash_flow_status = 'NON_CLAIM_CONTRACT_FLOW'), 0), 2) AS non_claim_outgoing_usd,CASEWHEN COUNT_IF(cash_flow_status IN ('MISSING_CASH_FLOW', 'VALUE_MISMATCH', 'NON_CLAIM_CONTRACT_FLOW')) = 0THEN 'PASS'ELSE 'REVIEW'