Query editor
WITH config AS (SELECT * FROM "query_8094634"), committed AS (SELECTe.committer AS participant,CAST(SUM(e.normalizedAmount) AS DECIMAL(38, 0)) AS committed_usd_6FROM plasma_ethereum.plasmasale_evt_committed eCROSS JOIN config cWHERE e.evt_block_date BETWEEN c.sale_start_date AND c.sale_end_dateAND e.contract_address = c.ethereum_sale_contractGROUP BY 1), settled AS (SELECTe.committer AS participant,CAST(SUM(e.refunded) AS DECIMAL(38, 0)) AS refunded_usd_6FROM plasma_ethereum.plasmasale_evt_settled eCROSS JOIN config cWHERE e.evt_block_date BETWEEN c.sale_end_date AND date_add('day', 2, c.sale_end_date)AND e.contract_address = c.ethereum_sale_contractGROUP BY 1), allocations AS (SELECTc.participant,c.committed_usd_6 - COALESCE(s.refunded_usd_6, DECIMAL '0') AS funded_usd_6,(c.committed_usd_6 - COALESCE(s.refunded_usd_6, DECIMAL '0')) * DECIMAL '20000000000000' AS allocation_xpl_weiFROM committed cLEFT JOIN settled s ON s.participant = c.participantWHERE c.committed_usd_6 > COALESCE(s.refunded_usd_6, DECIMAL '0')), tge_matches AS (SELECTa.participant,COUNT(*) AS matching_trace_count,MIN(t.block_number) AS distribution_block,MIN(t.block_time) AS distribution_time,arbitrary(t.tx_hash) AS distribution_tx_hashFROM allocations aCROSS JOIN config cJOIN plasma.traces tON t."to" = a.participantAND t."from" = c.plasma_tge_distributorAND CAST(t.value AS DECIMAL(38, 0)) = a.allocation_xpl_weiWHERE t.block_date = c.mainnet_beta_dateAND t.successAND t.tx_successAND t.call_type = 'call'GROUP BY 1)SELECTa.participant,CASEWHEN COALESCE(m.matching_trace_count, 0) = 1 THEN 'non-US'WHEN COALESCE(m.matching_trace_count, 0) = 0 THEN 'US'ELSE 'review'END AS inferred_category,CAST(a.funded_usd_6 AS DOUBLE) / 1e6 AS sale_funded_usd,CAST(a.allocation_xpl_wei AS DOUBLE) / 1e18 AS allocation_xpl,(CAST(a.allocation_xpl_wei AS DOUBLE) / 1e18) / c.public_sale_xpl AS public_sale_share,(CAST(a.allocation_xpl_wei AS DOUBLE) / 1e18) / c.initial_supply_xpl AS initial_supply_share,CASEWHEN COALESCE(m.matching_trace_count, 0) = 1 THEN c.mainnet_beta_date