Query editor
-- VRF Protocol Profitability-- Dune: query_6689628-- Depends on: shared/request_gas_refunded.sql (query_6689874)-- shared/fulfillment_gas_refunded.sql (query_6689874)-- shared/daily_oracle_gas.sql (query_6689991)-- Tables: paintswap_sonic.paintswapvrfcoordinator_evt_randomwordsrequested---- Money flow:-- 1. User pays msg.value = required + optional excess-- required = (callbackGasLimit + 300,000) × gasPricePaid-- 2. Excess overpayment: 90% refunded to user, protocol keeps 10%-- 3. Fulfillment: 90% of unused callback gas refunded to user, protocol keeps 10%-- 4. Oracle pays real Sonic gas for fulfillment tx (from sonic.transactions)-- 5. Sonic FeeM returns 90% of oracle gas to protocol---- Key formulas:-- user_paid = required + (request_refund × 10/9) [excess inferred from refund]-- total_refunded = request_refund + fulfill_refund-- net_user_cost = user_paid - total_refunded-- oracle_gas = actual gas from sonic.transactions (via shared/daily_oracle_gas)-- profit_before_feem = net_user_cost - oracle_gas-- feem_rebate = oracle_gas × 90%-- net_profit = net_user_cost - oracle_gas × 10%---- Visualization 1: Line chart (daily P&L)-- Title: Daily Protocol P&L-- X-axis: day-- Y-axis: net_user_cost_s, oracle_gas_s, profit_before_feem_s, net_profit_s-- Y-axis label: S---- Visualization 2: Area chart (cumulative)-- Title: Cumulative Profitability-- X-axis: day-- Y-axis: cumulative_user_paid_s, cumulative_refunded_s, cumulative_profit_before_feem_s, cumulative_net_profit_s---- Visualization 3: Stacked bar (revenue vs costs)-- Title: Daily Revenue vs Costs-- X-axis: day-- Y-axis: total_refunded_s, oracle_gas_net_s, profit_before_feem_s-- Stack: enabledWITH daily_required AS (SELECTdate_trunc('day', evt_block_time) AS day,COUNT(*) AS requests,CAST(CAST(SUM((callbackGasLimit + 300000) * gasPricePaid) AS DOUBLE) / 1e18 AS DECIMAL(38,6)) AS required_sFROM paintswap_sonic.paintswapvrfcoordinator_evt_randomwordsrequestedGROUP BY 1),daily_request_refunds AS (SELECTdate_trunc('day', evt_block_time) AS day,CAST(CAST(SUM(CASE WHEN refundedSuccessfully THEN gasRefunded END) AS DOUBLE) / 1e18 AS DECIMAL(38,6)) AS request_refunded_sFROM query_6689874 -- shared/request_gas_refunded.sqlGROUP BY 1),daily_fulfill_refunds AS (SELECTdate_trunc('day', evt_block_time) AS day,CAST(CAST(SUM(CASE WHEN refundedSuccessfully THEN gasRefunded END) AS DOUBLE) / 1e18 AS DECIMAL(38,6)) AS fulfill_refunded_s