Skip to content
Merged
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
38 changes: 17 additions & 21 deletions dbt_subprojects/solana/macros/_sector/gas/solana_tx_fees_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@ WITH base_model AS (
t.signer,
t.fee AS tx_fee_raw,
5000*required_signatures as base_fee_raw, -- each signature is 5000 lamports
(COALESCE(cb.compute_limit, 200000) * COALESCE(cb.compute_unit_price/ 1e6, 0)) AS prioritization_fee_raw,
COALESCE(cb.compute_unit_price/ 1e6, 0) AS compute_unit_price,
COALESCE(cb.compute_limit, 200000) AS compute_limit,
(COALESCE(cl.compute_limit, 200000) * COALESCE(up.compute_unit_price/ 1e6, 0)) AS prioritization_fee_raw,
COALESCE(up.compute_unit_price/ 1e6, 0) AS compute_unit_price,
COALESCE(cl.compute_limit, 200000) AS compute_limit,
'So11111111111111111111111111111111111111112' AS tx_fee_currency,
b.leader
FROM {{ source('solana', 'transactions') }} t
LEFT JOIN {{ ref('gas_solana_compute_budget') }} cb
ON t.id = cb.tx_id
AND t.block_date = cb.block_date
LEFT JOIN {{ ref('gas_solana_compute_limit') }} cl
ON t.id = cl.tx_id
AND t.block_date = cl.block_date
{% if is_incremental() %}
AND {{ incremental_predicate('cb.block_date') }}
AND {{ incremental_predicate('cl.block_date') }}
{% else %}
AND cb.block_date >= {{ start_date }}
AND cb.block_date < {{ end_date }}
AND cl.block_date >= {{ start_date }}
AND cl.block_date < {{ end_date }}
{% endif %}
{% if target.name == 'ci' %}
AND cb.block_date >= current_date - interval '3' day
LEFT JOIN {{ ref('gas_solana_compute_unit_price') }} up
ON t.id = up.tx_id
AND t.block_date = up.block_date
{% if is_incremental() %}
AND {{ incremental_predicate('up.block_date') }}
{% else %}
AND up.block_date >= {{ start_date }}
AND up.block_date < {{ end_date }}
{% endif %}
LEFT JOIN {{ ref('solana_utils_block_leaders') }} b
ON t.block_slot = b.slot
Expand All @@ -38,20 +44,13 @@ WITH base_model AS (
AND b.date >= {{ start_date }}
AND b.date < {{ end_date }}
{% endif %}
{% if target.name == 'ci' %}
AND b.date >= current_date - interval '3' day
{% endif %}
WHERE 1=1
{% if is_incremental() %}
AND {{ incremental_predicate('t.block_date') }}
{% else %}
AND t.block_date >= {{ start_date }}
AND t.block_date < {{ end_date }}
{% endif %}
{% if target.name == 'ci' %}
-- bound the full-refresh scan in CI so the build completes within the 90-min cap; prod is unaffected
AND t.block_date >= current_date - interval '3' day
{% endif %}
)

SELECT
Expand Down Expand Up @@ -94,7 +93,4 @@ LEFT JOIN {{ source('prices','usd_forward_fill') }} p
AND p.minute >= {{ start_date }}
AND p.minute < {{ end_date }}
{% endif %}
{% if target.name == 'ci' %}
AND p.minute >= current_date - interval '3' day
{% endif %}
{% endmacro %}
46 changes: 0 additions & 46 deletions dbt_subprojects/solana/models/_sector/gas/_schema.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,6 @@
version: 2

models:
- name: gas_solana_compute_budget
meta:
blockchain: solana
sector: gas
short_description: "Decoded Solana ComputeBudget program instructions per transaction: compute_limit (SetComputeUnitLimit / opcode 0x02) and compute_unit_price (SetComputeUnitPrice / opcode 0x03), keyed on (block_date, block_slot, tx_id)."
contributors: robinnehin
config:
tags: ['solana', 'gas', 'compute_budget']
description: >
Merged ComputeBudget decodings for Solana transactions. Reads
solana.instruction_calls once with an IN filter on the two opcodes and
pivots to one row per (block_date, tx_id), so downstream fee models can
join once instead of twice. gas_solana_compute_limit and
gas_solana_compute_unit_price are backward-compat views over this table.
data_tests:
- dbt_utils.unique_combination_of_columns:
arguments:
combination_of_columns:
- block_date
- block_hour
- block_slot
- tx_id
columns:
- name: tx_id
description: Solana transaction signature
data_tests:
- not_null
- name: block_date
data_tests:
- not_null
- name: block_hour
description: Truncated to hour, used as partition column
data_tests:
- not_null
- name: block_time
data_tests:
- not_null
- name: block_slot
data_tests:
- not_null
- name: tx_index
description: Position of the transaction within its block
- name: compute_limit
description: Requested compute unit limit (SetComputeUnitLimit / opcode 0x02). NULL when the transaction did not emit this instruction.
- name: compute_unit_price
description: Compute unit price in micro-lamports (SetComputeUnitPrice / opcode 0x03). NULL when the transaction did not emit this instruction.
- name: gas_solana_compute_limit #todo: add full metadata and tests
- name: gas_solana_compute_unit_price #todo: add full metadata and tests
- name: gas_solana_tx_fees #todo: add full metadata and tests
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
{{ config(
schema = 'gas_solana',
alias = 'compute_limit',
materialized = 'view'
partition_by = ['block_date', 'block_hour'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'delete+insert',
unique_key = ['block_date', 'block_slot', 'tx_id']
) }}

-- Backward-compat view. Physical decoding lives in gas_solana_compute_budget which
-- also holds compute_unit_price. Filter compute_limit IS NOT NULL to preserve the
-- historical row set (only txs that emitted the SetComputeUnitLimit opcode 0x02).
-- this is just decoding program data, could be moved into decoding pipeline

SELECT
tx_id,
block_date,
block_hour,
date_trunc('hour', block_time) AS block_hour,
block_time,
block_slot,
tx_index,
compute_limit
FROM {{ ref('gas_solana_compute_budget') }}
WHERE compute_limit IS NOT NULL
bytearray_to_bigint(
bytearray_reverse(
bytearray_substring(data, 2, 8)
)
) as compute_limit
FROM {{ source('solana', 'instruction_calls') }}
WHERE executing_account = 'ComputeBudget111111111111111111111111111111'
AND executing_account_prefix = 'Co'
AND bytearray_substring(data,1,1) = 0x02
AND inner_instruction_index is null
{% if is_incremental() %}
AND {{ incremental_predicate('block_date') }}
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
{{ config(
schema = 'gas_solana',
alias = 'compute_unit_price',
materialized = 'view'
partition_by = ['block_date', 'block_hour'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'delete+insert',
unique_key = ['block_date', 'block_slot', 'tx_id']
) }}

-- Backward-compat view. Physical decoding lives in gas_solana_compute_budget which
-- also holds compute_limit. Filter compute_unit_price IS NOT NULL to preserve the
-- historical row set (only txs that emitted the SetComputeUnitPrice opcode 0x03).
-- this is just decoding program data, could be moved into decoding pipeline

SELECT
tx_id,
block_date,
block_hour,
date_trunc('hour', block_time) AS block_hour,
block_time,
block_slot,
tx_index,
compute_unit_price
FROM {{ ref('gas_solana_compute_budget') }}
WHERE compute_unit_price IS NOT NULL
bytearray_to_bigint(
bytearray_reverse(
bytearray_substring(data, 2, 8)
)
) AS compute_unit_price
FROM {{ source('solana', 'instruction_calls') }}
WHERE executing_account = 'ComputeBudget111111111111111111111111111111'
AND executing_account_prefix = 'Co'
AND bytearray_substring(data,1,1) = 0x03
AND inner_instruction_index is null
{% if is_incremental() %}
AND {{ incremental_predicate('block_date') }}
{% endif %}
Loading