solana-models/models/gold/marinade/marinade__ez_liquid_staking_actions.sql
tarikceric ec4ff66c24
Some checks failed
docs_update / run_dbt_jobs (push) Has been cancelled
docs_update / notify-failure (push) Has been cancelled
dbt_run_streamline_solscan_token_list / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_solscan_token_list / notify-failure (push) Has been cancelled
dbt_test_scheduled_weekly / run_dbt_jobs (push) Has been cancelled
dbt_test_scheduled_weekly / notify-failure (push) Has been cancelled
dbt_test_scheduled / run_dbt_jobs (push) Has been cancelled
dbt_run_idls_history / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_validator_vote_program_accounts_snapshot / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_validator_vote_accounts_snapshot / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_validator_metadata_snapshot / run_dbt_jobs (push) Has been cancelled
dbt_run_streamline_validators_list_snapshot / run_dbt_jobs (push) Has been cancelled
dbt_run_scheduled_daily / run_dbt_jobs (push) Has been cancelled
dbt_run_macro_get_compressed_nft / run_dbt_jobs (push) Has been cancelled
dbt_run_helius_metadata / run_dbt_jobs (push) Has been cancelled
dbt_test_intraday / run_dbt_jobs (push) Has been cancelled
dbt_run_dev_refresh / run_dbt_jobs (push) Has been cancelled
dbt_run_macro_get_block_production / run_dbt_jobs (push) Has been cancelled
dbt_test_scheduled_hourly / run_dbt_jobs (push) Has been cancelled
dbt_run_batch_backfill / run_dbt_jobs (push) Has been cancelled
dbt_test_scheduled / notify-failure (push) Has been cancelled
dbt_run_idls_history / notify-failure (push) Has been cancelled
dbt_run_streamline_validator_vote_program_accounts_snapshot / notify-failure (push) Has been cancelled
dbt_run_streamline_validator_vote_accounts_snapshot / notify-failure (push) Has been cancelled
dbt_run_streamline_validator_metadata_snapshot / notify-failure (push) Has been cancelled
dbt_run_streamline_validators_list_snapshot / notify-failure (push) Has been cancelled
dbt_run_scheduled_daily / notify-failure (push) Has been cancelled
dbt_run_macro_get_compressed_nft / notify-failure (push) Has been cancelled
dbt_run_helius_metadata / notify-failure (push) Has been cancelled
dbt_test_intraday / notify-failure (push) Has been cancelled
dbt_run_macro_get_block_production / notify-failure (push) Has been cancelled
dbt_test_scheduled_hourly / notify-failure (push) Has been cancelled
dbt_run_full_observability / run_dbt_jobs (push) Has been cancelled
dbt_run_full_observability / notify-failure (push) Has been cancelled
add signer (#891)
2025-11-18 20:54:09 +01:00

81 lines
2.3 KiB
SQL

{{ config(
materialized = 'incremental',
meta = { 'database_tags': { 'table': { 'PROTOCOL': 'MARINADE', 'PURPOSE': 'STAKING' }}},
unique_key = ['marinade_ez_liquid_staking_actions_id'],
incremental_predicates = ["dynamic_range_predicate", "block_timestamp::date"],
cluster_by = ['block_timestamp::DATE', 'program_id'],
merge_exclude_columns = ["inserted_timestamp"],
post_hook = enable_search_optimization('{{this.schema}}', '{{this.identifier}}', 'ON EQUALITY(tx_id, action_type, provider_address)'),
tags = ['scheduled_non_core']
) }}
{% if execute %}
{% if is_incremental() %}
{% set query %}
SELECT MAX(modified_timestamp) AS max_modified_timestamp
FROM {{ this }}
{% endset %}
{% set max_modified_timestamp = run_query(query)[0][0] %}
{% endif %}
{% endif %}
WITH liquid_staking_actions AS (
SELECT
block_id,
block_timestamp,
tx_id,
index,
inner_index,
signer,
action_type,
provider_address,
deposit_amount,
msol_minted,
msol_burned,
claim_amount,
program_id,
_inserted_timestamp,
marinade_liquid_staking_actions_id AS marinade_ez_liquid_staking_actions_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__marinade_liquid_staking_actions') }}
{% if is_incremental() %}
WHERE modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
),
prices AS (
SELECT
HOUR,
token_address,
symbol,
price
FROM
{{ ref('price__ez_prices_hourly') }}
)
SELECT
a.block_id,
a.block_timestamp,
a.tx_id,
a.index,
a.inner_index,
a.signer,
a.action_type,
a.provider_address,
a.deposit_amount,
ROUND(b.price * a.deposit_amount, 2) AS deposit_amount_usd,
a.msol_minted,
a.msol_burned,
a.claim_amount,
ROUND(b.price * a.claim_amount, 2) AS claim_amount_usd,
a.program_id,
a.marinade_ez_liquid_staking_actions_id,
a.inserted_timestamp,
a.modified_timestamp
FROM
liquid_staking_actions a
LEFT JOIN prices b
ON a.action_type IN ('claim', 'deposit', 'depositStakeAccount')
AND b.token_address = 'So11111111111111111111111111111111111111112'
AND DATE_TRUNC('hour', a.block_timestamp) = b.hour