Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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: [ stilldasmainaem ]
config:
tags: [ 'solana','dex','pumpswap' ]
description: >
staging model for pumpswap new buy event decoded from raw instruction_calls
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, stilldasmainaem]
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,17 @@
{{
config(
schema = 'pumpswap_solana',
alias = 'int_all_swaps',
materialized = 'view'
)
}}

SELECT
*
FROM {{ ref('pumpswap_solana_stg_decoded_swaps')}}

UNION ALL

SELECT
*
FROM {{ref('pumpswap_solana_stg_decoded_newevent')}}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ WITH pools AS (
, base_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
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,89 @@
{{
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-08' %}

-- New buy event decoded from raw instruction_calls (discriminator: 0xe445a52e51cb9a1d67f4521f2cf57777)
WITH new_buy_events_raw AS (
SELECT
g.block_time
, g.block_slot
, g.block_date
, g.outer_instruction_index
, f.inner_instruction_index
, g.tx_id
, g.tx_index
, g.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
, ROW_NUMBER() OVER (
PARTITION BY g.tx_id, g.outer_instruction_index, g.inner_instruction_index
ORDER BY f.inner_instruction_index
) AS rn -- To avoid potential duplicate rows rom the join
FROM {{ source('solana', 'instruction_calls') }} g
JOIN {{ source('solana', 'instruction_calls') }} f
ON g.tx_id = f.tx_id
AND g.block_date = f.block_date
AND g.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 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
AND g.block_time >= TIMESTAMP '{{ project_start_date }}'
{% if is_incremental() %}
AND {{ incremental_predicate('g.block_time') }}
{% endif %}
)

SELECT
block_slot
, CAST(date_trunc('month', block_date) AS DATE) AS block_month
, block_date
, block_time
, COALESCE(inner_instruction_index, 0) AS inner_instruction_index
, inner_instruction_index AS swap_inner_index
, outer_instruction_index
, outer_executing_account
, tx_id
, 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
, 1 AS is_buy
, {{ solana_instruction_key(
'block_slot'
, 'tx_index'
, 'outer_instruction_index'
, 'COALESCE(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 @@ -95,4 +95,4 @@ SELECT
, 'sp.call_outer_instruction_index'
, 'COALESCE(sp.call_inner_instruction_index, 0)'
) }} AS surrogate_key
FROM swaps sp
FROM swaps sp
Loading