Query editor
-- with gmx_txs as (-- SELECT block_time as time, data, tx_hash, topic2, topic3-- FROM arbitrum.logs as a_l-- -- GMX contract-- WHERE contract_address = LOWER('0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a') and-- -- TRANSFER-- `topic1` = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' AND-- -- REMOVING EDGE CASE-- CONCAT('0x',substring(topic2 FROM 27 FOR 40)) not in ('0xbbd51d8fc750de753e183bdbf019adad39c189cc',-- '0x41e6cc2d2f2331ea5fb6b4c289f7d4b4972014d5')-- ),-- lp_txs as (-- SELECT distinct tx_hash-- FROM arbitrum.logs-- WHERE contract_address IN (LOWER('0x80a9ae39310abf666a87c743d6ebbd0e8c42158e'), LOWER('0x1aeedd3727a6431b8f070c0afaa81cc74f273882')) and-- `topic1` = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67'-- ),-- weth_txs as (-- SELECT block_time as time, data, tx_hash, topic2, topic3-- FROM arbitrum.logs as a_l-- WHERE contract_address = '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' AND-- -- TRANSFER-- `topic1` = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'-- ),-- weth_price as (-- SELECT date_trunc('day', minute) as time, avg(price) as avg_price-- FROM prices.usd-- WHERE symbol IN ('WETH')-- GROUP BY 1-- ORDER BY 1 DESC-- )with lp_txs as (select date_trunc('day', evt_block_time) as time,abs(amount0)/1e18 as eth_amount,abs(amount1)/1e18 as hmx_amount,abs(amount0/1e18)/abs(amount1/1e18) as eth_hmx_amount,evt_tx_hashfrom uniswap_v3_arbitrum.Pair_evt_Swapwhere contract_address in (0x83d6c8c06ac276465e4c92e7ac8c23740f435140,0x05bbaaa020ff6bea107a9a1e06d2feb7bfd79ed2)),weth_price as (SELECT date_trunc('day', minute) as time, avg(price) as avg_priceFROM prices.usdWHERE symbol IN ('WETH') and minute >= date'2023-08-3'GROUP BY 1ORDER BY 1 DESC)-- ,-- gmx_price as (-- select lp_txs.time, AVG(eth_gmx_amount * weth_price.avg_price) as avg_price, SUM(eth_gmx_amount * weth_price.avg_price) as eth_volume-- from lp_txs join weth_price on lp_txs.time = weth_price.time-- GROUP BY 1-- ORDER BY 1 DESC-- )SELECT time, SUM(eth_volume) as usd_volume, AVG(hmx_price) as hmx_price,IF(avg(hmx_price) - lag(avg(hmx_price)) OVER (order by time) > 0, SUM(eth_volume), NULL) as green_volume,IF(avg(hmx_price) - lag(avg(hmx_price)) OVER (order by time) < 0, SUM(eth_volume), NULL) as red_volume