Query editor
withposition_open as (selectevt_block_time, poolTokenAmount / 1e18 * varbinary_to_bigint(substr(openData, 3, 2)) as open_volume_busd -- poolTokenAmount * leverage, pool, casewhen pool = 0x8e4b02765435b1cc8eae0334ea9a6b011c7a224b then 'QUINT/USD'when pool = 0x56a51996ccfadad914e5316d10f000f643444bdc then 'BSW/USD'when pool = 0x52c682bb6e5c1a3237dfe4cd58a64c2e3eb4989f then 'ADA/USD'when pool = 0x88e617f53368f011f4f0972f88615d6097bbafd1 then 'KALM/USD'when pool = 0x6ffed1ca0a99cd5c7f1df8425fa7f024be49467f then 'CAKE/USD'end as trading_pair, positionId, 'open' as "type", varbinary_substring(openData, 13, 20) as ownerfrom borabora_v3_bnb.BoraRouter_evt_OpenedPosition), position_close as (selectc.evt_block_time, cast(json_query(closeInfo, 'lax $.closingTradingVolume') as uint256) / 1e18 as close_volume_busd, c.pool, casewhen c.pool = 0x8e4b02765435b1cc8eae0334ea9a6b011c7a224b then 'QUINT/USD'when c.pool = 0x56a51996ccfadad914e5316d10f000f643444bdc then 'BSW/USD'when c.pool = 0x52c682bb6e5c1a3237dfe4cd58a64c2e3eb4989f then 'ADA/USD'when c.pool = 0x88e617f53368f011f4f0972f88615d6097bbafd1 then 'KALM/USD'when c.pool = 0x6ffed1ca0a99cd5c7f1df8425fa7f024be49467f then 'CAKE/USD'end as trading_pair, c.positionId, 'close' as "type", json_query(closeInfo, 'lax $.isProfit') as isProfit, cast(json_query(closeInfo, 'lax $.pnl') as uint256) / 1e18 as pnl, o.ownerfrom borabora_v3_bnb.BoraRouter_evt_ClosedPosition cleft join position_open o on c.pool = o.pool and c.positionId = o.positionId), uni as (select evt_block_time, open_volume_busd as volume, pool, trading_pair, positionId, "type", owner from position_openunion allselect evt_block_time, close_volume_busd as volume, pool, trading_pair, positionId, "type", owner from position_close)selectround(sum(volume), 0) as total_volume,casewhen round(sum(volume) filter (where evt_block_time >= current_timestamp - interval '24' hour), 0) is null then 0else round(sum(volume) filter (where evt_block_time >= current_timestamp - interval '24' hour), 0) end as one_day_volume,round(sum(volume) filter (where evt_block_time >= current_timestamp - interval '7' day), 0) as seven_day_volume,round(sum(volume) filter (where "type" = 'close') * 0.0004, 4) as total_trading_fees,casewhen round(sum(volume) filter (where "type" = 'close' and evt_block_time >= current_timestamp - interval '24' hour) * 0.0004, 4) is null then 0else round(sum(volume) filter (where "type" = 'close' and evt_block_time >= current_timestamp - interval '24' hour) * 0.0004, 4) end as one_day_trading_fees,round(sum(volume) filter (where "type" = 'close' and evt_block_time >= current_timestamp - interval '7' day) * 0.0004, 4) as seven_day_trading_fees,count(distinct owner) as total_unique_users,count(distinct owner) filter(where evt_block_time >= current_timestamp - interval '24' hour) as one_day_unique_users,