Query editor
WITH target_token AS (-- 1. Hardcode the cRECY Celo token addressSELECT 0x34c11a932853ae24e845ad4b633e3cef91afe583 AS contract_address),pool_info AS (-- 2. Find the specific cRECY poolsSELECT id AS pool_idFROM uniswap_v4_celo.PoolManager_evt_InitializeWHERE currency0 = (SELECT contract_address FROM target_token)OR currency1 = (SELECT contract_address FROM target_token)),liquidity_txs AS (-- 3. Isolate the exact transactions where liquidity was added or removed-- We use DISTINCT because one transaction might have multiple ModifyLiquidity eventsSELECT DISTINCTm.evt_tx_hash,m.evt_tx_from AS real_user_addressFROM uniswap_v4_celo.PoolManager_evt_ModifyLiquidity mINNER JOIN pool_info p ON m.id = p.pool_id),pool_transfers AS (-- 4. Calculate the net cRECY tokens that entered the vault during those specific transactionsSELECTevt_tx_hash,SUM(CASE WHEN "to" = 0x288dc841a52fca2707c6947b3a777c5e56cd87bc THEN CAST(value AS DOUBLE) ELSE 0 END)- SUM(CASE WHEN "from" = 0x288dc841a52fca2707c6947b3a777c5e56cd87bc THEN CAST(value AS DOUBLE) ELSE 0 END) AS net_crecy_pool_flowFROM erc20_celo.evt_TransferWHERE contract_address = (SELECT contract_address FROM target_token)-- Only count transfers going into or coming out of the Celo PoolManagerAND ("to" = 0x288dc841a52fca2707c6947b3a777c5e56cd87bc OR "from" = 0x288dc841a52fca2707c6947b3a777c5e56cd87bc)GROUP BY evt_tx_hash),user_provided_liquidity AS (-- 5. Match the token flow to the real user who initiated the transactionSELECTlt.real_user_address,SUM(pt.net_crecy_pool_flow) / POWER(10, 18) AS net_crecy_providedFROM liquidity_txs ltINNER JOIN pool_transfers pt ON lt.evt_tx_hash = pt.evt_tx_hashGROUP BY lt.real_user_address)-- 6. Rank the real token amountsSELECTreal_user_address AS wallet_address,net_crecy_provided AS total_crecy_in_poolFROM user_provided_liquidityWHERE net_crecy_provided > 0ORDER BY net_crecy_provided DESC;