Skip to content
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

Add nft linked addresses #1457

Merged
merged 11 commits into from
Sep 7, 2022
7 changes: 7 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,10 @@ seeds:
platform_fee_amount: double
pool_fee_amount: double

nft:
+enabled: true
+schema: test_data
nft_linked_addresses_postgres:
+column_types:
master_address: string
alternative_address: string
10 changes: 10 additions & 0 deletions macros/alter_table_properties.sql
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ ALTER VIEW nft.aggregators SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.contributors'='["hildobby","soispoke"]');
{% endset %}

{% set nft_linked_addresses %}
ALTER TABLE nft.linked_addresses SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.blockchains'='["ethereum","solana"]',
'dune.data_explorer.category'='abstraction',
'dune.data_explorer.abstraction.type'='sector',
'dune.data_explorer.abstraction.name'='nft',
'dune.data_explorer.contributors'='["springzh"]');
{% endset %}

{% set tokens_erc20 %}
ALTER VIEW tokens.erc20 SET TBLPROPERTIES ('dune.public'='true',
'dune.data_explorer.blockchains'='["avalanche_c","bnb","ethereum","optimism", "gnosis"]',
Expand Down Expand Up @@ -626,6 +635,7 @@ ALTER VIEW archipelago_ethereum.fees SET TBLPROPERTIES ('dune.public'='true',
{% do run_query(uniswap_trades) %}
{% do run_query(dex_trades) %}
{% do run_query(nft_aggregators) %}
{% do run_query(nft_linked_addresses) %}
{% do run_query(transfers_ethereum_erc20) %}
{% do run_query(seaport_ethereum_view_transactions) %}
{% do run_query(seaport_ethereum_transfers) %}
Expand Down
67 changes: 67 additions & 0 deletions models/nft/nft_linked_addresses.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{{ config(
alias = 'linked_addresses',
partition_by = ['blockchain'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['blockchain', 'linked_address_id']
)
}}

with nft_trade_address as (
select distinct blockchain, buyer as address_a, seller as address_b
from {{ ref('nft_trades') }}
where buyer is not null
and seller is not null
and blockchain is not null
{% if is_incremental() %}
and block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
union all

select distinct blockchain, seller as address_a, buyer as address_b
from {{ ref('nft_trades') }}
where buyer is not null
and seller is not null
and blockchain is not null
{% if is_incremental() %}
and block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
),

linked_address_nft_trade as (
select blockchain,
address_a,
address_b,
count(*) as cnt
from nft_trade_address
group by 1, 2, 3
having count(*) > 1
),

linked_address_sorted as (
-- Normalize linked addresses to master address
select blockchain,
(case when address_a > address_b then address_b else address_a end) as master_address,
address_a as alternative_address
from linked_address_nft_trade
union
select blockchain,
(case when address_a > address_b then address_b else address_a end) as master_address,
address_b as alternative_address
from linked_address_nft_trade
),

linked_address_sorted_row_num as (
select blockchain, master_address, alternative_address,
master_address || '-' || alternative_address as linked_address_id,
row_number() over (partition by blockchain, alternative_address order by master_address) as row_num
from linked_address_sorted
)

select blockchain,
master_address,
alternative_address,
linked_address_id
from linked_address_sorted_row_num
where row_num = 1
20 changes: 19 additions & 1 deletion models/nft/nft_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,22 @@ models:
- *block_number
- *tx_from
- *tx_to
- *unique_trade_id
- *unique_trade_id

- name: nft_linked_addresses
meta:
blockchain: ethereum, solana
sector: nft
contributors: springzh
config:
tags: ['nft', 'opensea', 'looksrare', 'x2y2', 'magiceden', 'sudoswap', 'ethereum', 'solana', 'address']
description: >
NFT linked addresses. Addresses that buy and sell NFTs from each other.
columns:
- *blockchain
- name: master_address
description: "Master address"
- name: alternative_address
description: "Alternative address"
- name: linked_address_id
description: "Unique linked address id"
Loading