Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions dbt_subprojects/solana/models/_sector/dex/pumpswap/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ models:
- dbt_utils.unique_combination_of_columns:
combination_of_columns: [ 'block_month', 'block_date', 'surrogate_key' ]

- name: pumpswap_solana_stg_decoded_newevent
meta:
blockchain: solana
contributors: [ dev2020 ]
config:
tags: [ 'solana','dex','pumpswap' ]
description: >
staging model for pumpswap new buy event from decoded table
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns: [ 'block_month', 'block_date', 'surrogate_key' ]

- name: pumpswap_solana_int_all_swaps
meta:
blockchain: solana
contributors: [ krishhh, dev2020]
config:
tags: [ 'solana','dex','pumpswap' ]
description: >
intermediate model that unions old and new pumpswap swap events
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns: [ 'block_month', 'block_date', 'surrogate_key' ]

- name: pumpswap_solana_base_trades_backfill
meta:
blockchain: solana
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{
config(
schema = 'pumpswap_solana',
alias = 'int_all_swaps',
materialized = 'view'
)
}}

SELECT
block_slot
, block_month
, block_date
, block_time
, inner_instruction_index
, swap_inner_index
, outer_instruction_index
, outer_executing_account
, tx_id
, tx_index
, pool
, user_account
, account_user_base_token_account
, account_user_quote_token_account
, account_pool_base_token_account
, account_pool_quote_token_account
, account_protocol_fee_recipient_token_account
, base_amount
, quote_amount
, is_buy
, surrogate_key
FROM {{ ref('pumpswap_solana_stg_decoded_swaps')}}

UNION ALL

SELECT
block_slot
, block_month
, block_date
, block_time
, inner_instruction_index
, swap_inner_index
, outer_instruction_index
, outer_executing_account
, tx_id
, tx_index
, pool
, user_account
, account_user_base_token_account
, account_user_quote_token_account
, account_pool_base_token_account
, account_pool_quote_token_account
, account_protocol_fee_recipient_token_account
, base_amount
, quote_amount
, is_buy
, surrogate_key
FROM {{ref('pumpswap_solana_stg_decoded_newevent')}}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
, file_format = 'delta'
, incremental_strategy = 'microbatch'
, event_time = 'block_time'
, begin = '2025-02-20'
, begin = '2026-03-06'
, batch_size = var('pumpswap_batch_size', 'day')
, lookback = 1
, unique_key = ['block_month', 'surrogate_key']
, pre_hook='{{ enforce_join_distribution("PARTITIONED") }}'
)
}}

{% set begin = '2025-02-20' %}
{% set begin = '2026-03-06' %}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Keep the SQL fallback begin aligned with the model config.

This no longer matches Line 11's config(begin = '2025-02-20'). When model.batch is absent, the query now skips the first year of Pumpswap trades even though the microbatch config still says to backfill from February 20, 2025.

Suggested fix
-{% set begin = '2026-03-06' %}
+{% set begin = '2025-02-20' %}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{% set begin = '2026-03-06' %}
{% set begin = '2025-02-20' %}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@dbt_subprojects/solana/models/_sector/dex/pumpswap/pumpswap_solana_base_trades_backfill.sql`
at line 19, The fallback date assigned to the Jinja variable begin ('{% set
begin = ... %}') is out of sync with the model config; update the fallback value
used when model.batch is absent so it matches the model config(begin =
'2025-02-20') — i.e., change the begin fallback to '2025-02-20' in the
pumpswap_solana_base_trades_backfill.sql template so the query backfills from
the same date as the model config.

{% set batch_start = model.batch.event_time_start if model.batch else begin %}
{% set batch_end = model.batch.event_time_end if model.batch else '2099-01-01' %}

Expand Down Expand Up @@ -48,9 +48,10 @@ WITH pools AS (
, account_pool_quote_token_account
, account_protocol_fee_recipient_token_account
, base_amount
, quote_amount
, is_buy
, surrogate_key
FROM {{ ref('pumpswap_solana_stg_decoded_swaps') }}
FROM {{ ref('pumpswap_solana_int_all_swaps') }}
WHERE
block_time >= TIMESTAMP '{{ batch_start }}'
AND block_time < TIMESTAMP '{{ batch_end }}'
Expand Down Expand Up @@ -98,6 +99,7 @@ WITH pools AS (
)

, swaps_with_transfers AS (
-- Old events: require transfer match
SELECT
sf.*
, sf.base_amount AS base_token_amount
Expand Down Expand Up @@ -129,6 +131,18 @@ WITH pools AS (
END
)
)
WHERE sf.quote_amount IS NULL -- Only old events need transfer lookup

UNION ALL

-- New events: already have quote_token_amount
SELECT
sf.*
, sf.base_amount AS base_token_amount
, sf.quote_amount AS quote_token_amount
, 1 AS rn
FROM swaps_with_fees sf
WHERE sf.quote_amount IS NOT NULL
)

, trades AS (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ SELECT
p.quoteMint,
p.baseMintDecimals,
p.quoteMintDecimals
FROM pool_creation p
FROM pool_creation p
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{{
config(
schema = 'pumpswap_solana'
, alias = 'stg_decoded_newevent'
, partition_by = ['block_month']
, materialized = 'incremental'
, file_format = 'delta'
, incremental_strategy = 'merge'
, incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')]
Comment thread
coderabbitai[bot] marked this conversation as resolved.
, unique_key = ['block_month', 'block_date', 'surrogate_key']
)
}}

{% set project_start_date = '2026-03-06' %}

-- New buy event decoded from decoded table
WITH new_buy_events_raw AS (
SELECT
g.evt_block_time
, g.evt_block_slot
, g.evt_block_date
, g.evt_outer_instruction_index
, g.evt_inner_instruction_index
, g.evt_tx_id
, g.evt_tx_index
, g.evt_outer_executing_account
, g.pool
, g.user
, g.user_base_token_account AS account_user_base_token_account
, g.user_quote_token_account AS account_user_quote_token_account
, f.account_arguments[8] AS account_pool_base_token_account
, f.account_arguments[9] AS account_pool_quote_token_account
, g.protocol_fee_recipient_token_account AS account_protocol_fee_recipient_token_account
, g.base_amount_out AS base_amount
, g.quote_amount_in AS quote_amount
, ROW_NUMBER() OVER (
PARTITION BY g.evt_tx_id, g.evt_outer_instruction_index, g.evt_inner_instruction_index
ORDER BY f.inner_instruction_index
) AS rn -- To avoid potential duplicate rows rom the join
FROM {{ source('pumpdotfun_solana', 'pump_amm_evt_buyevent') }} g
INNER JOIN {{ source('solana', 'instruction_calls') }} f
ON g.evt_tx_id = f.tx_id
AND g.evt_block_date = f.block_date
AND g.evt_outer_instruction_index = f.outer_instruction_index
AND bytearray_substring(f.data, 1, 8) = 0xc62e1552b4d9e870
AND f.executing_account = 'pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA'
AND f.tx_success = true
AND f.block_time >= TIMESTAMP '{{ project_start_date }}'
{% if is_incremental() %}
AND {{ incremental_predicate('f.block_time') }}
{% endif %}
WHERE 1=1
{% if is_incremental() %}
AND {{ incremental_predicate('g.evt_block_time') }}
{% else %}
AND g.evt_block_time >= TIMESTAMP '{{ project_start_date }}'
{% endif %}


)

SELECT
evt_block_slot AS block_slot
, CAST(date_trunc('month', evt_block_date) AS DATE) AS block_month
, evt_block_date AS block_date
, evt_block_time as block_time
, COALESCE(evt_inner_instruction_index, 0) AS inner_instruction_index
, evt_inner_instruction_index AS swap_inner_index
, evt_outer_instruction_index AS outer_instruction_index
, evt_outer_executing_account AS outer_executing_account
, evt_tx_id AS tx_id
, evt_tx_index AS tx_index
, pool
, user as user_account
, account_user_base_token_account
, account_user_quote_token_account
, account_pool_base_token_account
, account_pool_quote_token_account
, account_protocol_fee_recipient_token_account
, base_amount
, quote_amount
, 1 AS is_buy
, {{ solana_instruction_key(
'evt_block_slot'
, 'evt_tx_index'
, 'evt_outer_instruction_index'
, 'COALESCE(evt_inner_instruction_index, 0)'
) }} AS surrogate_key
FROM new_buy_events_raw
WHERE rn = 1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
}}

{% set project_start_date = '2025-02-20' %}
{% set project_start_date = '2026-03-06' %}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Don't narrow the legacy swaps model to March 2026.

This staging model still carries the pre-new-event buy/sell history. Moving project_start_date to 2026-03-06 means any full refresh or first-time build will miss swaps from 2025-02-20 through 2026-03-05, and pumpswap_solana_int_all_swaps cannot reconstruct them because the new-event model only covers the new discriminator path.

Suggested fix
-{% set project_start_date = '2026-03-06' %}
+{% set project_start_date = '2025-02-20' %}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@dbt_subprojects/solana/models/_sector/dex/pumpswap/staging/pumpswap_solana_stg_decoded_swaps.sql`
at line 14, The project_start_date was narrowed to '2026-03-06', which will drop
legacy swaps (2025-02-20 through 2026-03-05); revert project_start_date in
pumpswap_solana_stg_decoded_swaps (the project_start_date variable) to the
previous/original value that covers 2025-02-20 (or set it to an earlier
universal start) so that pumpswap_solana_int_all_swaps can reconstruct full
history, or remove the artificial restriction entirely so legacy swaps are
preserved.


WITH swaps AS (
SELECT
Expand All @@ -31,6 +31,7 @@ WITH swaps AS (
, account_pool_quote_token_account
, account_protocol_fee_recipient_token_account
, base_amount_out AS base_amount
, CAST(NULL AS BIGINT) AS quote_amount
, 1 AS is_buy
FROM {{ source('pumpdotfun_solana', 'pump_amm_call_buy') }}
WHERE 1=1
Expand Down Expand Up @@ -59,6 +60,7 @@ WITH swaps AS (
, account_pool_quote_token_account
, account_protocol_fee_recipient_token_account
, base_amount_in AS base_amount
, CAST(NULL AS BIGINT) AS quote_amount
, 0 AS is_buy
FROM {{ source('pumpdotfun_solana', 'pump_amm_call_sell') }}
WHERE 1=1
Expand All @@ -70,29 +72,30 @@ WITH swaps AS (
)

SELECT
sp.call_block_slot AS block_slot
, CAST(date_trunc('month', sp.call_block_date) AS DATE) AS block_month
, sp.call_block_date AS block_date
, sp.call_block_time AS block_time
, COALESCE(sp.call_inner_instruction_index, 0) AS inner_instruction_index
, sp.call_inner_instruction_index AS swap_inner_index
, sp.call_outer_instruction_index AS outer_instruction_index
, sp.call_outer_executing_account AS outer_executing_account
, sp.call_tx_id AS tx_id
, sp.call_tx_index AS tx_index
, sp.account_pool AS pool
, sp.account_user AS user_account
, sp.account_user_base_token_account
, sp.account_user_quote_token_account
, sp.account_pool_base_token_account
, sp.account_pool_quote_token_account
, sp.account_protocol_fee_recipient_token_account
, sp.base_amount
, sp.is_buy
call_block_slot AS block_slot
, CAST(date_trunc('month', call_block_date) AS DATE) AS block_month
, call_block_date AS block_date
, call_block_time AS block_time
, COALESCE(call_inner_instruction_index, 0) AS inner_instruction_index
, call_inner_instruction_index AS swap_inner_index
, call_outer_instruction_index AS outer_instruction_index
, call_outer_executing_account AS outer_executing_account
, call_tx_id AS tx_id
, call_tx_index AS tx_index
, account_pool AS pool
, account_user AS user_account
, account_user_base_token_account
, account_user_quote_token_account
, account_pool_base_token_account
, account_pool_quote_token_account
, account_protocol_fee_recipient_token_account
, base_amount
, quote_amount
, is_buy
, {{ solana_instruction_key(
'sp.call_block_slot'
, 'sp.call_tx_index'
, 'sp.call_outer_instruction_index'
, 'COALESCE(sp.call_inner_instruction_index, 0)'
'call_block_slot'
, 'call_tx_index'
, 'call_outer_instruction_index'
, 'COALESCE(call_inner_instruction_index, 0)'
) }} AS surrogate_key
FROM swaps sp
FROM swaps
1 change: 1 addition & 0 deletions dbt_subprojects/solana/models/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sources:
- name: pump_amm_call_create_pool
- name: pump_amm_call_create_config
- name: pump_amm_call_update_fee_config
- name: pump_amm_evt_buyevent

- name: raydium_solana
description: "Raydium protocol decoded tables"
Expand Down
Loading