Query editor
-- look up gmx price-- the resulting table does not include prices for the early dayswith gmx_prices as (select minute, price from prices.usdwhere blockchain = 'arbitrum' and symbol = 'GMX'order by minute),-- so we'll need to calculate early days' gmx prices by going through the swaps on uniswapgmx_eth_contracts(contract_address, fee_tier) as (values(0x80a9ae39310abf666a87c743d6ebbd0e8c42158e, '100bp'),(0x1aeedd3727a6431b8f070c0afaa81cc74f273882, '30bp'),(0xb435ebfe0bf4ce66810aa4d44e3a5ca875d40db1, '5bp')),gmx_usdc_contracts(contract_address, fee_tier) as (values(0x2039f8c9cd32ba9cd2ea7e575d5b1abea93f7527, '100bp'),(0xbed2589fefae17d62a8a4fdac92fa5895cae90d2, '30bp'),(0xea263b98314369f2245c7b7e6a9f72e25cb8cded, '5bp')),-- calculate GMX price in ETH via swaps in the GMX-ETH pools on uniswapgmx_prices_in_eth as (select evt_block_time as minute,abs(amount0) / 1e18 as eth_qty,abs(amount1) / 1e18 as gmx_qty,cast(abs(amount0) as double) / cast(abs(amount1) as double) as gmx_ethfrom uniswap_v3_arbitrum.Pair_evt_Swapwhere contract_address in (select contract_address from gmx_eth_contracts)and evt_block_time < (select minute from gmx_prices limit 1)),-- get minute level eth prices, sometimes price doesn't exist for some minutes, but mostly ok.eth_prices as (select minute, price as eth_usdfrom prices.usdwhere symbol = 'WETH'and minute >= cast('2021-08-31 00:00' as timestamp) -- platform inceptionand minute < (select minute from gmx_prices limit 1)),-- derive GMX prices in USD at minute levelgmx_prices_01 as (select gmx_prices_in_eth.minute, gmx_eth * eth_usd as gmx_usdfrom gmx_prices_in_ethjoin eth_prices on gmx_prices_in_eth.minute = eth_prices.minute),-- calculate GMX price in USDC via swaps in the GMX-USDC pools on uniswapgmx_prices_in_usdc as (select evt_block_time as minute,abs(amount1) / 1e6 as usdc_qty,abs(amount0) / 1e18 as gmx_qty,(abs(amount1) / 1e6) / (abs(amount0) / 1e18) as gmx_usdfrom uniswap_v3_arbitrum.Pair_evt_Swapwhere contract_address in (select contract_address from gmx_usdc_contracts)and evt_block_time < (select minute from gmx_prices limit 1)),-- stack price tablesgmx_minute_prices as (select *from (select minute, gmx_usd as price from gmx_prices_01union