-
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.
Brief comments on the purpose of your changes: This PR aims to give an example of adding query labels to the spellbook repo *For Dune Engine V2* I've checked that: General checks: * [x] I tested the query on dune.com after compiling the model with dbt compile (compiled queries are written to the target directory) * [x] I used "refs" to reference other models in this repo and "sources" to reference raw or decoded tables * [x] if adding a new model, I added a test * [x] the filename is unique and ends with .sql * [x] each sql file is a select statement and has only one view, table or function defined * [x] column names are `lowercase_snake_cased` * [x] if adding a new model, I edited the dbt project YAML file with new directory path for both models and seeds (if applicable) * [x] if adding a new model, I edited the alter table macro to display new database object (table or view) in UI explorer * [x] if adding a new materialized table, I edited the optimize table macro Join logic: * [ ] if joining to base table (i.e. ethereum transactions or traces), I looked to make it an inner join if possible Incremental logic: * [ ] I used is_incremental & not is_incremental jinja block filters on both base tables and decoded tables * [ ] where block_time >= date_trunc("day", now() - interval '1 week') * [ ] if joining to base table (i.e. ethereum transactions or traces), I applied join condition where block_time >= date_trunc("day", now() - interval '1 week') * [ ] if joining to prices view, I applied join condition where minute >= date_trunc("day", now() - interval '1 week')
- Loading branch information
Showing
8 changed files
with
247 additions
and
3 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
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,7 @@ | ||
{{config(alias='nft')}} | ||
|
||
SELECT * FROM {{ ref('labels_nft_traders_transactions') }} | ||
UNION | ||
SELECT * FROM {{ ref('labels_nft_traders_volume_usd') }} | ||
UNION | ||
SELECT * FROM {{ ref('labels_nft_users_platforms') }} |
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,113 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: labels_nft | ||
meta: | ||
blockchain: ethereum, solana | ||
sector: labels | ||
category: nft | ||
project: ['opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
contibutors: soispoke | ||
config: | ||
tags: ['labels', 'nft', 'ethereum', 'solana', 'opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
description: "NFT query labels" | ||
columns: | ||
- name: blockchain | ||
description: "Blockchain on which NFT trades have been made" | ||
- name: address | ||
description: "Address of NFT traders" | ||
- name: name | ||
description: "Label name NFT trader (Top 1, 5, 10% or simply NFT Trader when an address has traded NFTs but is not in top top 10 or above)" | ||
- name: category | ||
description: "Label category (NFT here)" | ||
- name: contributor | ||
description: "Wizard(s) contributing to labels" | ||
- name: source | ||
description: "How were labels generated (could be static or query)" | ||
- name: created_at | ||
description: "When were labels created" | ||
- name: updated_at | ||
description: "When were labels updated for the last time" | ||
|
||
- name: labels_nft_users_platforms | ||
meta: | ||
blockchain: ethereum, solana | ||
sector: labels | ||
category: nft | ||
project: ['labels','opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
contibutors: soispoke | ||
config: | ||
tags: ['labels', 'nft_traders', 'ethereum', 'solana', 'opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
description: "NFT Platforms users across chains" | ||
columns: | ||
- name: blockchain | ||
description: "Blockchain" | ||
- name: address | ||
description: "Address of NFT platforms users" | ||
- name: name | ||
description: "Label name (NFT Platform User)" | ||
- name: category | ||
description: "Label category (NFT here)" | ||
- name: contributor | ||
description: "Wizard(s) contributing to labels" | ||
- name: source | ||
description: "How were labels generated (could be static or query)" | ||
- name: created_at | ||
description: "When were labels created" | ||
- name: updated_at | ||
description: "When were labels updated for the last time" | ||
|
||
- name: labels_nft_traders_transactions | ||
meta: | ||
blockchain: ethereum, solana | ||
sector: labels | ||
category: nft | ||
project: ['labels','opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
contibutors: soispoke | ||
config: | ||
tags: ['labels', 'nft_traders', 'ethereum', 'solana', 'opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
description: "Top NFT traders based on the number of transactions across chains" | ||
columns: | ||
- name: blockchain | ||
description: "Blockchain on which NFT trades have been made" | ||
- name: address | ||
description: "Address of NFT traders" | ||
- name: name | ||
description: "Label name NFT trader (Top 1, 5, 10% or simply NFT Trader when an address has traded NFTs but is not in top top 10 or above)" | ||
- name: category | ||
description: "Label category (NFT here)" | ||
- name: contributor | ||
description: "Wizard(s) contributing to labels" | ||
- name: source | ||
description: "How were labels generated (could be static or query)" | ||
- name: created_at | ||
description: "When were labels created" | ||
- name: updated_at | ||
description: "When were labels updated for the last time" | ||
|
||
- name: labels_nft_traders_volume_usd | ||
meta: | ||
blockchain: ethereum, solana | ||
sector: labels | ||
project: ['labels','opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
contibutors: soispoke | ||
config: | ||
tags: ['labels', 'nft_traders', 'ethereum', 'solana', 'opensea', 'looksrare', 'x2y2', 'magiceden'] | ||
description: "Top NFT traders based on volume in USD across chains" | ||
columns: | ||
- name: blockchain | ||
description: "Blockchain on which NFT trades have been made" | ||
- name: address | ||
description: "Address of NFT traders" | ||
- name: name | ||
description: "Label name NFT trader (Top 1, 5, 10% or simply NFT Trader when an address has traded NFTs but is not in top top 10 or above)" | ||
- name: category | ||
description: "Label category (NFT here)" | ||
- name: contributor | ||
description: "Wizard(s) contributing to labels" | ||
- name: source | ||
description: "How were labels generated (could be static or query)" | ||
- name: created_at | ||
description: "When were labels created" | ||
- name: updated_at | ||
description: "When were labels updated for the last time" |
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,45 @@ | ||
|
||
{{config(alias='nft_traders_transactions')}} | ||
|
||
WITH nft_trades AS ( | ||
SELECT | ||
blockchain, | ||
tx_hash, | ||
buyer AS address | ||
FROM {{ ref('nft_trades') }} | ||
UNION | ||
SELECT | ||
blockchain, | ||
tx_hash, | ||
seller AS address | ||
FROM {{ ref('nft_trades') }} | ||
), | ||
|
||
total as ( | ||
SELECT | ||
address, | ||
COUNT(tx_hash) AS total_count | ||
FROM nft_trades | ||
GROUP BY 1 | ||
) | ||
|
||
SELECT | ||
collect_set(nft_trades.blockchain) as blockchain, | ||
nft_trades.address, | ||
CASE WHEN ((ROW_NUMBER() OVER(ORDER BY COUNT(tx_hash) DESC)) / total_count * 100) <= 10 | ||
AND ((ROW_NUMBER() OVER(ORDER BY COUNT(tx_hash) DESC)) / total_count * 100) > 5 | ||
THEN 'Top 10% NFT Trader (Transaction)' | ||
WHEN ((ROW_NUMBER() OVER(ORDER BY COUNT(tx_hash) DESC)) / total_count * 100) <= 5 | ||
AND ((ROW_NUMBER() OVER(ORDER BY COUNT(tx_hash) DESC)) / total_count * 100) > 1 | ||
THEN 'Top 5% NFT Trader (Transactions)' | ||
WHEN ((ROW_NUMBER() OVER(ORDER BY COUNT(tx_hash) DESC)) / total_count * 100) <= 1 | ||
THEN 'Top 1% NFT Trader (Transactions)' END AS name, | ||
'nft' AS category, | ||
'soispoke' AS contributor, | ||
'query' AS source, | ||
timestamp('2022-08-24') as created_at, | ||
now() as updated_at | ||
FROM nft_trades | ||
JOIN total on total.address = nft_trades.address | ||
WHERE nft_trades.address is not null | ||
GROUP BY nft_trades.address, total_count |
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 @@ | ||
{{config(alias='nft_traders_volume_usd')}} | ||
|
||
WITH nft_trades AS ( | ||
SELECT | ||
blockchain, | ||
amount_usd, | ||
buyer AS address | ||
FROM {{ ref('nft_trades') }} | ||
UNION | ||
SELECT | ||
blockchain, | ||
amount_usd, | ||
seller AS address | ||
FROM {{ ref('nft_trades') }} | ||
), | ||
|
||
total as ( | ||
SELECT | ||
address, | ||
SUM(amount_usd) AS total_count | ||
FROM nft_trades | ||
GROUP BY 1 | ||
) | ||
|
||
SELECT | ||
collect_set(nft_trades.blockchain) as blockchain, | ||
nft_trades.address, | ||
CASE WHEN ((ROW_NUMBER() OVER(ORDER BY SUM(amount_usd) DESC)) / total_count * 100) <= 10 | ||
AND ((ROW_NUMBER() OVER(ORDER BY SUM(amount_usd) DESC)) / total_count * 100) > 5 | ||
THEN 'Top 10% NFT Trader (Volume in $USD)' | ||
WHEN ((ROW_NUMBER() OVER(ORDER BY SUM(amount_usd) DESC)) / total_count * 100) <= 5 | ||
AND ((ROW_NUMBER() OVER(ORDER BY SUM(amount_usd) DESC)) / total_count * 100) > 1 | ||
THEN 'Top 5% NFT Trader (Volume in $USD)' | ||
WHEN ((ROW_NUMBER() OVER(ORDER BY SUM(amount_usd) DESC)) / total_count * 100) <= 1 | ||
THEN 'Top 1% NFT Trader (Volume in $USD)' END AS name, | ||
'nft' AS category, | ||
'soispoke' AS contributor, | ||
'query' AS source, | ||
timestamp('2022-08-24') as created_at, | ||
now() as updated_at | ||
FROM nft_trades | ||
JOIN total on total.address = nft_trades.address | ||
WHERE nft_trades.address is not null and amount_usd is not null | ||
GROUP BY nft_trades.address, total_count |
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,28 @@ | ||
{{config(alias='nft_users_platforms')}} | ||
|
||
WITH nft_trades AS ( | ||
SELECT | ||
blockchain, | ||
project, | ||
buyer AS address | ||
FROM {{ ref('nft_trades') }} | ||
UNION | ||
SELECT | ||
blockchain, | ||
project, | ||
seller AS address | ||
FROM {{ ref('nft_trades') }} | ||
) | ||
|
||
SELECT | ||
collect_set(blockchain) as blockchain, | ||
address, | ||
array_join(collect_set(concat(upper(substring(project,1,1)),substring(project,2))), ', ') ||' User' as name, | ||
'nft' AS category, | ||
'soispoke' AS contributor, | ||
'query' AS source, | ||
timestamp('2022-09-03') as created_at, | ||
now() as updated_at | ||
FROM nft_trades | ||
WHERE address is not null | ||
GROUP BY address |