-
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.
* Restructure Cryptopunks to new NFT trades setup (#3286) * cryptopunks restructuring * add to trades_beta * fix join logic * fix call reference * fix bid pricing * fix bid buyer * syntax * fix * allow 0.1% error and fix seed value * Restructure Sudoswap to new NFT trades setup (#3329) * sudoswap restructuring * syntax fix * add seed test * Restructure collectionswap to new NFT trades setup (#3330) * restructure collectionswap * syntax fix * bugfix * use price_raw * add test seed * check-seed * Restructure looksrare to new NFT trades setup (#3332) * restructure looksrare * bugfix * bugfix * bugfix * add seed tests * fix seed * seed schema * cleanup * lr seed schema * NFT trades backwards compatibility layer (#3350) * compatibility layer * typo * test passes with no results * fix setup * fix * add fee percentages * nest test * move from string to varchar * allow the ignore of 1 punk sale in the rowcount test * allow the ignore of 1 punk sale in the rowcount test * allow the ignore of 1 punk sale in the rowcount test
- Loading branch information
Showing
21 changed files
with
1,017 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{% macro port_to_old_schema(model) %} | ||
|
||
SELECT | ||
blockchain, | ||
project, | ||
project_version as version, | ||
block_date, | ||
block_time, | ||
nft_token_id as token_id, | ||
nft_collection as collection, | ||
price_usd as amount_usd, | ||
nft_standard as token_standard, | ||
trade_type, | ||
nft_amount as number_of_items, | ||
trade_category, | ||
'Trade' as evt_type, | ||
seller, | ||
buyer, | ||
price as amount_original, | ||
price_raw as amount_raw, | ||
currency_symbol, | ||
currency_contract, | ||
nft_contract_address, | ||
project_contract_address, | ||
aggregator_name, | ||
aggregator_address, | ||
tx_hash, | ||
block_number, | ||
tx_from, | ||
tx_to, | ||
platform_fee_amount_raw, | ||
platform_fee_amount, | ||
platform_fee_amount_usd, | ||
platform_fee_percentage, | ||
royalty_fee_address as royalty_fee_receive_address, | ||
currency_symbol as royalty_fee_currency_symbol, | ||
royalty_fee_amount_raw, | ||
royalty_fee_amount, | ||
royalty_fee_amount_usd, | ||
royalty_fee_percentage, | ||
concat(cast(block_number as varchar(10)),'-',cast(tx_hash as varchar(42)),'-',cast(sub_tx_trade_id as varchar(10))) as unique_trade_id | ||
FROM {{ model }} | ||
|
||
{% endmacro %} |
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
115 changes: 115 additions & 0 deletions
115
models/_sector/nft/trades/ethereum/platforms/collectionswap_ethereum_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,115 @@ | ||
{{ config( | ||
schema = 'collectionswap_ethereum', | ||
alias ='base_trades', | ||
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 = '2023-03-29' %} | ||
|
||
WITH | ||
raw_trades as ( | ||
select * | ||
, row_number() over (partition by tx_hash order by evt_index asc, sub_order_id asc) as sub_tx_trade_id | ||
from( | ||
select | ||
block_number, block_time, evt_index, tx_hash, buyer, seller, | ||
posexplode(nft_id_array) as (sub_order_id, nft_token_id), | ||
cast(1 as int) as nft_amount, | ||
price_raw/number_of_items as price_raw, | ||
platform_fee_amount_raw/number_of_items as platform_fee_amount_raw, | ||
royalty_fee_amount_raw/number_of_items as royalty_fee_amount_raw, | ||
trade_fee_amount_raw/number_of_items as trade_fee_amount_raw, | ||
royalty_fee_address, | ||
project_contract_address, | ||
number_of_items, | ||
'secondary' as trade_type, | ||
trade_category | ||
from( | ||
select | ||
evt_block_number as block_number | ||
,evt_block_time as block_time | ||
,evt_index | ||
,evt_tx_hash as tx_hash | ||
,null as buyer | ||
,contract_address as seller | ||
,'Buy' as trade_category | ||
,nftIds as nft_id_array | ||
,cardinality(nftIds) as number_of_items | ||
,cast(outputAmount as decimal(38)) as price_raw | ||
,cast(protocolFee as decimal(38)) as platform_fee_amount_raw | ||
,get_json_object(royaltyDue[0], '$.amount') as royalty_fee_amount_raw | ||
,get_json_object(royaltyDue[0], '$.recipient') as royalty_fee_address | ||
,cast(tradeFee as decimal(38)) as trade_fee_amount_raw | ||
,contract_address as project_contract_address | ||
from {{ source('collectionswap_ethereum','CollectionPool_evt_SwapNFTOutPool') }} e | ||
{% if is_incremental() %} | ||
WHERE evt_block_time >= date_trunc("day", now() - interval '1 week') | ||
{% else %} | ||
WHERE evt_block_time >= '{{project_start_date}}' | ||
{% endif %} | ||
union all | ||
select | ||
evt_block_number as block_number | ||
,evt_block_time as block_time | ||
,evt_index | ||
,evt_tx_hash as tx_hash | ||
,contract_address as buyer | ||
,null as seller | ||
,'Sell' as trade_category | ||
,nftIds as nft_id_array | ||
,cardinality(nftIds) as number_of_items | ||
,cast(inputAmount + protocolFee + cast(get_json_object(royaltyDue[0], '$.amount') as decimal(38)) as decimal(38)) as price_raw | ||
,cast(protocolFee as decimal(38)) as platform_fee_amount_raw | ||
,get_json_object(royaltyDue[0], '$.amount') as royalty_fee_amount_raw | ||
,get_json_object(royaltyDue[0], '$.recipient') as royalty_fee_address | ||
,cast(tradeFee as decimal(38)) as trade_fee_amount_raw | ||
,contract_address as project_contract_address | ||
from {{ source('collectionswap_ethereum','CollectionPool_evt_SwapNFTInPool') }} e | ||
{% if is_incremental() %} | ||
WHERE evt_block_time >= date_trunc("day", now() - interval '1 week') | ||
{% else %} | ||
WHERE evt_block_time >= '{{project_start_date}}' | ||
{% endif %} | ||
) | ||
) | ||
), | ||
|
||
base_trades as ( | ||
select | ||
t.*, | ||
p.nft_contract_address, | ||
p.token_address as currency_contract | ||
from raw_trades t | ||
left join {{ ref('collectionswap_ethereum_pools') }} p | ||
on t.project_contract_address = p.pool_address | ||
) | ||
|
||
-- results | ||
SELECT | ||
date_trunc('day',block_time ) as block_date | ||
, block_time | ||
, block_number | ||
, tx_hash | ||
, project_contract_address | ||
, buyer | ||
, seller | ||
, nft_contract_address | ||
, nft_token_id | ||
, nft_amount | ||
, trade_type | ||
, trade_category | ||
, currency_contract | ||
, cast(price_raw as decimal(38)) as price_raw | ||
, cast(platform_fee_amount_raw as decimal(38)) as platform_fee_amount_raw | ||
, cast(royalty_fee_amount_raw as decimal(38)) as royalty_fee_amount_raw | ||
, cast(null as varchar(1)) as platform_fee_address | ||
, royalty_fee_address | ||
, sub_tx_trade_id | ||
FROM base_trades | ||
|
||
|
Oops, something went wrong.