-
Notifications
You must be signed in to change notification settings - Fork 1.3k
migrate foundation_ethereum_base_trades #3664
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8badbd3
migrate foundation_ethereum_base_trades
0xRobin 58ad9ac
Merge branch 'main' into migrate-foundation
0xRobin 8b57e37
Merge branch 'main' into migrate-foundation
0xRobin 438181c
migrate foundation seed test
0xRobin f8aee4b
fix check_seed_macro
0xRobin 15291d3
tag test with sources as dunesql
0xRobin 7fc42f4
exclusion tag in git CI seed step
0xRobin f214cb5
try different approach for sources
0xRobin 9d5375a
typo
0xRobin 798c367
Update macros/dune/source.sql
0xRobin 9c4cb91
Merge branch 'main' into migrate-foundation
jeff-dude 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 hidden or 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 hidden or 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
124 changes: 124 additions & 0 deletions
124
models/_sector/nft/trades/ethereum/platforms/foundation_ethereum_base_trades_legacy.sql
This file contains hidden or 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,124 @@ | ||
{{ config( | ||
schema = 'foundation_ethereum', | ||
alias = alias('base_trades', legacy_model=True), | ||
partition_by = ['block_date'], | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['block_number','tx_hash','sub_tx_trade_id'], | ||
) | ||
}} | ||
{% set project_start_date='2021-2-04' %} | ||
|
||
WITH all_foundation_trades AS ( | ||
SELECT | ||
f.evt_block_time AS block_time | ||
, f.evt_block_number AS block_number | ||
, c.tokenId AS nft_token_id | ||
, 'Auction Settled' AS trade_category | ||
, case when (f.sellerRev = 0 and cast(f.creatorRev as decimal(38)) > 0 ) then 'primary' else 'secondary' end as trade_type | ||
, f.seller | ||
, f.bidder AS buyer | ||
, f.creatorRev+f.totalFees+f.sellerRev AS price_raw | ||
, f.contract_address AS project_contract_address | ||
, c.nftContract AS nft_contract_address | ||
, f.evt_tx_hash AS tx_hash | ||
, f.totalFees AS platform_fee_amount_raw | ||
, case when (f.sellerRev = 0 and cast(f.creatorRev as decimal(38)) > 0 ) then 0 else f.creatorRev end AS royalty_fee_amount_raw | ||
, f.evt_index as sub_tx_trade_id | ||
FROM {{ source('foundation_ethereum','market_evt_ReserveAuctionFinalized') }} f | ||
INNER JOIN {{ source('foundation_ethereum','market_evt_ReserveAuctionCreated') }} c ON c.auctionId=f.auctionId AND c.evt_block_time<=f.evt_block_time | ||
{% if is_incremental() %} -- this filter will only be applied on an incremental run | ||
WHERE f.evt_block_time >= date_trunc("day", now() - interval '1 week') | ||
{% else %} | ||
WHERE f.evt_block_time >= '{{project_start_date}}' | ||
{% endif %} | ||
UNION ALL | ||
SELECT | ||
evt_block_time AS block_time | ||
, evt_block_number AS block_number | ||
, tokenId AS nft_token_id | ||
, 'Buy' AS trade_category | ||
, case when (sellerRev = 0 and cast(creatorRev as decimal(38)) > 0 ) then 'primary' else 'secondary' end as trade_type | ||
, seller | ||
, buyer | ||
, creatorRev+totalFees+sellerRev AS price_raw | ||
, contract_address AS project_contract_address | ||
, nftContract AS nft_contract_address | ||
, evt_tx_hash AS tx_hash | ||
, totalFees AS platform_fee_amount_raw | ||
, case when (sellerRev = 0 and cast(creatorRev as decimal(38)) > 0 ) then 0 else creatorRev end AS royalty_fee_amount_raw | ||
, evt_index as sub_tx_trade_id | ||
FROM {{ source('foundation_ethereum','market_evt_BuyPriceAccepted') }} f | ||
{% if is_incremental() %} -- this filter will only be applied on an incremental run | ||
WHERE f.evt_block_time >= date_trunc("day", now() - interval '1 week') | ||
{% else %} | ||
WHERE f.evt_block_time >= '{{project_start_date}}' | ||
{% endif %} | ||
UNION ALL | ||
SELECT | ||
evt_block_time AS block_time | ||
, evt_block_number AS block_number | ||
, tokenId AS nft_token_id | ||
, 'Sell' AS trade_category | ||
, case when (sellerRev = 0 and cast(creatorRev as decimal(38)) > 0 ) then 'primary' else 'secondary' end as trade_type | ||
, seller | ||
, buyer | ||
, creatorRev+totalFees+sellerRev AS price_raw | ||
, contract_address AS project_contract_address | ||
, nftContract AS nft_contract_address | ||
, evt_tx_hash AS tx_hash | ||
, totalFees AS platform_fee_amount_raw | ||
, case when (sellerRev = 0 and cast(creatorRev as decimal(38)) > 0 ) then 0 else creatorRev end AS royalty_fee_amount_raw | ||
, evt_index as sub_tx_trade_id | ||
FROM {{ source('foundation_ethereum','market_evt_OfferAccepted') }} f | ||
{% if is_incremental() %} -- this filter will only be applied on an incremental run | ||
WHERE f.evt_block_time >= date_trunc("day", now() - interval '1 week') | ||
{% else %} | ||
WHERE f.evt_block_time >= '{{project_start_date}}' | ||
{% endif %} | ||
UNION ALL | ||
SELECT | ||
evt_block_time AS block_time | ||
, evt_block_number AS block_number | ||
, tokenId AS nft_token_id | ||
, 'Private Sale' AS trade_category | ||
, case when (sellerRev = 0 and cast(creatorFee as decimal(38)) > 0 ) then 'primary' else 'secondary' end as trade_type | ||
, seller | ||
, buyer | ||
, creatorFee+protocolFee+sellerRev AS price_raw | ||
, contract_address AS project_contract_address | ||
, nftContract AS nft_contract_address | ||
, evt_tx_hash AS tx_hash | ||
, protocolFee AS platform_fee_amount_raw | ||
, case when (sellerRev = 0 and cast(creatorFee as decimal(38)) > 0 ) then 0 else creatorFee end AS royalty_fee_amount_raw | ||
, evt_index as sub_tx_trade_id | ||
FROM {{ source('foundation_ethereum','market_evt_PrivateSaleFinalized') }} f | ||
{% if is_incremental() %} -- this filter will only be applied on an incremental run | ||
WHERE f.evt_block_time >= date_trunc("day", now() - interval '1 week') | ||
{% else %} | ||
WHERE f.evt_block_time >= '{{project_start_date}}' | ||
{% endif %} | ||
) | ||
|
||
SELECT | ||
date_trunc('day', t.block_time) AS block_date | ||
, t.block_time | ||
, t.block_number | ||
, t.nft_token_id | ||
, 1 AS nft_amount | ||
, t.trade_category | ||
, t.trade_type | ||
, t.seller | ||
, t.buyer | ||
, cast(t.price_raw as decimal(38)) as price_raw | ||
, '{{ var("ETH_ERC20_ADDRESS") }}' AS currency_contract -- all trades are in ETH | ||
, t.project_contract_address | ||
, t.nft_contract_address | ||
, t.tx_hash | ||
, cast(t.platform_fee_amount_raw as decimal(38)) as platform_fee_amount_raw | ||
, cast(t.royalty_fee_amount_raw as decimal(38)) as royalty_fee_amount_raw | ||
, cast(NULL as string) AS royalty_fee_address | ||
, cast(NULL as string) AS platform_fee_address | ||
, t.sub_tx_trade_id | ||
FROM all_foundation_trades t |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.