Query editor
with tokens(contract_address, symbol, decimals, underlying_name) as (values-- Arbitrum Tokens(0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, 'USDC', 6, 'USDC.e'),(0xaf88d065e77c8cc2239327c5edb3a432268e5831, 'USDC', 6, 'USDC'),(0x82af49447d8a07e3bd95bd0d56f35241523fbab1, 'WETH', 18, 'WETH'),(0xda10009cbd5d07dd0cecc66161fc93d7c9000da1, 'DAI', 18, 'DAI'),(0xf97f4df75117a78c1a5a0dbb814af92458539fb4, 'LINK', 18, 'LINK'),(0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, 'USDT', 6, 'USDT'),(0xfa7f8980b0f1e64a2062791cc3b0871572f1f7f0, 'UNI', 18, 'UNI'),(0xfea7a6a0b346362bf88a9e4a88416b77a57d6c2a, 'MIM', 18, 'MIM'),(0x17fc002b466eec40dae837fc4be5c67993ddbd6f, 'FRAX', 18, 'FRAX'),(0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f, 'WBTC', 8, 'WBTC'))SELECT glp_flows.time, glp_flows.symbol,recent_prices.avg_price * SUM(SUM(amount)) OVER(PARTITION BY glp_flows.symbol ORDER BY glp_flows.time) as token_value_cumulative,recent_prices.avg_price * SUM(amount) as total_token_value_amountFROM(SELECT date_trunc('day', evt_block_time) as time,tokens.symbol, underlying_name,SUM(amount/POW(10, tokens.decimals)) as amountFROM gmx_arbitrum.Vault_evt_IncreasePoolAmount as increase_pool jointokens on increase_pool.token = tokens.contract_addressGROUP BY date_trunc('day', evt_block_time), tokens.symbol, underlying_nameUNION ALL-- Decrease Vault PoolsSELECT date_trunc('day', evt_block_time) as time,tokens.symbol, underlying_name,-SUM(amount/POW(10, tokens.decimals)) as amountFROM gmx_arbitrum.Vault_evt_DecreasePoolAmount as decrease_pool jointokens on decrease_pool.token = tokens.contract_addressGROUP BY date_trunc('day', evt_block_time), tokens.symbol, underlying_name) as glp_flows inner join(SELECT date_trunc('day', minute) as time, symbol, avg(price) as avg_priceFROM prices.usdWHERE symbol IN ('WETH', 'WBTC', 'USDC', 'USDT', 'MIM', 'FRAX', 'UNI', 'DAI', 'LINK') andminute >= TIMESTAMP '2021-08-30 00:00'GROUP BY 1, 2ORDER BY 1 DESC) as recent_prices on glp_flows.symbol = recent_prices.symbol and glp_flows.time = recent_prices.timeGROUP BY glp_flows.time, glp_flows.symbol, recent_prices.avg_priceorder by glp_flows.time DESC