Query editor
/*──────────────────────────────────────────────────────────────Dogstar Dogwallets - Previous Week Total Volume (sin efectos)▸ Calculates the total WTV in USD generated during the PREVIOUS complete weekby ALL Dogwallets (funded by 'GDYA...VC3R').▸ Volume INCLUDES ops (payments, LPs) and trades initiated by the accounts.▸ Volume EXCLUDES passive effects like receiving credits.──────────────────────────────────────────────────────────────*/WITHparams AS (SELECTdate_trunc('week', date_add('week', -12, current_date)) AS pricing_window_start,date_trunc('week', current_date) AS pricing_window_end,date_trunc('week', date_add('week', -1, current_date)) AS prev_week_start,date_trunc('week', current_date) AS prev_week_end,'GDYAPTNACFQVAPUCD6LIV3RK75ERETZAID6KAN6K6NCPLEOBUCWPVC3R' AS dogwallet_funder,'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN' AS usdc_issuer),accounts_dogwallets AS (SELECT DISTINCT h.accountFROM stellar.history_operations hJOIN params p ON TRUEWHERE h.type_string = 'create_account' AND h.funder = p.dogwallet_funder),is_allowed_asset AS (SELECT asset_code, asset_issuer FROM query_5034222),ops AS (SELECT 'ops' AS source_cte, date_trunc('day', o.closed_at) AS event_day, CASE WHEN o.asset_type='native' THEN 'XLM' ELSE o.asset_code END AS asset_code, CASE WHEN o.asset_type='native' THEN NULL ELSE o.asset_issuer END AS asset_issuer, CAST(o.amount AS DOUBLE) AS amountFROM stellar.history_operations o JOIN accounts_dogwallets adw ON o.source_account = adw.account JOIN params p ON TRUE JOIN is_allowed_asset allowed ON (CASE WHEN o.asset_type='native' THEN 'XLM' ELSE o.asset_code END) = allowed.asset_code AND (CASE WHEN o.asset_type='native' THEN TRUE ELSE o.asset_issuer = allowed.asset_issuer END)WHERE o.type_string IN ('payment', 'path_payment_strict_send', 'path_payment_strict_receive', 'liquidity_pool_deposit', 'liquidity_pool_withdraw')AND o.closed_at >= p.prev_week_start AND o.closed_at < p.prev_week_end),trades AS (SELECT 'trades' AS source_cte, date_trunc('day', ht.closed_at) AS event_day, CASE WHEN ht.selling_asset_type='native' THEN 'XLM' ELSE ht.selling_asset_code END AS asset_code, CASE WHEN ht.selling_asset_type='native' THEN NULL ELSE ht.selling_asset_issuer END AS asset_issuer, CAST(ht.selling_amount AS DOUBLE) AS amountFROM stellar.history_trades ht JOIN accounts_dogwallets adw ON ht.selling_account_address = adw.account OR ht.buying_account_address = adw.account JOIN params p ON TRUE JOIN is_allowed_asset allowed_selling ON (CASE WHEN ht.selling_asset_type='native' THEN 'XLM' ELSE ht.selling_asset_code END) = allowed_selling.asset_code AND (CASE WHEN ht.selling_asset_type='native' THEN TRUE ELSE ht.selling_asset_issuer = allowed_selling.asset_issuer END) JOIN is_allowed_asset allowed_buying ON (CASE WHEN ht.buying_asset_type='native' THEN 'XLM' ELSE ht.buying_asset_code END) = allowed_buying.asset_code AND (CASE WHEN ht.buying_asset_type='native' THEN TRUE ELSE ht.buying_asset_issuer = allowed_buying.asset_issuer END)WHERE ht.selling_liquidity_pool_id IS NULLAND ht.closed_at >= p.prev_week_start AND ht.closed_at < p.prev_week_end),-- La CTE 'credits' ha sido eliminada por completo.events AS (SELECT source_cte, event_day, asset_code, asset_issuer, amount FROM opsUNION ALLSELECT source_cte, event_day, asset_code, asset_issuer, amount FROM trades-- La línea que unía 'credits' ha sido eliminada.),daily_xlm_avg_price AS (SELECT date_trunc('day', ht.closed_at) AS day, AVG(CASE WHEN ht.buying_asset_code = 'USDC' AND ht.selling_asset_type = 'native' THEN ht.buying_amount / ht.selling_amount WHEN ht.selling_asset_code = 'USDC' AND ht.buying_asset_type = 'native' THEN ht.selling_amount / ht.buying_amount ELSE NULL END) AS avg_xlm_usdc_priceFROM stellar.history_trades ht JOIN params p ON TRUEWHERE ht.closed_at >= p.pricing_window_start AND ht.closed_at < p.pricing_window_endAND ( (ht.buying_asset_code = 'USDC' AND ht.buying_asset_issuer = p.usdc_issuer AND ht.selling_asset_type = 'native') OR (ht.selling_asset_code = 'USDC' AND ht.selling_asset_issuer = p.usdc_issuer AND ht.buying_asset_type = 'native') )AND ht.buying_amount > 0 AND ht.selling_amount > 0GROUP BY 1),