Query editor
WITH pools AS (SELECT DISTINCT poolAddressFROM rain_protocol_arbitrum.raindeployer_evt_poolcreatedUNIONSELECT DISTINCT poolAddressFROM rain_protocol_arbitrum.raindeployerv2_evt_poolcreated --rain v2 factory),tokens AS (SELECT DISTINCTtokenAddress,tokenDecimals,lower(concat('0x', to_hex(tokenAddress))) AS token_hexFROM rain_protocol_arbitrum.raindeployer_evt_pooltokensetWHERE poolAddress IN (SELECT poolAddress FROM pools)),token_list AS (SELECT array_join(array_agg(token_hex), ',') AS token_csvFROM tokens),api_response AS (SELECT json_parse(http_get(concat('https://api.geckoterminal.com/api/v2/simple/networks/arbitrum/token_price/',(SELECT token_csv FROM token_list)))) AS resp),prices AS (SELECTCAST(from_hex(substr(k, 3)) AS varbinary) AS tokenAddress,CAST(v AS DOUBLE) AS priceFROM api_responseCROSS JOIN UNNEST(map_entries(CAST(json_extract(resp, '$.data.attributes.token_prices') AS MAP(VARCHAR, VARCHAR)))) AS t(k, v)),weekly_inflows AS (-- pool inflowsSELECTdate_trunc('week', t.evt_block_time) AS week,(t.value / POWER(10, tk.tokenDecimals)) * COALESCE(pr.price, 0) AS inflow_usdFROM erc20_arbitrum.evt_Transfer tJOIN pools pON t."to" = p.poolAddressJOIN tokens tkON t.contract_address = tk.tokenAddressLEFT JOIN prices prON t.contract_address = pr.tokenAddressWHERE t.evt_block_time >= DATE '2025-01-01'UNION ALL-- reservoir inflowsSELECT