Skip to content

Commit

Permalink
Add X2Y2 events to Dune v2 (#1298)
Browse files Browse the repository at this point in the history
Brief comments on the purpose of your changes:

Adding all X2Y2 events for `nft.trades` on Dune v2. Code compiled and tested here: https://dune.com/queries/1062586

Unlike LooksRare, X2Y2 wasn't decoded on v1 and thus doesn't have much data to backtest against, this is why I did not include any tests, let me know if that needs to be changed!


*For Dune Engine V2*
I've checked that:

* [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 
* [ ] 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`

When you are ready for a review, tag duneanalytics/data-experience. We will re-open your forked pull request as an internal pull request. Then your spells will run in dbt and the logs will be avaiable in Github Actions DBT Slim CI. This job will only run the models and tests changed by your PR compared to the production project.
  • Loading branch information
hildobby authored Jul 21, 2022
1 parent 0c10e02 commit 2fd09aa
Show file tree
Hide file tree
Showing 35 changed files with 844 additions and 23 deletions.
6 changes: 6 additions & 0 deletions spellbook/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ models:
ethereum:
+schema: looksrare_ethereum
+materialized: view
x2y2:
+schema: x2y2
+materialized: view
ethereum:
+schema: x2y2_ethereum
+materialized: view
magiceden:
+schema: magiceden
+materialized: view
Expand Down
49 changes: 49 additions & 0 deletions spellbook/macros/alter_table_properties.sql
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,50 @@ ALTER VIEW looksrare_ethereum.fees SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.contributors'='["soispoke"]');
{% endset %}

{% set x2y2_ethereum_events %}
ALTER TABLE x2y2_ethereum.events SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.blockchains'='["ethereum"]',
'dune.data_explorer.category'='abstraction',
'dune.data_explorer.abstraction.type'='project',
'dune.data_explorer.abstraction.name'='x2y2',
'dune.data_explorer.contributors'='["hildobby","soispoke"]');
{% endset %}

{% set x2y2_ethereum_trades %}
ALTER VIEW x2y2_ethereum.trades SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.blockchains'='["ethereum"]',
'dune.data_explorer.category'='abstraction',
'dune.data_explorer.abstraction.type'='project',
'dune.data_explorer.abstraction.name'='x2y2',
'dune.data_explorer.contributors'='["hildobby","soispoke"]');
{% endset %}

{% set x2y2_ethereum_mints %}
ALTER VIEW x2y2_ethereum.mints SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.blockchains'='["ethereum"]',
'dune.data_explorer.category'='abstraction',
'dune.data_explorer.abstraction.type'='project',
'dune.data_explorer.abstraction.name'='x2y2',
'dune.data_explorer.contributors'='["hildobby","soispoke"]');
{% endset %}

{% set x2y2_ethereum_burns %}
ALTER VIEW x2y2_ethereum.burns SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.blockchains'='["ethereum"]',
'dune.data_explorer.category'='abstraction',
'dune.data_explorer.abstraction.type'='project',
'dune.data_explorer.abstraction.name'='x2y2',
'dune.data_explorer.contributors'='["hildobby","soispoke"]');
{% endset %}

{% set x2y2_ethereum_fees %}
ALTER VIEW x2y2_ethereum.fees SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.blockchains'='["ethereum"]',
'dune.data_explorer.category'='abstraction',
'dune.data_explorer.abstraction.type'='project',
'dune.data_explorer.abstraction.name'='x2y2',
'dune.data_explorer.contributors'='["hildobby","soispoke"]');
{% endset %}

{% set magiceden_events %}
ALTER TABLE magiceden.events SET TBLPROPERTIES('dune.public'='true',
Expand Down Expand Up @@ -363,6 +407,11 @@ ALTER VIEW ens.view_renewals SET TBLPROPERTIES('dune.public'='true',
{% do run_query(looksrare_ethereum_mints) %}
{% do run_query(looksrare_ethereum_burns) %}
{% do run_query(looksrare_ethereum_fees) %}
{% do run_query(x2y2_ethereum_events) %}
{% do run_query(x2y2_ethereum_trades) %}
{% do run_query(x2y2_ethereum_mints) %}
{% do run_query(x2y2_ethereum_burns) %}
{% do run_query(x2y2_ethereum_fees) %}
{% do run_query(magiceden_events) %}
{% do run_query(magiceden_trades) %}
{% do run_query(magiceden_mints) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
block_number,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
block_number,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
block_number,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
block_number,
tx_hash,
tx_from,
tx_to,
Expand Down
1 change: 1 addition & 0 deletions spellbook/models/magiceden/magiceden_mints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ NULL::string as nft_contract_address,
project_contract_address,
NULL::string as aggregator_name,
NULL::string as aggregator_address,
block_number,
tx_hash,
NULL::string as tx_from,
NULL::string as tx_to,
Expand Down
1 change: 1 addition & 0 deletions spellbook/models/magiceden/magiceden_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ NULL::string as nft_contract_address,
project_contract_address,
NULL::string as aggregator_name,
NULL::string as aggregator_address,
block_number,
tx_hash,
NULL::string as tx_from,
NULL::string as tx_to,
Expand Down
6 changes: 4 additions & 2 deletions spellbook/models/nft/nft_burns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
SELECT * FROM
(SELECT * FROM {{ ref('opensea_burns') }}
UNION
SELECT * FROM {{ ref('looksrare_ethereum_burns') }})
SELECT * FROM {{ ref('looksrare_ethereum_burns') }}
UNION
SELECT * FROM {{ ref('x2y2_ethereum_burns') }})
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
WHERE block_time > now() - interval 2 days
{% endif %}
{% endif %}
2 changes: 2 additions & 0 deletions spellbook/models/nft/nft_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ SELECT * FROM {{ ref('opensea_events') }}
SELECT * FROM {{ ref('magiceden_events') }}
UNION
SELECT * FROM {{ ref('looksrare_ethereum_events') }}
UNION
SELECT * FROM {{ ref('x2y2_ethereum_events') }}
)

{% if is_incremental() %}
Expand Down
6 changes: 4 additions & 2 deletions spellbook/models/nft/nft_fees.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
SELECT * FROM
(SELECT * FROM {{ ref('opensea_fees') }}
UNION
SELECT * FROM {{ ref('looksrare_ethereum_fees') }})
SELECT * FROM {{ ref('looksrare_ethereum_fees') }}
UNION
SELECT * FROM {{ ref('x2y2_ethereum_fees') }})
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
WHERE block_time > now() - interval 2 days
{% endif %}
{% endif %}
2 changes: 2 additions & 0 deletions spellbook/models/nft/nft_mints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ SELECT * FROM {{ ref('opensea_mints') }}
SELECT * FROM {{ ref('magiceden_mints') }}
UNION
SELECT * FROM {{ ref('looksrare_ethereum_mints') }}
UNION
SELECT * FROM {{ ref('x2y2_ethereum_mints') }}
)

{% if is_incremental() %}
Expand Down
20 changes: 10 additions & 10 deletions spellbook/models/nft/nft_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ models:
meta:
blockchain: ethereum, solana
sector: nft
contributors: soispoke
contributors: soispoke, hildobby
config:
tags: ['nft', 'opensea', 'looksrare', 'magiceden', 'ethereum', 'solana', 'events']
tags: ['nft', 'opensea', 'looksrare', 'x2y2', 'magiceden', 'ethereum', 'solana', 'events']
description: >
NFT events
columns:
Expand Down Expand Up @@ -127,9 +127,9 @@ models:
meta:
blockchain: ethereum, solana
sector: nft
contributors: soispoke
contributors: soispoke, hildobby
config:
tags: ['nft', 'opensea', 'looksrare', 'magiceden', 'ethereum', 'solana', 'trades']
tags: ['nft', 'opensea', 'looksrare', 'x2y2', 'magiceden', 'ethereum', 'solana', 'trades']
description: >
NFT trades
columns:
Expand Down Expand Up @@ -165,9 +165,9 @@ models:
meta:
blockchain: ethereum, solana
sector: nft
contributors: soispoke
contributors: soispoke, hildobby
config:
tags: ['nft', 'opensea', 'looksrare', 'magiceden', 'ethereum', 'solana', 'mints']
tags: ['nft', 'opensea', 'looksrare', 'x2y2', 'magiceden', 'ethereum', 'solana', 'mints']
description: >
NFT mints
columns:
Expand Down Expand Up @@ -203,9 +203,9 @@ models:
meta:
blockchain: ethereum, solana
sector: nft
contributors: soispoke
contributors: soispoke, hildobby
config:
tags: ['nft', 'opensea', 'looksrare', 'magiceden', 'ethereum', 'solana', 'burns']
tags: ['nft', 'opensea', 'looksrare', 'x2y2', 'magiceden', 'ethereum', 'solana', 'burns']
description: >
NFT burns
columns:
Expand Down Expand Up @@ -241,9 +241,9 @@ models:
meta:
blockchain: ethereum, solana
sector: nft
contributors: soispoke
contributors: soispoke, hildobby
config:
tags: ['nft', 'opensea', 'looksrare', 'magiceden', 'ethereum', 'solana', 'fees']
tags: ['nft', 'opensea', 'looksrare', 'x2y2', 'magiceden', 'ethereum', 'solana', 'fees']
description: >
NFT fees
columns:
Expand Down
2 changes: 2 additions & 0 deletions spellbook/models/nft/nft_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ SELECT * FROM {{ ref('opensea_trades') }}
SELECT * FROM {{ ref('magiceden_trades') }}
UNION
SELECT * FROM {{ ref('looksrare_ethereum_trades') }}
UNION
SELECT * FROM {{ ref('x2y2_ethereum_trades') }}
)

{% if is_incremental() %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
block_number,
tx_hash,
tx_from,
tx_to,
Expand Down
85 changes: 81 additions & 4 deletions spellbook/models/opensea/ethereum/opensea_ethereum_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,88 @@
unique_key='unique_trade_id'
)
}}

SELECT * FROM ({{ ref('opensea_v1_ethereum_events') }})

SELECT blockchain,
project,
version,
block_time,
token_id,
collection,
amount_usd,
token_standard,
trade_type,
number_of_items,
trade_category,
evt_type,
seller,
buyer,
amount_original,
amount_raw,
currency_symbol,
currency_contract,
nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
block_number,
tx_hash,
tx_from,
tx_to,
platform_fee_amount_raw,
platform_fee_amount,
platform_fee_amount_usd,
platform_fee_percentage,
royalty_fee_amount_raw,
royalty_fee_amount,
royalty_fee_amount_usd,
royalty_fee_percentage,
royalty_fee_receive_address,
royalty_fee_currency_symbol,
unique_trade_id
FROM ({{ ref('opensea_v1_ethereum_events') }})
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
WHERE block_time > now() - interval 2 days
{% endif %}
UNION
SELECT * FROM ({{ ref('opensea_v3_ethereum_events') }})

SELECT blockchain,
'opensea' as project,
'v3' as version,
block_time,
token_id,
collection,
amount_usd,
token_standard,
trade_type,
number_of_items,
trade_category,
evt_type,
seller,
buyer,
amount_original,
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_amount_raw,
royalty_fee_amount,
royalty_fee_amount_usd,
royalty_fee_percentage,
royalty_fee_receive_address,
royalty_fee_currency_symbol,
unique_trade_id
FROM ({{ ref('opensea_v3_ethereum_events') }})
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
WHERE block_time > now() - interval 2 days
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
block_number,
tx_hash,
tx_from,
tx_to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
block_number,
tx_hash,
tx_from,
tx_to,
Expand Down
4 changes: 2 additions & 2 deletions spellbook/models/opensea/ethereum/opensea_ethereum_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
block_number,
tx_hash,
tx_from,
tx_to,
unique_trade_id
FROM (SELECT * FROM {{ ref('opensea_ethereum_events') }} )
WHERE evt_type = 'Trade'
FROM {{ ref('opensea_ethereum_events') }} WHERE evt_type = 'Trade'
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ SELECT DISTINCT
wa.project_contract_address,
agg.name as aggregator_name,
agg.contract_address as aggregator_address,
wa.call_tx_hash AS tx_hash,
tx.block_number,
wa.call_tx_hash AS tx_hash,
tx.from as tx_from,
tx.to as tx_to,
ROUND((2.5*(wa.amount_original)/100),7) AS platform_fee_amount_raw,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
tx_hash,
block_number,
tx_hash,
tx_from,
tx_to,
platform_fee_amount_raw,
Expand Down
1 change: 1 addition & 0 deletions spellbook/models/opensea/opensea_burns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
block_number,
tx_hash,
tx_from,
tx_to,
Expand Down
Loading

0 comments on commit 2fd09aa

Please sign in to comment.