Skip to content

Commit

Permalink
Arbitrum Nova nft.trades (duneanalytics#6559)
Browse files Browse the repository at this point in the history
* nova nft trades

* add source()

* add royalty and platform fee address

* add sub_tx_trade_id

* add tx_from and tx_to

* array index

* array index

* fix type

* fix incremental
  • Loading branch information
0xRobin authored Aug 14, 2024
1 parent a976ac8 commit 3acb6dd
Show file tree
Hide file tree
Showing 18 changed files with 271 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{{ config(
schema = 'nft_nova',
alias = 'base_trades',
materialized = 'view'
)
}}


{% set nft_models = [
ref('king_of_destiny_nova_base_trades')
,ref('opensea_v3_nova_base_trades')
,ref('opensea_v4_nova_base_trades')
] %}

with base_union as (
SELECT * FROM (
{% for nft_model in nft_models %}
SELECT
blockchain,
project,
project_version,
cast(date_trunc('day', block_time) as date) as block_date,
cast(date_trunc('month', block_time) as date) as block_month,
block_time,
block_number,
tx_hash,
project_contract_address,
trade_category, --buy/sell/swap
trade_type, --primary/secondary
buyer,
seller,
nft_contract_address,
nft_token_id,
nft_amount, -- always 1 for erc721
price_raw,
currency_contract,
platform_fee_amount_raw,
royalty_fee_amount_raw,
platform_fee_address, -- optional
royalty_fee_address, -- optional
sub_tx_trade_id,
-- tx_from,
-- tx_to,
row_number() over (partition by tx_hash, sub_tx_trade_id order by tx_hash) as duplicates_rank -- duplicates protection
FROM {{ nft_model }}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
)
where duplicates_rank = 1
)

-- this will be removed once tx_from and tx_to are available in the base event tables
{{ add_nft_tx_data('base_union', 'nova') }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: 2

models:
- name: king_of_destiny_nova_base_trades
meta:
blockchain: nova
sector: nft
project: king_of_destiny
contributors: ['0xRob' ]
config:
tags: [ 'nova', 'nft', 'trades', 'king_of_destiny' ]
description: "king_of_destiny base trades"
tests:
- check_columns_nft_base_trades
- dbt_utils.unique_combination_of_columns:
combination_of_columns: [ 'block_number','tx_hash','sub_tx_trade_id' ]

- name: opensea_v3_nova_base_trades
meta:
blockchain: nova
project: opensea
contributors: sohwak, 0xRob
config:
tags: [ 'opensea','base_trades','seaport' ]
description: >
Opensea base trades from seaport (v3)
tests:
- check_columns_nft_base_trades
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_number
- tx_hash
- sub_tx_trade_id

- name: opensea_v4_nova_base_trades
meta:
blockchain: nova
project: opensea
contributors: sohwak, 0xRob
config:
tags: [ 'opensea','base_trades','seaport' ]
description: >
Opensea base trades from seaport (v4)
tests:
- check_columns_nft_base_trades
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_number
- tx_hash
- sub_tx_trade_id

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{{ config(
schema = 'king_of_destiny_nova',
alias = 'base_trades',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_number','tx_hash','sub_tx_trade_id'],
)
}}


select
'nova' as blockchain
,'king_of_destiny' as project
,'v1' as project_version
,s.evt_block_time as block_time
,cast(date_trunc('day', s.evt_block_time) as date) as block_date
,cast(date_trunc('month', s.evt_block_time) as date) as block_month
,s.evt_block_number as block_number
,s.evt_tx_hash as tx_hash
,'secondary' as trade_type
,'Buy' as trade_category
,s.evt_index
,s.buyer
,s.listingCreator as seller
,s.contract_address as project_contract_address
,s.tokenId as nft_token_id
,s.assetContract as nft_contract_address
,s.quantityBought as nft_amount
,s.totalPricePaid as price_raw
,from_hex(json_extract_scalar(l.listing, '$.currency')) as currency_contract
,element_at(r.output_amounts,1) as royalty_fee_amount_raw
,cast(null as uint256) as platform_fee_amount_raw
,cast(null as varbinary) as platform_fee_address
,element_at(r.output_recipients,1) as royalty_fee_address
,s.listingId as listing_id
,s.evt_index as sub_tx_trade_id
from {{source('king_of_destiny_nova','MarketplaceV3_DirectListingsLogic_evt_NewSale')}} s
left join {{source('king_of_destiny_nova','MarketplaceV3_DirectListingsLogic_evt_NewListing')}} l
on s.listingId = l.listingId
{% if is_incremental() %}
and {{incremental_predicate('l.evt_block_time')}}
{% endif %}
left join {{source('king_of_destiny_nova','MarketplaceV3_call_GetRoyalty')}} r
on s.evt_tx_hash = r.call_tx_hash
and s.evt_block_number = r.call_block_number
and s.totalPricePaid = r.value
and s.assetContract = r.tokenAddress
and s.tokenId = r.tokenId
{% if is_incremental() %}
and {{incremental_predicate('r.call_block_time')}}
{% endif %}
{% if is_incremental() %}
WHERE {{incremental_predicate('s.evt_block_time')}}
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{ config(
schema = 'opensea_v3_nova',
alias = 'base_trades',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_number', 'tx_hash', 'sub_tx_trade_id']
)
}}
WITH fee_wallets as (
select wallet_address, wallet_name from (
values (0x5b3256965e7c3cf26e11fcaf296dfc8807c01073,'opensea')
,(0x8de9c5a032463c561423387a9648c5c7bcc5bc90,'opensea')
,(0x34ba0f2379bf9b81d09f7259892e26a8b0885095,'opensea')
,(0x0000a26b00c1f0df003000390027140000faa719,'opensea')
) as foo(wallet_address, wallet_name)
)
, trades as (
{{ seaport_v3_trades(
blockchain = 'nova'
,source_transactions = source('nova','transactions')
,Seaport_evt_OrderFulfilled = source('seaport_nova','Seaport_evt_OrderFulfilled')
,Seaport_call_matchAdvancedOrders = source('seaport_nova','Seaport_call_matchAdvancedOrders')
,Seaport_call_matchOrders = source('seaport_nova','Seaport_call_matchOrders')
,fee_wallet_list_cte = 'fee_wallets'
,start_date = '2022-06-01'
)
}}
)

select *
from trades
where
( zone_address in (0xf397619df7bfd4d1657ea9bdd9df7ff888731a11
,0x9b814233894cd227f561b78cc65891aa55c62ad2
,0x004c00500000ad104d7dbd00e3ae0a5c00560c00
,0x110b2b128a9ed1be5ef3232d8e4e41640df5c2cd
,0x000000e7ec00e7b300774b00001314b8610022b8 -- newly added on seaport v1.4
)
or fee_wallet_name = 'opensea'
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{ config(
schema = 'opensea_v4_nova',
alias = 'base_trades',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_number', 'tx_hash', 'sub_tx_trade_id']
)
}}

WITH fee_wallets as (
select wallet_address, wallet_name from (
values (0x5b3256965e7c3cf26e11fcaf296dfc8807c01073,'opensea')
,(0x8de9c5a032463c561423387a9648c5c7bcc5bc90,'opensea')
,(0x34ba0f2379bf9b81d09f7259892e26a8b0885095,'opensea')
,(0x0000a26b00c1f0df003000390027140000faa719,'opensea')
) as foo(wallet_address, wallet_name)
)
, trades as (
{{ seaport_v4_trades(
blockchain = 'nova'
,source_transactions = source('nova','transactions')
,Seaport_evt_OrderFulfilled = source('seaport_nova','Seaport_evt_OrderFulfilled')
,Seaport_evt_OrdersMatched = source('seaport_nova','Seaport_evt_OrdersMatched')
,fee_wallet_list_cte = 'fee_wallets'
,start_date = '2023-01-05'
)
}}
)

select *
from trades
where
( zone_address in (0xf397619df7bfd4d1657ea9bdd9df7ff888731a11
,0x9b814233894cd227f561b78cc65891aa55c62ad2
,0x004c00500000ad104d7dbd00e3ae0a5c00560c00
,0x110b2b128a9ed1be5ef3232d8e4e41640df5c2cd
,0x000000e7ec00e7b300774b00001314b8610022b8 -- newly added on seaport v1.4
,0x000056f7000000ece9003ca63978907a00ffd100 -- new signed zone for seaport v1.6
)
or fee_wallet_name = 'opensea'
)

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
,ref('nft_zora_base_trades')
,ref('nft_blast_base_trades')
,ref('nft_fantom_base_trades')
,ref('nft_nova_base_trades')
] %}

with base_union as (
Expand Down
6 changes: 3 additions & 3 deletions dbt_subprojects/nft/models/_sector/trades/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ models:

- name: nft_trades
meta:
blockchain: ethereum, solana, bnb, optimism, arbitrum, polygon, blast, fantom
blockchain: ethereum, solana, bnb, optimism, arbitrum, polygon, blast, fantom, nova
sector: nft
contributors: soispoke, hildobby, ilemi, cat
contributors: soispoke, hildobby, ilemi, cat, 0xRob
config:
tags: [ 'nft', 'opensea', 'looksrare', 'x2y2', 'magiceden', 'sudoswap', 'foundation', 'element', 'zora', 'ethereum', 'bnb', 'solana', 'optimism', 'arbitrum', 'trades','superrare', 'polygon', 'rarible', 'aavegotchi', 'oneplanet', 'fractal' ]
description: >
Expand Down Expand Up @@ -190,7 +190,7 @@ models:
meta:
blockchain: ethereum, solana, polygon
sector: nft
contributors: soispoke, hildobby, ilemi, cat
contributors: soispoke, hildobby, ilemi, cat, 0xRob
config:
tags: [ 'nft', 'opensea', 'looksrare', 'x2y2', 'magiceden', 'sudoswap', 'foundation', 'element', 'zora', 'ethereum', 'bnb', 'solana', 'fees','superrare', 'polygon', 'rarible', 'aavegotchi', 'oneplanet', 'fractal' ]
description: >
Expand Down
8 changes: 8 additions & 0 deletions sources/king_of_destiny/king_of_destiny_nova_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2

sources:
- name: king_of_destiny_nova
tables:
- name: MarketplaceV3_DirectListingsLogic_evt_NewSale
- name: MarketplaceV3_DirectListingsLogic_evt_NewListing
- name: MarketplaceV3_call_GetRoyalty
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions sources/seaport/seaport_nova_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2

sources:
- name: seaport_nova
tables:
- name: Seaport_evt_OrderFulfilled
- name: Seaport_evt_OrdersMatched
- name: Seaport_call_fulfillAvailableAdvancedOrders
- name: Seaport_call_fulfillOrder
- name: Seaport_call_fulfillBasicOrder
- name: Seaport_call_matchAdvancedOrders
- name: Seaport_call_fulfillAdvancedOrder
- name: Seaport_call_fulfillAvailableOrders
- name: Seaport_call_matchOrders
File renamed without changes.
File renamed without changes.

0 comments on commit 3acb6dd

Please sign in to comment.