-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An 5001/update amm sell #616
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
639c100
wip
tarikceric 37f30b4
add relationship test
tarikceric 8be2803
update ref
tarikceric e6193ed
add tests
tarikceric 293cf25
revert
tarikceric 8caefa8
revert
tarikceric 42cc7be
new model; convert old one to view; update gold
tarikceric 5c412b9
add events
tarikceric 6c7aa52
update ME signers filter
tarikceric e949bd8
update relationship test
tarikceric File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
tx_id,purchaser,seller,mint,sales_amount | ||
Ep7n5yUXoBiV6J3ntzvCqaGMS92NbQ9zdqS8ZMJVEwVGhKxsomKzGfsKzyHpzrb9s7ipLH4Cn5P88rneZEcm1Uy,6Y9SASCK9Vsa1T84qb6fY16HwkxmAk3mYyxbKs1UQ5cN,EVszcWthU6JidYCPgYc1y2uqoSajkJ3uepWPcK19336b,BwQKXrxKS9qDSvjmU4ZfFv8YnJM2jYXpSQA4yE6KmV6p,4.403131112 | ||
59fgrVMFqY1scM8gumej3kCq6gzhQauso41QzB9sMx72MdH5dQ76Z7ZHcPM8gWyecCB3mriwbng8uPZ5zEKgmVN1,4GJALHbWj3y1MLGzo6MJz3hJyDwQph3nSgE54f9K9dYC,EvCoDUdLCv8D5CBfQwArvxgr2C8WRBosVDg4ZhxCHEpo,3rRg9RtT64msF5nxSUSdbnVR3mC149mM5jNW9VfZjStW,3.108971958 |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fJWHmWyz2VAUnWeZETYLwYUD1ddc3k,2QufyZxx8vrd8ztiuiM4CSRgVVz7eHCqzA1bav4SbdfL,3.861127675 | ||
5RbhAmdeFoWDtRW4bN5FUXZvin2WMjjnbgfdUVw97QVo6mbowdBozKs2ruhZ5EvpKr2pUjHoTTqJdwGeQL2E2H5F,AGFCb7sETaMhvKuq6j3iiVmRLh7WtryAJFgnDGt6LTgN,ENL47paJQUHhtoyEowYTK1Q7kiNmqV2BkrbZJXBXGQMf,7r7ZQBFTngNKGkL84fQxJt7HCTjzWZGLnDVdcu469CQ3,0.276342858 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
308 changes: 308 additions & 0 deletions
308
models/silver/nfts/silver__nft_sales_amm_sell_decoded.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,308 @@ | ||
-- depends_on: {{ ref('silver__decoded_instructions_combined') }} | ||
{{ config( | ||
materialized = 'incremental', | ||
incremental_predicates = ["dynamic_range_predicate", "block_timestamp::date"], | ||
merge_exclude_columns = ["inserted_timestamp"], | ||
unique_key = "nft_sales_amm_sell_decoded_id", | ||
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'], | ||
tags = ['scheduled_non_core'] | ||
) }} | ||
|
||
{% if execute %} | ||
{% set base_query %} | ||
CREATE OR REPLACE temporary TABLE silver.nft_sales_amm_sell_decoded__intermediate_tmp AS | ||
|
||
SELECT | ||
block_timestamp, | ||
block_id, | ||
tx_id, | ||
succeeded, | ||
signers, | ||
INDEX, | ||
inner_index, | ||
program_id, | ||
event_type, | ||
decoded_instruction, | ||
_inserted_timestamp | ||
FROM | ||
{{ ref('silver__decoded_instructions_combined') }} | ||
WHERE | ||
program_id = 'mmm3XBJg5gk8XJxEKBvdgptZz6SgK4tXvn36sodowMc' | ||
AND event_type IN ( | ||
'solMip1FulfillSell', | ||
'solFulfillSell', | ||
'solFulfillBuy', | ||
'solMip1FulfillBuy', | ||
'solOcpFulfillBuy', | ||
'solExtFulfillBuy', | ||
'solOcpFulfillSell' | ||
) | ||
AND succeeded | ||
|
||
{% if is_incremental() %} | ||
AND _inserted_timestamp >= ( | ||
SELECT | ||
MAX(_inserted_timestamp) - INTERVAL '1 hour' | ||
FROM | ||
{{ this }} | ||
) | ||
{% else %} | ||
AND block_timestamp :: DATE >= '2022-10-30' -- refer to legacy model for sales before this date | ||
{% endif %} | ||
{% endset %} | ||
|
||
{% do run_query(base_query) %} | ||
{% set between_stmts = fsc_utils.dynamic_range_predicate( | ||
"silver.nft_sales_amm_sell_decoded__intermediate_tmp", | ||
"block_timestamp::date" | ||
) %} | ||
{% endif %} | ||
|
||
WITH base_decoded AS ( | ||
SELECT | ||
* | ||
FROM | ||
silver.nft_sales_amm_sell_decoded__intermediate_tmp | ||
), | ||
base_transfers AS ( | ||
SELECT | ||
* | ||
FROM | ||
{{ ref('silver__transfers') }} | ||
WHERE | ||
mint = 'So11111111111111111111111111111111111111111' | ||
AND succeeded | ||
AND {{ between_stmts }} | ||
), | ||
coral_cube_sales AS( | ||
SELECT | ||
block_timestamp, | ||
block_id, | ||
tx_id, | ||
INDEX, | ||
inner_index, | ||
signers, | ||
succeeded, | ||
program_id, | ||
decoded_instruction, | ||
event_type, | ||
CASE | ||
WHEN event_type IN ( | ||
'solFulfillSell', | ||
'solMip1FulfillSell', | ||
'solOcpFulfillSell' | ||
) THEN silver.udf_get_account_pubkey_by_name( | ||
'payer', | ||
decoded_instruction :accounts | ||
) | ||
ELSE silver.udf_get_account_pubkey_by_name( | ||
'pool', | ||
decoded_instruction :accounts | ||
) | ||
END AS purchaser, | ||
CASE | ||
WHEN event_type IN ( | ||
'solFulfillSell', | ||
'solMip1FulfillSell', | ||
'solOcpFulfillSell' | ||
) THEN silver.udf_get_account_pubkey_by_name( | ||
'pool', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The seller is the NFT pool for coral cube? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vice versa for purchaser comment |
||
decoded_instruction :accounts | ||
) | ||
ELSE silver.udf_get_account_pubkey_by_name( | ||
'payer', | ||
decoded_instruction :accounts | ||
) | ||
END AS seller, | ||
CASE | ||
WHEN event_type IN ( | ||
'solFulfillSell', | ||
'solMip1FulfillSell', | ||
'solOcpFulfillSell' | ||
) THEN 'sell' | ||
ELSE 'buy' | ||
END AS nft_sale_type, | ||
'Coral Cube' AS marketplace, | ||
silver.udf_get_account_pubkey_by_name( | ||
'assetMint', | ||
decoded_instruction :accounts | ||
) AS mint, | ||
_inserted_timestamp | ||
FROM | ||
base_decoded | ||
WHERE | ||
signers [1] = '7RpRDUZBdu5hfmqWvobPazbNeVCagRk5E3Rb8Bm8qRmD' | ||
AND purchaser <> '7RpRDUZBdu5hfmqWvobPazbNeVCagRk5E3Rb8Bm8qRmD' | ||
), | ||
mev2_sales AS( | ||
SELECT | ||
block_timestamp, | ||
block_id, | ||
tx_id, | ||
INDEX, | ||
inner_index, | ||
signers, | ||
succeeded, | ||
program_id, | ||
decoded_instruction, | ||
event_type, | ||
CASE | ||
WHEN event_type IN ( | ||
'solMip1FulfillSell', | ||
'solFulfillSell' | ||
) THEN silver.udf_get_account_pubkey_by_name( | ||
'payer', | ||
decoded_instruction :accounts | ||
) | ||
ELSE silver.udf_get_account_pubkey_by_name( | ||
'owner', | ||
decoded_instruction :accounts | ||
) | ||
END AS purchaser, | ||
CASE | ||
WHEN event_type IN ( | ||
'solMip1FulfillSell', | ||
'solFulfillSell' | ||
) THEN silver.udf_get_account_pubkey_by_name( | ||
'owner', | ||
decoded_instruction :accounts | ||
) | ||
ELSE silver.udf_get_account_pubkey_by_name( | ||
'payer', | ||
decoded_instruction :accounts | ||
) | ||
END AS seller, | ||
CASE | ||
WHEN event_type IN ( | ||
'solMip1FulfillSell', | ||
'solFulfillSell' | ||
) THEN 'sell' | ||
ELSE 'buy' | ||
END AS nft_sale_type, | ||
'Magic Eden' AS marketplace, | ||
silver.udf_get_account_pubkey_by_name( | ||
'assetMint', | ||
decoded_instruction :accounts | ||
) AS mint, | ||
_inserted_timestamp | ||
FROM | ||
base_decoded | ||
WHERE | ||
signers [1] = 'NTYeYJ1wr4bpM5xo6zx5En44SvJFAd35zTxxNoERYqd' | ||
), | ||
coral_cube_nft_sale_amount AS ( | ||
SELECT | ||
A.tx_id, | ||
b.mint, | ||
SUM( | ||
b.amount | ||
) AS sales_amount | ||
FROM | ||
coral_cube_sales A | ||
LEFT OUTER JOIN base_transfers b | ||
ON A.tx_id = b.tx_id | ||
WHERE | ||
( | ||
A.nft_sale_type = 'sell' | ||
AND A.purchaser = b.tx_from | ||
) | ||
OR ( | ||
A.nft_sale_type = 'buy' | ||
AND silver.udf_get_account_pubkey_by_name( | ||
'buysideSolEscrowAccount', | ||
A.decoded_instruction :accounts | ||
) :: STRING = b.tx_from | ||
) | ||
GROUP BY | ||
1, | ||
2 | ||
), | ||
mev2_nft_sale_amount AS ( | ||
SELECT | ||
A.tx_id, | ||
b.mint, | ||
SUM( | ||
b.amount | ||
) AS sales_amount | ||
FROM | ||
mev2_sales A | ||
LEFT OUTER JOIN base_transfers b | ||
ON A.tx_id = b.tx_id | ||
WHERE | ||
( | ||
A.nft_sale_type = 'sell' | ||
AND A.purchaser = b.tx_from | ||
) | ||
OR ( | ||
A.nft_sale_type = 'buy' | ||
AND silver.udf_get_account_pubkey_by_name( | ||
'buysideSolEscrowAccount', | ||
A.decoded_instruction :accounts | ||
) :: STRING = b.tx_from | ||
) | ||
GROUP BY | ||
1, | ||
2 | ||
), | ||
pre_final AS ( | ||
SELECT | ||
A.block_timestamp, | ||
A.block_id, | ||
A.tx_id, | ||
A.succeeded, | ||
A.index, | ||
A.inner_index, | ||
A.program_id, | ||
A.mint, | ||
A.purchaser, | ||
A.seller, | ||
b.sales_amount, | ||
A.marketplace, | ||
A._inserted_timestamp | ||
FROM | ||
coral_cube_sales A | ||
LEFT JOIN coral_cube_nft_sale_amount b | ||
ON A.tx_id = b.tx_id | ||
WHERE | ||
b.sales_amount IS NOT NULL | ||
UNION | ||
SELECT | ||
A.block_timestamp, | ||
A.block_id, | ||
A.tx_id, | ||
A.succeeded, | ||
A.index, | ||
A.inner_index, | ||
A.program_id, | ||
A.mint, | ||
A.purchaser, | ||
A.seller, | ||
b.sales_amount, | ||
A.marketplace, | ||
A._inserted_timestamp | ||
FROM | ||
mev2_sales A | ||
LEFT JOIN mev2_nft_sale_amount b | ||
ON A.tx_id = b.tx_id | ||
) | ||
SELECT | ||
block_timestamp, | ||
block_id, | ||
tx_id, | ||
succeeded, | ||
index, | ||
inner_index, | ||
program_id, | ||
mint, | ||
purchaser, | ||
seller, | ||
sales_amount, | ||
marketplace, | ||
_inserted_timestamp, | ||
{{ dbt_utils.generate_surrogate_key(['tx_id','mint']) }} AS nft_sales_amm_sell_decoded_id, | ||
SYSDATE() AS inserted_timestamp, | ||
SYSDATE() AS modified_timestamp, | ||
'{{ invocation_id }}' AS _invocation_id | ||
FROM | ||
pre_final | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purchaser is the NFT pool for coral cube?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in these instances the 'pool' address is what recieves the NFT and has ownership, and also what sends payment so we ID that as technically the purchaser.