-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac97a0a
commit 0a9c9b5
Showing
7 changed files
with
140 additions
and
2 deletions.
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
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
92 changes: 92 additions & 0 deletions
92
nft/models/_sector/trades/chains/avalanche_c/platforms/salvor_avalanche_c_base_trades.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,92 @@ | ||
{{ config( | ||
schema='salvor_avalanche_c', | ||
alias = 'base_trades', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['block_number','tx_hash','sub_tx_trade_id'] | ||
)}} | ||
|
||
{% set project_start_date = '2023-09-01' %} | ||
|
||
WITH | ||
|
||
events as ( | ||
SELECT | ||
evt_block_time, | ||
tokenId as nft_token_id, | ||
UINT256 '1' as nft_amount, | ||
'Trade' as trade_category, | ||
buyer, | ||
bid as price_raw, | ||
0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7 as currency_contract, | ||
collection as nft_contract_address, | ||
evt_tx_hash, | ||
contract_address, | ||
evt_block_number, | ||
evt_index | ||
FROM | ||
{{ source('salvor_avalanche_c', 'Marketplace_evt_AcceptCollectionOffer') }} | ||
{% if is_incremental() %} | ||
WHERE {{incremental_predicate('evt_block_time')}} | ||
{% endif %} | ||
), | ||
|
||
royalty_payment as ( | ||
SELECT | ||
evt_tx_hash, | ||
collection, | ||
tokenId, | ||
SUM(amount) as amount, | ||
MIN_BY(royaltyReceiver, evt_index) as royaltyRecipient, | ||
MIN_BY(_seller, evt_index) as seller, | ||
COUNT(*) as number_of_payments -- when there are multiple payments, the royalty_fee_address & seller is null | ||
FROM | ||
{{ source('salvor_avalanche_c', 'PaymentManager_evt_RoyaltyReceived') }} | ||
{% if is_incremental() %} | ||
WHERE {{incremental_predicate('evt_block_time')}} | ||
{% endif %} | ||
GROUP BY 1, 2, 3 | ||
), | ||
|
||
base_trades as ( | ||
SELECT | ||
'avalanche_c' as blockchain, | ||
'salvor' as project, | ||
'v1' as project_version, | ||
ee.evt_block_time as block_time, | ||
date_trunc('day',ee.evt_block_time) as block_date, | ||
date_trunc('month',ee.evt_block_time) as block_month, | ||
ee.nft_token_id, | ||
'secondary' as trade_type, | ||
ee.nft_amount, | ||
ee.trade_category, | ||
CASE | ||
WHEN number_of_payments = 1 THEN seller | ||
ELSE CAST(NULL as VARBINARY) | ||
END as seller, | ||
ee.buyer, | ||
ee.price_raw, | ||
ee.currency_contract, | ||
ee.nft_contract_address, | ||
ee.evt_tx_hash as tx_hash, | ||
ee.contract_address as project_contract_address, | ||
ee.evt_block_number as block_number, | ||
CAST(NULL as UINT256) as platform_fee_amount_raw, | ||
ra.amount as royalty_fee_amount_raw, | ||
CASE | ||
WHEN number_of_payments = 1 THEN royaltyRecipient | ||
ELSE CAST(NULL as VARBINARY) | ||
END as royalty_fee_address, | ||
CAST(NULL as VARBINARY) as platform_fee_address, | ||
ee.evt_index as sub_tx_trade_id | ||
FROM | ||
events ee | ||
LEFT JOIN | ||
royalty_payment ra | ||
ON ee.evt_tx_hash = ra.evt_tx_hash | ||
AND ee.nft_contract_address = ra.collection | ||
AND ee.nft_token_id = ra.tokenId | ||
) | ||
|
||
{{add_nft_tx_data('base_trades','avalanche_c')}} |
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
3 changes: 3 additions & 0 deletions
3
nft/seeds/trades/base_trades/salvor_avalanche_c_base_trades_seed.csv
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,3 @@ | ||
block_number,tx_hash,sub_tx_trade_id,buyer,seller,nft_contract_address,nft_token_id,price_raw,royalty_fee_amount_raw | ||
43243959,0xa278c982cf657e5c0198b5f463213267c3fc460a7fb144ae691271b1c87f7d45,12,0xa01c2eda113867352a5e30b3c052810478eff526,0x4f765b9fcd43712404dc32cee0bd4cadf073cc05,0x465e9486bd69155c91ba12fe56f679808e360302,2,650000000000000000,32500000000000000 | ||
43241144,0xc0583dd9ad6379b8975077e4b7bc23522a5b127a65069b981075390e24dd4d21,8,0x11c91012cfd0bfbae673f1fcf39b10b1c05b2201,0x8a7190b2db6fe5e6551180ddec53ae138bb401bc,0x956062f3299adeb15a8676426542e1f0c0e7ca09,0,51000000000000000,5100000000000000 |
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