Skip to content

Commit

Permalink
An 5383/me decoded update (#775)
Browse files Browse the repository at this point in the history
* models and core update

* add currency address and logic update

* deprecate old table

* use tx_id as unique_key

* remove filter for legacy model

* update tests/cols, cleanup logic

* add cutoff date

* use jinja var, use timestamp to join
  • Loading branch information
tarikceric authored Jan 29, 2025
1 parent 759603a commit a4bbf76
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 24 deletions.
87 changes: 65 additions & 22 deletions models/gold/nft/nft__fact_nft_sales.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
) }}

{% if execute %}

{% set SOL_MINT = 'So11111111111111111111111111111111111111111' %}
{% set magic_eden_switchover_block_timestamp = '2024-03-16' %}

{% if is_incremental() %}
{% set query %}
SELECT MAX(modified_timestamp) AS max_modified_timestamp
Expand All @@ -20,6 +24,8 @@
{% endif %}
{% endif %}



-- Select from the deprecated _view models only during the initial FR
{% if not is_incremental() %}
SELECT
Expand All @@ -33,6 +39,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -58,6 +65,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -81,6 +89,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -106,6 +115,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -129,6 +139,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -152,6 +163,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -175,6 +187,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand Down Expand Up @@ -209,6 +222,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -230,6 +244,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -251,6 +266,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -274,10 +290,8 @@ FROM
WHERE
block_timestamp::date <= '2023-02-08'
UNION ALL
{% endif %}
-- Only select from active models during incremental
SELECT
'magic eden v2' as marketplace,
'magic eden v2',
block_timestamp,
block_id,
tx_id,
Expand All @@ -287,33 +301,23 @@ SELECT
seller,
mint,
sales_amount,
currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
FALSE as is_compressed,
COALESCE (
nft_sales_magic_eden_v2_id,
{{ dbt_utils.generate_surrogate_key(
['tx_id']
) }}
) AS fact_nft_sales_id,
COALESCE(
inserted_timestamp,
'2000-01-01'
) AS inserted_timestamp,
COALESCE(
modified_timestamp,
'2000-01-01'
) AS modified_timestamp
nft_sales_magic_eden_v2_id as fact_nft_sales_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver__nft_sales_magic_eden_v2') }}
{% if is_incremental() %}
{{ ref('silver__nft_sales_magic_eden_v2_view') }}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
block_timestamp::date < '{{ magic_eden_switchover_block_timestamp }}'
UNION ALL
{% endif %}
-- Only select from active models during incremental
SELECT
'solanart',
'solanart' as marketplace,
block_timestamp,
block_id,
tx_id,
Expand All @@ -323,6 +327,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand Down Expand Up @@ -359,6 +364,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -384,6 +390,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand Down Expand Up @@ -420,6 +427,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -445,6 +453,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand Down Expand Up @@ -481,6 +490,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -506,6 +516,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
tree_authority,
merkle_tree,
leaf_index,
Expand All @@ -531,6 +542,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
tree_authority,
merkle_tree,
leaf_index,
Expand All @@ -556,6 +568,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
tree_authority,
merkle_tree,
leaf_index,
Expand All @@ -581,6 +594,7 @@ SELECT
seller,
mint,
sales_amount,
'{{ SOL_MINT }}' as currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
Expand All @@ -594,3 +608,32 @@ FROM
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
UNION ALL
SELECT
'magic eden v2' AS marketplace,
block_timestamp,
block_id,
tx_id,
succeeded,
program_id,
purchaser,
seller,
mint,
sales_amount,
currency_address,
NULL as tree_authority,
NULL as merkle_tree,
NULL as leaf_index,
FALSE as is_compressed,
nft_sales_magic_eden_v2_decoded_id AS fact_nft_sales_id,
inserted_timestamp,
modified_timestamp,
FROM
{{ ref('silver__nft_sales_magic_eden_v2_decoded') }}
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% else %}
WHERE
block_timestamp::date >= '{{magic_eden_switchover_block_timestamp}}'
{% endif %}
7 changes: 6 additions & 1 deletion models/gold/nft/nft__fact_nft_sales.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ models:
tests:
- reference_tx_missing:
reference_tables:
- 'silver__nft_sales_magic_eden_v2'
- 'silver__nft_sales_magic_eden_v2_decoded'
- 'silver__nft_sales_solanart'
- 'silver__nft_sales_hadeswap_decoded'
- 'silver__nft_sales_hyperspace'
Expand Down Expand Up @@ -66,6 +66,11 @@ models:
tests:
- dbt_expectations.expect_column_to_exist
- not_null: *recent_date_filter
- name: CURRENCY_ADDRESS
description: "Address of token used to pay for the NFT"
tests:
- dbt_expectations.expect_column_to_exist
- not_null: *recent_date_filter
- name: MARKETPLACE
description: "{{ doc('marketplace') }}"
tests:
Expand Down
4 changes: 3 additions & 1 deletion models/silver/nfts/silver__nft_sales_magic_eden_v2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
unique_key = "tx_id",
incremental_strategy = 'delete+insert',
cluster_by = ['block_timestamp::DATE','modified_timestamp::DATE'],
tags = ['scheduled_non_core']
tags = ['scheduled_non_core'],
full_refresh = false,
enabled = false
) }}

/* run incremental timestamp value first then use it as a static value */
Expand Down
Loading

0 comments on commit a4bbf76

Please sign in to comment.