diff --git a/dbt_subprojects/solana/models/_sector/dex/pumpswap/pumpswap_solana_base_trades_backfill.sql b/dbt_subprojects/solana/models/_sector/dex/pumpswap/pumpswap_solana_base_trades_backfill.sql index 4f3e8f71af5..77d4e1fe907 100644 --- a/dbt_subprojects/solana/models/_sector/dex/pumpswap/pumpswap_solana_base_trades_backfill.sql +++ b/dbt_subprojects/solana/models/_sector/dex/pumpswap/pumpswap_solana_base_trades_backfill.sql @@ -1,3 +1,4 @@ +{# TEMP CI scope: revert begin to protocol_begin before merge. #} {{ config( schema = 'pumpswap_solana' @@ -8,7 +9,7 @@ , file_format = 'delta' , incremental_strategy = 'microbatch' , event_time = 'block_time' - , begin = '2025-02-20' + , begin = '2026-06-01' , batch_size = var('pumpswap_batch_size', 'day') , lookback = 1 , unique_key = ['block_month', 'surrogate_key'] @@ -25,6 +26,16 @@ WITH pools AS ( FROM {{ ref('pumpswap_solana_pools') }} ) +, pool_accounts AS ( + SELECT + account_pool AS pool + , arbitrary(account_pool_base_token_account) AS pool_base_token_account + , arbitrary(account_pool_quote_token_account) AS pool_quote_token_account + FROM {{ source('pumpdotfun_solana', 'pump_amm_call_create_pool') }} + WHERE call_block_time >= TIMESTAMP '2025-02-20' + GROUP BY 1 +) + , swaps AS ( SELECT block_slot @@ -122,7 +133,7 @@ WITH pools AS ( ) ) -, trades AS ( +, decoded_trades AS ( SELECT sp.block_time , sp.block_slot @@ -151,6 +162,58 @@ WITH pools AS ( AND COALESCE(p.is_valid_pool, false) ) +, buy_exact_quote_in_trades AS ( + SELECT + e.evt_block_time AS block_time + , e.evt_block_slot AS block_slot + , CAST(date_trunc('month', e.evt_block_date) AS DATE) AS block_month + , {{ solana_instruction_key( + 'e.evt_block_slot' + , 'e.evt_tx_index' + , 'e.evt_outer_instruction_index' + , 'COALESCE(e.evt_inner_instruction_index, 0)' + ) }} AS surrogate_key + , CASE + WHEN e.evt_outer_executing_account = 'pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA' THEN 'direct' + ELSE e.evt_outer_executing_account + END AS trade_source + , p.baseMint AS token_bought_mint_address + , e.base_amount_out AS token_bought_amount_raw + , p.quoteMint AS token_sold_mint_address + , e.quote_amount_in AS token_sold_amount_raw + , CAST((e.lp_fee_basis_points + e.protocol_fee_basis_points) AS DOUBLE) / 10000.0 AS fee_tier + , e.pool AS pool_id + , e.user AS trader_id + , e.evt_tx_id AS tx_id + , e.evt_outer_instruction_index AS outer_instruction_index + , e.evt_inner_instruction_index AS inner_instruction_index + , e.evt_tx_index AS tx_index + , pa.pool_base_token_account AS token_bought_vault + , pa.pool_quote_token_account AS token_sold_vault + FROM {{ source('pumpdotfun_solana', 'pump_amm_evt_buyevent') }} e + INNER JOIN pool_accounts pa + ON pa.pool = e.pool + LEFT JOIN {{ source('pumpdotfun_solana', 'pump_amm_call_buy') }} c + ON c.call_block_date = e.evt_block_date + AND c.call_tx_id = e.evt_tx_id + AND c.call_outer_instruction_index = e.evt_outer_instruction_index + AND c.account_pool = e.pool + AND c.base_amount_out = e.base_amount_out + AND c.call_block_date >= DATE '2025-11-01' + LEFT JOIN pools p ON p.pool = e.pool + WHERE c.call_tx_id IS NULL + AND e.evt_block_time >= TIMESTAMP '2025-11-01' + AND COALESCE(p.is_valid_pool, false) +) + +, trades AS ( + SELECT * FROM decoded_trades + + UNION ALL + + SELECT * FROM buy_exact_quote_in_trades +) + SELECT 'solana' AS blockchain , 'pumpswap' AS project diff --git a/dbt_subprojects/solana/models/_sources.yml b/dbt_subprojects/solana/models/_sources.yml index 408023a3610..1ea01097f3d 100644 --- a/dbt_subprojects/solana/models/_sources.yml +++ b/dbt_subprojects/solana/models/_sources.yml @@ -46,10 +46,15 @@ sources: schema: pumpdotfun_solana tables: - name: pump_amm_call_buy + config: + event_time: call_block_date - name: pump_amm_call_sell - name: pump_amm_call_create_pool - name: pump_amm_call_create_config - name: pump_amm_call_update_fee_config + - name: pump_amm_evt_buyevent + config: + event_time: evt_block_date - name: raydium_solana description: "Raydium protocol decoded tables" @@ -87,4 +92,3 @@ sources: - name: jupiter_call_shared_accounts_route_v2 - name: jupiter_evt_swapevent - name: jupiter_evt_swapsevent -