From c0d866b4fdd408d6ceebf3ab4505192fa7a077d3 Mon Sep 17 00:00:00 2001 From: desmond-hui <97470747+desmond-hui@users.noreply.github.com> Date: Wed, 8 May 2024 09:01:42 -0700 Subject: [PATCH] An 4800/tensorswap refactor (#553) * (wip) initial model * remove testing lines, add depends on comment * handle more than one sale per tx * separate sol escrow from margin account * use min_price as sale price for bid sales * fix column name * add model docs and tests * add caveat for tensorswap sales amount description * add business logic tests --- data/testing__nft_sales_tensorswap.csv | 19 + models/descriptions/_invocation_id.md | 5 + .../nfts/silver__nft_sales_tensorswap.sql | 426 ++++++++++-------- .../nfts/silver__nft_sales_tensorswap.yml | 63 ++- .../silver__decoded_instructions_combined.yml | 23 + 5 files changed, 351 insertions(+), 185 deletions(-) create mode 100644 data/testing__nft_sales_tensorswap.csv create mode 100644 models/descriptions/_invocation_id.md diff --git a/data/testing__nft_sales_tensorswap.csv b/data/testing__nft_sales_tensorswap.csv new file mode 100644 index 000000000..b79611f72 --- /dev/null +++ b/data/testing__nft_sales_tensorswap.csv @@ -0,0 +1,19 @@ +tx_id,index,inner_index,purchaser,seller,mint,sales_amount +zzvAhzMxDpJy99zcYms6vsjimT3XhQBf76s9AYA4XcYaEgRS2EmMDHY9uHrfz7372v85726Krz3kaKfYmLgnMFz,2,,HEsoAeQ6jgwiyPCL7A9mBjMf34qVAF96KYPNdxE68iY6,2w4HeHXEEVrpqpKUTZqVSCzCR5uWKK88pNY9pfqSW59R,BBMQUm1domLQUZr4gUm9Pd6EGLnuUu9hPX7bpD5dpqMT,0.468830396 +4KnHxNCwtbvdnUP9xP6aUAGpEVVgZqVnGP8FzJAz3ghPhnSgUvm8DPVdwm5tE9d78ScBxFQNqzRotW5mr2bYL9P5,2,,2zzPrvMe843AJ15jwppiA25XRXXgM4ajH9ZnVLtPmvPb,8FQ73HFaXurdDEUC4UpTJw99hvpaCJUHiqaQwBGgujiD,AnBW1sLFStkdHXpyJAH49Gu2t4y4rRhDnEKcEAcps28W,0.852 +2nrF2VH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aBcXVrwUR9N9toMaCD,2.831451429 +5Ndp4DwJvVxiF6cEVtHvnzW749hjqKFdwYVYS4Bn2GHtc3qPGsk9AuowBhamqDkJaXNgiC3CaSDMK4k2a2pEchzJ,2,,AQYyCfb358cokJks8GBYrRhCE2smJNEFsj38V9N4y54R,FgVYBs7Qag74oSNgFozGH2zCXeWZKyff6KNyQBGVZsF2,2pE7mPLe1Fi1eM4MMSYByVEqcBnBEW3AvUqZu5rozpTZ,0.723530448 +5Ndp4DwJvVxiF6cEVtHvnzW749hjqKFdwYVYS4Bn2GHtc3qPGsk9AuowBhamqDkJaXNgiC3CaSDMK4k2a2pEchzJ,3,,FgVYBs7Qag74oSNgFozGH2zCXeWZKyff6KNyQBGVZsF2,AQYyCfb358cokJks8GBYrRhCE2smJNEFsj38V9N4y54R,AMZJ5CaFHPeL3V1poFt14GvZwisJk7x7aRN69C3DNcRD,0.666161076 \ No newline at end of file diff --git a/models/descriptions/_invocation_id.md b/models/descriptions/_invocation_id.md new file mode 100644 index 000000000..7cfbcb5a5 --- /dev/null +++ b/models/descriptions/_invocation_id.md @@ -0,0 +1,5 @@ +{% docs _invocation_id %} + +Unique identifier for DBT job run that inserted/modified this record + +{% enddocs %} \ No newline at end of file diff --git a/models/silver/nfts/silver__nft_sales_tensorswap.sql b/models/silver/nfts/silver__nft_sales_tensorswap.sql index 48cb5b397..bb0d6878c 100644 --- a/models/silver/nfts/silver__nft_sales_tensorswap.sql +++ b/models/silver/nfts/silver__nft_sales_tensorswap.sql @@ -1,194 +1,266 @@ +-- depends_on: {{ ref('silver__decoded_instructions_combined') }} + {{ config( materialized = 'incremental', - unique_key = "CONCAT_WS('-', tx_id, mint, purchaser)", - incremental_strategy = 'delete+insert', - cluster_by = ['block_timestamp::DATE'], + incremental_predicates = ["dynamic_range_predicate", "block_timestamp::date"], + merge_exclude_columns = ["inserted_timestamp"], + unique_key = "nft_sales_tensorswap_id", + cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'], tags = ['scheduled_non_core'] ) }} -with pre_final as ( -SELECT - block_id, - block_timestamp, - tx_id, - succeeded, - i.value:programId :: STRING AS program_id, - i.value:accounts[4] :: STRING AS mint, - i.value:accounts[8] :: STRING AS purchaser, - i.value:accounts[7] :: STRING AS seller, - MAX(ABS(post_balances[keys.index] - pre_balances[keys.index]) / POWER(10,9)) AS sales_amount, - _inserted_timestamp -FROM - {{ ref('silver__transactions') }} -INNER JOIN lateral flatten (input => instructions) i -INNER JOIN lateral flatten (input => account_keys) keys -WHERE - array_contains('Program log: Instruction: BuySingleListing'::VARIANT, log_messages) - AND i.value:programId = 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN' - AND i.value:accounts[8] = signers[0] - {% if is_incremental() %} - AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - FROM - {{ this }} - ) - {% else %} - AND block_timestamp :: date >= '2022-09-22' - {% endif %} -GROUP BY - block_id, - block_timestamp, - tx_id, - succeeded, - i.value, - i.value:accounts[8], - i.value:accounts[7], - i.value:accounts[4], - _inserted_timestamp -UNION +{% if execute %} + {% set base_query %} + CREATE OR REPLACE temporary TABLE silver.nft_sales_tensorswap__intermediate_tmp AS + SELECT + block_timestamp, + block_id, + tx_id, + succeeded, + INDEX, + inner_index, + program_id, + event_type, + decoded_instruction, + _inserted_timestamp + FROM + {{ ref('silver__decoded_instructions_combined') }} + WHERE + program_id = 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN' + AND event_type IN ( + 'wnsBuySingleListing', + 'buyNftT22', + 'buySingleListing', + 'buyNft', + 'buySingleListingT22', + 'wnsBuyNft', + 'sellNftTokenPool', + 'sellNftTokenPoolT22', + 'sellNftTradePoolT22', + 'wnsSellNftTradePool', + 'wnsSellNftTokenPool', + 'sellNftTradePool' + ) + AND succeeded -SELECT - block_id, - block_timestamp, - tx_id, - succeeded, - i.value:programId :: STRING AS program_id, - i.value:accounts[5] :: STRING AS mint, - i.value:accounts[11] :: STRING AS purchaser, - i.value:accounts[10] :: STRING AS seller, - MAX(ABS(post_balances[keys.index] - pre_balances[keys.index]) / POWER(10,9)) AS sales_amount, - _inserted_timestamp -FROM - {{ ref('silver__transactions') }} -INNER JOIN lateral flatten (input => instructions) i -INNER JOIN lateral flatten (input => account_keys) keys -WHERE - array_contains('Program log: Instruction: BuyNft'::VARIANT, log_messages) - AND i.value:programId = 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN' - AND i.value:accounts[11] = signers[0] {% if is_incremental() %} - AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - FROM - {{ this }} - ) + AND _inserted_timestamp >= ( + SELECT + MAX(_inserted_timestamp) - INTERVAL '1 hour' + FROM + {{ this }} + ) {% else %} - AND block_timestamp :: date >= '2022-09-22' + AND _inserted_timestamp :: DATE >= '2023-11-15' {% endif %} -GROUP BY - block_id, - block_timestamp, - tx_id, - succeeded, - i.value, - i.value:accounts[11], - i.value:accounts[10], - i.value:accounts[5], - _inserted_timestamp +{% endset %} -UNION +{% do run_query(base_query) %} +{% set between_stmts = fsc_utils.dynamic_range_predicate( + "silver.nft_sales_tensorswap__intermediate_tmp", + "block_timestamp::date" +) %} +{% endif %} -SELECT - block_id, - block_timestamp, - tx_id, - succeeded, - i.value:programId :: STRING AS program_id, - i.value:accounts[6] :: STRING AS mint, - i.value:accounts[9] :: STRING AS purchaser, - i.value:accounts[10] :: STRING AS seller, - MAX(ABS(post_balances[keys.index] - pre_balances[keys.index]) / POWER(10,9)) AS sales_amount, - _inserted_timestamp -FROM - {{ ref('silver__transactions') }} -INNER JOIN lateral flatten (input => instructions) i -INNER JOIN lateral flatten (input => account_keys) keys -WHERE - array_contains('Program log: Instruction: SellNftTokenPool'::VARIANT, log_messages) - AND i.value:programId = 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN' - AND i.value:accounts[10] = signers[0] - {% if is_incremental() %} - AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - FROM - {{ this }} - ) - {% else %} - AND block_timestamp :: date >= '2022-09-22' - {% endif %} -GROUP BY - block_id, - block_timestamp, - tx_id, - succeeded, - i.value, - i.value:accounts[9], - i.value:accounts[10], - i.value:accounts[6], - _inserted_timestamp - -UNION +WITH decoded AS ( + SELECT + block_timestamp, + block_id, + tx_id, + succeeded, + INDEX, + inner_index, + program_id, + event_type, + CASE + WHEN event_type IN ( + 'wnsBuySingleListing', + 'buyNftT22', + 'buySingleListing', + 'buyNft', + 'buySingleListingT22', + 'wnsBuyNft' + ) THEN silver.udf_get_account_pubkey_by_name( + 'buyer', + decoded_instruction :accounts + ) + WHEN event_type IN ( + 'sellNftTokenPool', + 'sellNftTokenPoolT22', + 'sellNftTradePoolT22', + 'wnsSellNftTradePool', + 'wnsSellNftTokenPool', + 'sellNftTradePool' + ) THEN silver.udf_get_account_pubkey_by_name( + 'shared > owner', + decoded_instruction :accounts + ) + END AS purchaser, + CASE + WHEN event_type IN ( + 'wnsBuySingleListing', + 'buyNftT22', + 'buySingleListing', + 'buyNft', + 'buySingleListingT22', + 'wnsBuyNft' + ) THEN silver.udf_get_account_pubkey_by_name( + 'owner', + decoded_instruction :accounts + ) + WHEN event_type IN ( + 'sellNftTokenPool', + 'sellNftTokenPoolT22', + 'sellNftTradePoolT22', + 'wnsSellNftTradePool', + 'wnsSellNftTokenPool', + 'sellNftTradePool' + ) THEN silver.udf_get_account_pubkey_by_name( + 'shared > seller', + decoded_instruction :accounts + ) + END AS seller, + CASE + WHEN event_type IN ( + 'wnsBuySingleListing', + 'buyNftT22', + 'buySingleListing', + 'buyNft', + 'buySingleListingT22', + 'wnsBuyNft' + ) THEN silver.udf_get_account_pubkey_by_name( + 'nftMint', + decoded_instruction :accounts + ) + WHEN event_type IN ( + 'sellNftTokenPool', + 'sellNftTokenPoolT22', + 'sellNftTradePoolT22', + 'wnsSellNftTradePool', + 'wnsSellNftTokenPool', + 'sellNftTradePool' + ) THEN silver.udf_get_account_pubkey_by_name( + 'shared > nftMint', + decoded_instruction :accounts + ) + END AS mint, + decoded_instruction:args:minPrice::int * pow(10,-9) AS min_price, + _inserted_timestamp + FROM + silver.nft_sales_tensorswap__intermediate_tmp +), +base_transfers AS ( + SELECT + block_timestamp, + tx_id, + index, + tx_from, + mint, + amount + FROM + {{ ref('silver__transfers') }} t + WHERE + {{ between_stmts }} +), +buys AS ( + SELECT + d.block_timestamp, + d.tx_id, + d.index, + SUM( + t.amount + ) AS sales_amount + FROM + base_transfers t + JOIN decoded d + ON d.block_timestamp :: DATE = t.block_timestamp :: DATE + AND d.tx_id = t.tx_id + AND d.index = SPLIT_PART( + t.index, + '.', + 1 + ) + AND d.purchaser = t.tx_from + WHERE + d.event_type IN ( + 'wnsBuySingleListing', + 'buyNftT22', + 'buySingleListing', + 'buyNft', + 'buySingleListingT22', + 'wnsBuyNft' + ) + AND t.mint = 'So11111111111111111111111111111111111111112' -SELECT - block_id, - block_timestamp, - tx_id, - succeeded, - i.value:programId :: STRING AS program_id, - i.value:accounts[6] :: STRING AS mint, - i.value:accounts[9] :: STRING AS purchaser, - i.value:accounts[10] :: STRING AS seller, - MAX(ABS(post_balances[keys.index] - pre_balances[keys.index]) / POWER(10,9)) AS sales_amount, - _inserted_timestamp -FROM - {{ ref('silver__transactions') }} -INNER JOIN lateral flatten (input => instructions) i -INNER JOIN lateral flatten (input => account_keys) keys -WHERE - array_contains('Program log: Instruction: SellNftTradePool'::VARIANT, log_messages) - AND i.value:programId = 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN' - AND i.value:accounts[10] = signers[0] - {% if is_incremental() %} - AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - FROM - {{ this }} - ) - {% else %} - AND block_timestamp :: date >= '2022-09-22' - {% endif %} -GROUP BY - block_id, - block_timestamp, - tx_id, - succeeded, - i.value, - i.value:accounts[9], - i.value:accounts[10], - i.value:accounts[6], - _inserted_timestamp + GROUP BY + 1,2,3 +), +sells AS ( + SELECT + block_timestamp, + block_id, + tx_id, + succeeded, + index, + inner_index, + program_id, + purchaser, + seller, + mint, + min_price AS sales_amount, + _inserted_timestamp + FROM + decoded + WHERE + event_type IN ( + 'sellNftTokenPool', + 'sellNftTokenPoolT22', + 'sellNftTradePoolT22', + 'wnsSellNftTradePool', + 'wnsSellNftTokenPool', + 'sellNftTradePool' + ) +), +pre_final AS ( + SELECT + block_timestamp, + block_id, + tx_id, + succeeded, + index, + inner_index, + program_id, + purchaser, + seller, + mint, + sales_amount, + _inserted_timestamp, + FROM + sells + UNION ALL + SELECT + d.block_timestamp, + d.block_id, + d.tx_id, + d.succeeded, + d.index, + d.inner_index, + d.program_id, + d.purchaser, + d.seller, + d.mint, + b.sales_amount, + d._inserted_timestamp, + FROM + decoded d + JOIN buys b + USING(block_timestamp, tx_id, index) ) - SELECT - block_id, - block_timestamp, - tx_id, - succeeded, - program_id, - mint, - purchaser, - seller, - sales_amount, - _inserted_timestamp, - {{ dbt_utils.generate_surrogate_key( - ['tx_id','mint','purchaser'] - ) }} AS nft_sales_tensorswap_id, + *, + {{ dbt_utils.generate_surrogate_key(['tx_id','index','inner_index','mint']) }} AS nft_sales_tensorswap_id, SYSDATE() AS inserted_timestamp, SYSDATE() AS modified_timestamp, '{{ invocation_id }}' AS _invocation_id -FROM - pre_final +FROM + pre_final \ No newline at end of file diff --git a/models/silver/nfts/silver__nft_sales_tensorswap.yml b/models/silver/nfts/silver__nft_sales_tensorswap.yml index 8bac21981..0e80c29e5 100644 --- a/models/silver/nfts/silver__nft_sales_tensorswap.yml +++ b/models/silver/nfts/silver__nft_sales_tensorswap.yml @@ -2,12 +2,33 @@ version: 2 models: - name: silver__nft_sales_tensorswap tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - TX_ID - - MINT - - PURCHASER - - SELLER + - compare_model_subset: + name: silver__nft_sales_tensorswap_business_logic_test + compare_model: ref('testing__nft_sales_tensorswap') + compare_columns: + - tx_id + - index + - inner_index + - purchaser + - seller + - mint + - round(sales_amount,8) + model_condition: "where tx_id in ('zzvAhzMxDpJy99zcYms6vsjimT3XhQBf76s9AYA4XcYaEgRS2EmMDHY9uHrfz7372v85726Krz3kaKfYmLgnMFz', + '4KnHxNCwtbvdnUP9xP6aUAGpEVVgZqVnGP8FzJAz3ghPhnSgUvm8DPVdwm5tE9d78ScBxFQNqzRotW5mr2bYL9P5', + '2nrF2VHpLvYQKjtFWqTxoXtHNDEJEH2zi1xYeaDd2FprFYWY7wajcnbnQbPkhqwrhQkiKfYDgKc9mCDgWUzZwvrb', + 'p55mzFVcnhtVCi6sawH2pkSxkJa9SKMJkxn8TWUeE8tKjopo5vJkoh5qrQ9Ew8xN4kJ3YJtbt3uPUaF6wpsgGnZ', + '3xwnYCxCeZNUu9sA1Rfb6HdDc73JqALfWVNgJq2YSwYrz5bxLTiCjiHTzPbuzLTnddojE3fyiRTq5xGhdMmer9wo', + '2TrRP357hzX7Ax1ViTuZFndRRUDMpswKs9dKpFvpu8EcXwH23JQyqXQSvCENX3EqoAcWUV9aFpN3HYHMtvSdEPQG', + 'c5iWkPRG58nw9RRgoe77ewYFRR99NS3XqsBAFurEZ5CUAYefiGMdvvhWLCoyd7Tv1NcCPDsVu3eQVJS9VyjY1Gh', + '2gy21b8QzZ2VXUvd7QCFiELhy7papBqQctHK9XLcvMVeTdJwAZqmmfE6WHQRYQntQmkuzi63b1XYTJf99WnoApDD', + 'svSAsA7hVRshe1qWPaJGD8SptQgZsb38Hn2iKo5W8wk8kp37brEXRkyKUPS34xmJXxRYQDgQhtxUXNCtsKKEwXv', + '4zb3F8A7suKVJc9bi6isX2Y99YemwUSVuALBkjVXAZUaFH6CybycJ6BCqdFe2R4okWo27o3k1h5hJNC9nbCHVQGn', + '3Q9fnZTxhXU8hKt21Q9DawgNAMRbXf5zuatNE8x27vpc2WGZhax8f5ALnZhGDswUHjgTbCNkjBFRQwkHPTfKrcA3', + '3PwcTmfb1jd2d6ouABkvfpw2p261zYyuMrkH9wozL8nKBVnQCBji1WUSy1LfZe4iegiWYiHA5ae3VK3ASbcUDjjo', + '5vsPBQWgtwhqeQQUHVQhuCtWDtAu5sqQak1FkMj7ZkQbMz12m8XrgTQCYtD1paFKh1KqAakpf6hQV4APd94VihLN', + '2munG4m9guSktDAp8QNt3WK1uVVD3BKV5zWqYuApjKjeiLDV9br6QwemQ1UeTHnfeF5CB7axL3K2kFbKUJpCAzHr', + '5PaqpRyNvDjPkRD8UeBKUC8SiwddLLtxZgPuDTngZXCZ2sZ7tDVHoXtqwDWWf9Jq4DVCytobc4o8h1mxNMD8hXzv', + '5Ndp4DwJvVxiF6cEVtHvnzW749hjqKFdwYVYS4Bn2GHtc3qPGsk9AuowBhamqDkJaXNgiC3CaSDMK4k2a2pEchzJ')" columns: - name: BLOCK_TIMESTAMP description: "{{ doc('block_timestamp') }}" @@ -28,6 +49,12 @@ models: description: "{{ doc('tx_succeeded') }}" tests: - not_null + - name: INDEX + description: "{{ doc('event_index') }}" + tests: + - not_null + - name: INNER_INDEX + description: "{{ doc('inner_index') }}" - name: PROGRAM_ID description: "{{ doc('program_id') }}" tests: @@ -46,10 +73,30 @@ models: - not_null: where: succeeded = TRUE - name: SALES_AMOUNT - description: "{{ doc('sales_amount') }}" + description: "{{ doc('sales_amount') }}. For bid side sales the amount is an estimation using `min_price`" tests: - not_null + - dbt_utils.expression_is_true: + expression: ">= 0" - name: _INSERTED_TIMESTAMP description: "{{ doc('_inserted_timestamp') }}" tests: - - not_null \ No newline at end of file + - not_null + - name: NFT_SALES_TENSORSWAP_ID + description: '{{ doc("pk") }}' + tests: + - unique + - name: INSERTED_TIMESTAMP + description: '{{ doc("inserted_timestamp") }}' + tests: + - not_null + - name: MODIFIED_TIMESTAMP + description: '{{ doc("modified_timestamp") }}' + tests: + - not_null + - name: _INVOCATION_ID + description: '{{ doc("_invocation_id") }}' + tests: + - not_null: + name: test_silver__not_null_nft_sales_tensorswap__invocation_id + \ No newline at end of file diff --git a/models/silver/parser/silver__decoded_instructions_combined.yml b/models/silver/parser/silver__decoded_instructions_combined.yml index 30343a7ae..761ac0615 100644 --- a/models/silver/parser/silver__decoded_instructions_combined.yml +++ b/models/silver/parser/silver__decoded_instructions_combined.yml @@ -71,6 +71,29 @@ models: and _inserted_timestamp between current_date - 7 and current_timestamp() - INTERVAL '4 HOUR' and block_timestamp::date <> '2022-07-04' /* upstream issue with missing inner instructions in events for some blocks in this date, remove this when it gets resolved */ to_condition: "_inserted_timestamp >= current_date - 7" + - dbt_utils.relationships_where: + name: dbt_utils_relationships_where_silver__decoded_instructions_combined_nft_sales_tensorswap_tx_id + to: ref('silver__nft_sales_tensorswap') + field: tx_id + from_condition: > + program_id = 'TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN' + AND event_type IN ( + 'wnsBuySingleListing', + 'buyNftT22', + 'buySingleListing', + 'buyNft', + 'buySingleListingT22', + 'wnsBuyNft', + 'sellNftTokenPool', + 'sellNftTokenPoolT22', + 'sellNftTradePoolT22', + 'wnsSellNftTradePool', + 'wnsSellNftTokenPool', + 'sellNftTradePool' + ) + AND succeeded + AND _inserted_timestamp between current_date - 7 AND current_timestamp() - INTERVAL '4 HOUR' + to_condition: "_inserted_timestamp >= current_date - 7" - name: SIGNERS - name: SUCCEEDED - name: INDEX