Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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
Expand Up @@ -67,6 +67,51 @@ WITH swaps AS (
{% else %}
AND call_block_time >= TIMESTAMP '{{ project_start_date }}'
{% endif %}

UNION ALL


-- New buy event decoded from raw instruction_calls (discriminator: 0xe445a52e51cb9a1d67f4521f2cf57777)

SELECT
g.block_time AS call_block_time
, g.block_slot AS call_block_slot
, CAST(g.block_date AS DATE) AS call_block_date
, g.outer_instruction_index AS call_outer_instruction_index
, g.inner_instruction_index AS call_inner_instruction_index
, g.tx_id AS call_tx_id
, g.tx_index AS call_tx_index
, g.outer_executing_account AS call_outer_executing_account
, to_base58(bytearray_substring(g.data, 129, 32)) AS account_pool
, to_base58(bytearray_substring(g.data, 161, 32)) AS account_user
, to_base58(bytearray_substring(g.data, 193, 32)) AS account_user_base_token_account
, to_base58(bytearray_substring(g.data, 225, 32)) 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
, to_base58(bytearray_substring(g.data, 289, 32)) AS account_protocol_fee_recipient_token_account
, bytearray_to_uint256(bytearray_reverse(bytearray_substring(g.data, 25, 8))) AS base_amount
, 1 AS is_buy
FROM {{ source('solana', 'instruction_calls') }} g
JOIN {{ source('solana', 'instruction_calls') }} f
ON g.tx_id = f.tx_id
AND bytearray_substring(f.data, 1, 8) = 0xc62e1552b4d9e870
AND f.executing_account = 'pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA'
AND f.tx_success = true
{% if is_incremental() %}
AND {{ incremental_predicate('f.block_time') }}
{% else %}
AND f.block_time >= TIMESTAMP '{{ project_start_date }}'
{% endif %}
WHERE bytearray_substring(g.data, 1, 16) = 0xe445a52e51cb9a1d67f4521f2cf57777
AND g.executing_account = 'pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA'
AND g.is_inner = true
AND g.tx_success = true
AND length(g.data) = 447
{% if is_incremental() %}
AND {{ incremental_predicate('g.block_time') }}
{% else %}
AND g.block_time >= TIMESTAMP '{{ project_start_date }}'
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

Tighten the gf join to an instruction-scoped key.

Right now this branch matches g and f on tx_id only. If a transaction contains more than one qualifying PumpFun instruction, every matching f row can pair with every matching g row, which will duplicate swaps and attach the wrong account_pool_*_token_account values. Please join on the smallest instruction-level key that makes the relationship 1:1 for this tx, and include block_date in the join/filter so the raw-table self-join stays prunable.

As per coding guidelines, "Filter on block_date (not block_time) for partition pruning, and always include partition columns in WHERE and JOIN conditions".

🤖 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`
around lines 95 - 113, The join between g and f is currently only on tx_id
causing N:N matches; change it to a 1:1 instruction-scoped join (add the
instruction-level key such as instruction_index or instruction_id: e.g., ON
g.tx_id = f.tx_id AND g.instruction_index = f.instruction_index) and include
block_date equality (AND g.block_date = f.block_date) so the relationship is
unique and partition-prunable; also switch any filters using block_time to use
block_date for partition pruning (replace incremental_predicate('f.block_time')
and incremental_predicate('g.block_time') with
incremental_predicate('f.block_date') and incremental_predicate('g.block_date')
and ensure WHERE includes AND g.block_date >= DATE '{{ project_start_date }}' /
f.block_date counterpart).

{% endif %}
)

SELECT
Expand Down Expand Up @@ -95,4 +140,4 @@ SELECT
, 'sp.call_outer_instruction_index'
, 'COALESCE(sp.call_inner_instruction_index, 0)'
) }} AS surrogate_key
FROM swaps sp
FROM swaps sp
Loading