Query editor
/*──────────────────────────────────────────────────────────────Dogwallets - Volume Semanal - SEMANA 1 (26-May a 01-Jun) [VERSIÓN FINAL CORREGIDA]Estructura de CTEs limpiada para resolver el error 'cannot be resolved'.──────────────────────────────────────────────────────────────*/WITH/* 1. Parameters */params AS (SELECT'GDYAPTNACFQVAPUCD6LIV3RK75ERETZAID6KAN6K6NCPLEOBUCWPVC3R' AS dogwallet_funder,DATE '2025-05-26' AS date_start,DATE '2025-06-01' AS date_end,DATE '2025-05-26' - interval '7' day AS pricing_window_start,DATE '2025-06-01' + interval '1' day AS pricing_window_end,'USDC' AS quote_code,'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN' AS usdc_issuer),/* 1.5. Successful Transactions IDs */successful_transaction_ids AS (SELECT DISTINCT idFROM stellar.history_transactionsWHERE successful = trueAND closed_at >= (SELECT date_start FROM params) - interval '2' dayAND closed_at <= (SELECT date_end FROM params) + interval '2' day),/* 2. All Dogwallets */accounts_dogwallets AS (SELECT DISTINCT h.accountFROM stellar.history_operations hWHERE h.type_string = 'create_account' AND h.funder = (SELECT dogwallet_funder FROM params)),/* 3. Allowed assets list */allowed_assets AS (SELECT asset_code, asset_issuer FROM query_5034222UNION ALLSELECT 'XLM', NULL),/* 4. RESTRUCTURED: Gather events in separate, clear CTEs */ops_simple AS (SELECT o.source_account AS account, CAST(o.amount AS DOUBLE) AS amount,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_issuerFROM stellar.history_operations o JOIN successful_transaction_ids st ON o.transaction_id = st.idWHERE o.source_account IN (SELECT account FROM accounts_dogwallets)AND o.type_string IN ('payment', 'path_payment_strict_send', 'path_payment_strict_receive')AND o.closed_at >= (SELECT date_start FROM params) AND o.closed_at < date_add('day', 1, (SELECT date_end FROM params))),ops_lp AS (SELECT o.source_account AS account, CAST(COALESCE(o.reserve_a_deposit_amount, 0) - COALESCE(o.reserve_a_withdraw_amount, 0) AS DOUBLE) AS amount,CASE WHEN o.reserve_a_asset_type = 'native' THEN 'XLM' ELSE o.reserve_a_asset_code END AS asset_code,CASE WHEN o.reserve_a_asset_type = 'native' THEN NULL ELSE o.reserve_a_asset_issuer END AS asset_issuerFROM stellar.history_operations o JOIN successful_transaction_ids st ON o.transaction_id = st.idWHERE o.source_account IN (SELECT account FROM accounts_dogwallets)AND o.type_string IN ('liquidity_pool_deposit','liquidity_pool_withdraw')AND o.closed_at >= (SELECT date_start FROM params) AND o.closed_at < date_add('day', 1, (SELECT date_end FROM params))UNION ALLSELECT o.source_account AS account, CAST(COALESCE(o.reserve_b_deposit_amount, 0) - COALESCE(o.reserve_b_withdraw_amount, 0) AS DOUBLE) AS amount,