diff --git a/models/silver/nfts/silver__nft_sales_magic_eden_cnft.sql b/models/silver/nfts/silver__nft_sales_magic_eden_cnft.sql new file mode 100644 index 000000000..0daaf7f62 --- /dev/null +++ b/models/silver/nfts/silver__nft_sales_magic_eden_cnft.sql @@ -0,0 +1,69 @@ +{{ config( + materialized = 'incremental', + unique_key = ['nft_sales_magic_eden_cnft_id'], + incremental_strategy = 'delete+insert', + merge_exclude_columns = ["inserted_timestamp"], + tags = ['scheduled_non_core'] +) }} + +WITH mint_addresses AS ( + + SELECT + r.value :tx_id :: STRING AS tx_id, + COALESCE( + r.value :mint :: STRING, + '' + ) AS mint, + r.value :index :: INTEGER AS mint_index, + r.value :inner_index :: INTEGER AS mint_inner_index, + _inserted_timestamp AS mint_inserted_timestamp + FROM + {{ ref('bronze_api__parse_compressed_nft_sales_magic_eden') }}, + TABLE(FLATTEN(responses)) AS r + WHERE + mint <> '' + {% if is_incremental() %} + AND _inserted_timestamp >= ( + SELECT + MAX(mint_inserted_timestamp) + FROM + {{ this }} + ) + {% endif %} + qualify(ROW_NUMBER() over (PARTITION BY tx_id, mint + ORDER BY + _inserted_timestamp DESC)) = 1 +) +SELECT + A.block_id, + A.block_timestamp, + A.program_id, + A.tx_id, + A.succeeded, + A.purchaser, + A.seller, + A.tree_authority, + A.merkle_tree, + A.leaf_index, + b.mint, + b.mint_inserted_timestamp, + A.sales_amount, + A._inserted_timestamp, + {{ dbt_utils.generate_surrogate_key( + ['a.tx_id','b.mint'] + ) }} AS nft_sales_magic_eden_cnft_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp +FROM + {{ ref('silver__nft_sales_magic_eden_cnft_onchain') }} A + INNER JOIN mint_addresses b + ON A.tx_id = b.tx_id + +{% if is_incremental() %} +WHERE A._inserted_timestamp >= ( + SELECT + MAX(_inserted_timestamp) + FROM + {{ this }} +) +{% endif %} diff --git a/models/silver/nfts/silver__nft_sales_magic_eden_cnft.yml b/models/silver/nfts/silver__nft_sales_magic_eden_cnft.yml new file mode 100644 index 000000000..571aa4f50 --- /dev/null +++ b/models/silver/nfts/silver__nft_sales_magic_eden_cnft.yml @@ -0,0 +1,64 @@ +version: 2 +models: + - name: silver__nft_sales_magic_eden_cnft + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - MINT + columns: + - name: BLOCK_TIMESTAMP + description: "{{ doc('block_timestamp') }}" + tests: + - not_null + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 2 + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + tests: + - not_null + - name: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - not_null + - name: SUCCEEDED + description: "{{ doc('tx_succeeded') }}" + tests: + - not_null + - name: PROGRAM_ID + description: "{{ doc('program_id') }}" + tests: + - not_null + - name: PURCHASER + description: "{{ doc('purchaser') }}" + tests: + - not_null + - name: SELLER + description: "{{ doc('seller') }}" + tests: + - not_null + - name: SALES_AMOUNT + description: "{{ doc('sales_amount') }}" + tests: + - not_null + - name: TREE_AUTHORITY + description: "{{ doc('tree_authority') }}" + tests: + - not_null + - name: MERKLE_TREE + description: "{{ doc('merkle_tree') }}" + tests: + - not_null + - name: LEAF_INDEX + description: "{{ doc('leaf_index') }}" + tests: + - not_null + - name: MINT + description: "{{ doc('mint') }}" + tests: + - not_null + - name: _INSERTED_TIMESTAMP + description: "{{ doc('_inserted_timestamp') }}" + tests: + - not_null diff --git a/models/silver/nfts/silver__nft_sales_solsniper_cnft.sql b/models/silver/nfts/silver__nft_sales_solsniper_cnft.sql new file mode 100644 index 000000000..ab803f3cc --- /dev/null +++ b/models/silver/nfts/silver__nft_sales_solsniper_cnft.sql @@ -0,0 +1,69 @@ +{{ config( + materialized = 'incremental', + unique_key = ['nft_sales_solsniper_cnft_id'], + incremental_strategy = 'delete+insert', + merge_exclude_columns = ["inserted_timestamp"], + tags = ['scheduled_non_core'] +) }} + +WITH mint_addresses AS ( + + SELECT + r.value :tx_id :: STRING AS tx_id, + COALESCE( + r.value :mint :: STRING, + '' + ) AS mint, + r.value :index :: INTEGER AS mint_index, + r.value :inner_index :: INTEGER AS mint_inner_index, + _inserted_timestamp AS mint_inserted_timestamp + FROM + {{ ref('bronze_api__parse_compressed_nft_sales_solsniper') }}, + TABLE(FLATTEN(responses)) AS r + WHERE + mint <> '' + {% if is_incremental() %} + AND _inserted_timestamp >= ( + SELECT + MAX(mint_inserted_timestamp) + FROM + {{ this }} + ) + {% endif %} + qualify(ROW_NUMBER() over (PARTITION BY tx_id, mint + ORDER BY + _inserted_timestamp DESC)) = 1 +) +SELECT + A.block_id, + A.block_timestamp, + A.program_id, + A.tx_id, + A.succeeded, + A.purchaser, + A.seller, + A.tree_authority, + A.merkle_tree, + A.leaf_index, + b.mint, + b.mint_inserted_timestamp, + A.sales_amount, + A._inserted_timestamp, + {{ dbt_utils.generate_surrogate_key( + ['a.tx_id','b.mint'] + ) }} AS nft_sales_solsniper_cnft_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp +FROM + {{ ref('silver__nft_sales_solsniper_cnft_onchain') }} A + INNER JOIN mint_addresses b + ON A.tx_id = b.tx_id + +{% if is_incremental() %} +WHERE A._inserted_timestamp >= ( + SELECT + MAX(_inserted_timestamp) + FROM + {{ this }} +) +{% endif %} diff --git a/models/silver/nfts/silver__nft_sales_solsniper_cnft.yml b/models/silver/nfts/silver__nft_sales_solsniper_cnft.yml new file mode 100644 index 000000000..0cb2fc873 --- /dev/null +++ b/models/silver/nfts/silver__nft_sales_solsniper_cnft.yml @@ -0,0 +1,64 @@ +version: 2 +models: + - name: silver__nft_sales_solsniper_cnft + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TX_ID + - MINT + columns: + - name: BLOCK_TIMESTAMP + description: "{{ doc('block_timestamp') }}" + tests: + - not_null + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 2 + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + tests: + - not_null + - name: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - not_null + - name: SUCCEEDED + description: "{{ doc('tx_succeeded') }}" + tests: + - not_null + - name: PROGRAM_ID + description: "{{ doc('program_id') }}" + tests: + - not_null + - name: PURCHASER + description: "{{ doc('purchaser') }}" + tests: + - not_null + - name: SELLER + description: "{{ doc('seller') }}" + tests: + - not_null + - name: SALES_AMOUNT + description: "{{ doc('sales_amount') }}" + tests: + - not_null + - name: TREE_AUTHORITY + description: "{{ doc('tree_authority') }}" + tests: + - not_null + - name: MERKLE_TREE + description: "{{ doc('merkle_tree') }}" + tests: + - not_null + - name: LEAF_INDEX + description: "{{ doc('leaf_index') }}" + tests: + - not_null + - name: MINT + description: "{{ doc('mint') }}" + tests: + - not_null + - name: _INSERTED_TIMESTAMP + description: "{{ doc('_inserted_timestamp') }}" + tests: + - not_null