Query editor
/* Daily FIFO allocation of the first $20M of qualifying whitelist liquidity.- Deposits are preserved as timestamped lots.- Withdrawals consume the address's oldest deposits first.- The earliest remaining lots across all qualifying entities fill the $20M cap.- A withdrawal on a given day reduces that day's eligible balance.- Later deposits backfill capacity released by withdrawals.*/WITH params AS (SELECTDATE '2026-09-09' AS program_start,90 AS program_days,180000.0 AS total_budget,100000.0 AS min_deposit,20000000.0 AS reward_cap),address_input AS (SELECTposition,from_hex(regexp_replace(lower(trim(address_text)),'^0x','')) AS addressFROM UNNEST(split('{{wallet_addresses}}', ',')) WITH ORDINALITY AS t(address_text, position)),entity_input AS (SELECTposition,trim(entity_text) AS entityFROM UNNEST(split('{{entity_names}}', ',')) WITH ORDINALITY AS t(entity_text, position)),whitelist AS (SELECTe.entity,a.addressFROM address_input aINNER JOIN entity_input eON a.position = e.position),flows AS (/* Supply-side balance only: ciUSDCv3 Transfer events (mint = supply,burn = withdraw of supplied balance, plus wallet-to-wallet moves).Supply/Withdraw events are NOT used because Comet also emits themfor borrow repayments and borrows. */SELECTbytearray_substring(topic2, 13, 20) AS account,CAST(date_trunc('day', block_time) AS date) AS event_day,block_time,