Query editor
WITHGMX_PRICES as(SELECTAVG(price) as gmx_priceFROM prices.usdWHERE symbol = 'GMX' and minute >= date_add('hour', -12, NOW())),Pirex_Flow as (SELECTdate_trunc('{{Time Scale:}}', block_time) as time_scale,SUM(bytearray_to_decimal(bytearray_ltrim(bytearray_substring(data, 1 + 32*0, 32)))) / 1e18 as depositFROM arbitrum.logsWHEREcontract_address = 0xb0e54cde03e37414672d69687b212388566ba856AND topic0 = 0x87c12eaacc81a498a056cd366c1172ded5d876d6f2d1c711d719d15c9e1659a4GROUP BY 1),GMX_Flow as (SELECT pf.*,pf.deposit * gp.gmx_price as deposit_usdFROM Pirex_Flow pfJOIN GMX_PRICES gp ON 1=1ORDER BY 1)SELECT *FROM(SELECTtime_scale,SUM(deposit) as deposit,SUM(deposit_usd) as deposit_usd,SUM(deposit_usd) / SUM(deposit) as price,SUM(SUM(deposit)) OVER (ORDER BY time_scale) as deposit_t,SUM(SUM(deposit_usd)) OVER (ORDER BY time_scale) as deposit_usd_tFROM GMX_FlowGROUP BY 1)WHERE time_scale >= date_add(split('{{Period:}}', ' ')[2], -cast(split('{{Period:}}', ' ')[1] as int), NOW())