-
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.
T 12704 add magiceden trades abstraction (#1084)
In this PR, I'm adding magic eden trades based on the solana.transactions table - Creating magiceden_solana.trades, magiceden.trades, and nft.trades composed on both opensea.trades and magiceden.trades This is part of a bigger attempt to create nft abstractions so wizards can build on top of it. I've checked that: * [* ] I tested the query on dune.com after compiling the model with dbt compile (compiled queries are written to the target directory) * [*] I used "refs" to reference other models in this repo and "sources" to reference raw or decoded tables * [*] the directory tree matches the pattern /sector/blockchain/ e.g. /tokens/ethereum * [*] if adding a new model, I added a test * [*] the filename is unique and ends with .sql * [*] each file has only one view, table or function defined * [*] column names are `lowercase_snake_cased`
- Loading branch information
Showing
23 changed files
with
364 additions
and
38 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
11 changes: 11 additions & 0 deletions
11
spellbook/macros/alter_tblproperties/alter_tblproperties_magiceden_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,11 @@ | ||
{% macro alter_tblproperties_magiceden_trades() -%} | ||
{%- if target.name == 'prod'-%} | ||
ALTER VIEW magiceden.trades SET TBLPROPERTIES('dune.public'='true', | ||
'dune.data_explorer.blockchains'='["solana"]', | ||
'dune.data_explorer.category'='abstraction', | ||
'dune.data_explorer.abstraction.type'='project', | ||
'dune.data_explorer.abstraction.name'='magiceden', | ||
'dune.data_explorer.contributors'='["soispoke"]'); | ||
{%- else -%} | ||
{%- endif -%} | ||
{%- endmacro %} |
11 changes: 11 additions & 0 deletions
11
spellbook/macros/alter_tblproperties/alter_tblproperties_nft_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,11 @@ | ||
{% macro alter_tblproperties_nft_trades() -%} | ||
{%- if target.name == 'prod'-%} | ||
ALTER VIEW nft.trades SET TBLPROPERTIES('dune.public'='true', | ||
'dune.data_explorer.blockchains'='["solana"]', | ||
'dune.data_explorer.category'='abstraction', | ||
'dune.data_explorer.abstraction.type'='sector', | ||
'dune.data_explorer.abstraction.name'='nft', | ||
'dune.data_explorer.contributors'='["soispoke"]'); | ||
{%- else -%} | ||
{%- endif -%} | ||
{%- 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: magiceden_trades | ||
meta: | ||
blockchain: solana | ||
project: magiceden | ||
contributors: soispoke | ||
config: | ||
tags: ['magiceden','solana','trades'] | ||
description: > | ||
Magic Eden trades | ||
columns: | ||
- &blockchain | ||
name: blockchain | ||
description: "Blockchain" | ||
- name: project | ||
description: "Project" | ||
- name: version | ||
description: "Project version" | ||
- name: tx_hash | ||
description: "Transaction hash" | ||
- name: block_time | ||
description: "UTC event block time" | ||
- name: token_symbol | ||
description: "Token Symbol" | ||
- name: amount | ||
description: "Value of the trade at time of execution in the original currency" | ||
- name: amount_usd | ||
description: "USD value of the trade at time of execution" | ||
- name: trade_id | ||
description: "Trade ID (derived from id in solana transactions)" |
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,14 @@ | ||
{{ config( | ||
alias='trades' | ||
) | ||
}} | ||
|
||
SELECT blockchain, 'magiceden' as project, '' as version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id FROM | ||
( | ||
SELECT blockchain, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id | ||
FROM {{ ref('magiceden_solana_trades') }} | ||
) | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
where block_time > (select max(block_time) from {{ this }}) | ||
{% endif %} |
34 changes: 34 additions & 0 deletions
34
spellbook/models/magiceden/solana/magiceden_solana_schema.yml
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,34 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: magiceden_solana_trades | ||
meta: | ||
blockchain: solana | ||
project: magiceden | ||
contributors: soispoke | ||
config: | ||
tags: ['solana','magiceden','trades'] | ||
description: > | ||
MagicEden trades on Solana | ||
columns: | ||
- name: unique_id | ||
description: "Unique id, combination of signatures[0] and id" | ||
tests: | ||
- unique | ||
- &blockchain | ||
name: blockchain | ||
description: "Blockchain" | ||
- name: tx_hash | ||
description: "Transaction hash" | ||
- name: block_time | ||
description: "UTC event block time" | ||
- name: token_symbol | ||
description: "Token Symbol" | ||
- name: amount | ||
description: "Value of the trade at time of execution in the original currency" | ||
- name: amount_usd | ||
description: "USD value of the trade at time of execution" | ||
- name: trader | ||
description: "Trader" | ||
- name: trade_id | ||
description: "Trade ID (derived from id in solana transactions)" |
33 changes: 33 additions & 0 deletions
33
spellbook/models/magiceden/solana/magiceden_solana_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,33 @@ | ||
{{ | ||
config( | ||
alias='trades', | ||
materialized ='incremental', | ||
file_format ='delta', | ||
incremental_strategy='merge', | ||
unique_key='unique_id' | ||
) | ||
}} | ||
|
||
SELECT | ||
signatures[0] || id as unique_id, | ||
'solana' as blockchain, | ||
signatures[0] as tx_hash, | ||
block_time, | ||
abs(post_balances[0] / 1e9 - pre_balances[0] / 1e9) * p.price AS amount_usd, | ||
abs(post_balances[0] / 1e9 - pre_balances[0] / 1e9) AS amount, | ||
p.symbol as token_symbol, | ||
p.contract_address as token_address, | ||
account_keys[0] as traders, | ||
id as trade_id | ||
FROM {{ source('solana','transactions') }} | ||
LEFT JOIN {{ source('prices', 'usd') }} p | ||
ON p.minute = date_trunc('minute', block_time) | ||
AND p.symbol = 'SOL' | ||
WHERE (array_contains(account_keys, 'MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8') -- magic eden v1 | ||
OR array_contains(account_keys, 'M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K')) -- magic eden v2 | ||
AND ARRAY_CONTAINS(log_messages, 'Program log: Instruction: ExecuteSale') | ||
AND block_time > '2021-09-01' | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
AND block_time > (select max(block_time) from {{ this }}) | ||
{% endif %} |
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,26 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: nft_trades | ||
meta: | ||
blockchain: ethereum, solana | ||
sector: nft | ||
contributors: soispoke | ||
config: | ||
tags: ['nft', 'opensea', 'magiceden', 'ethereum', 'solana', 'trades'] | ||
description: > | ||
NFT trades | ||
columns: | ||
- &blockchain | ||
name: blockchain | ||
description: "Blockchain" | ||
- name: tx_hash | ||
description: "Transaction hash" | ||
- name: block_time | ||
description: "UTC event block time" | ||
- name: token_symbol | ||
description: "Token Symbol" | ||
- name: amount | ||
description: "Value of the trade at time of execution in the original currency" | ||
- name: amount_usd | ||
description: "USD value of the trade at time of execution" |
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,13 @@ | ||
{{ config( | ||
alias='trades' | ||
) | ||
}} | ||
|
||
SELECT blockchain, project, version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address,trade_id FROM | ||
(SELECT blockchain, project, version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id FROM {{ ref('opensea_trades') }} | ||
UNION ALL | ||
SELECT blockchain, project, version, tx_hash, block_time, amount_usd, amount, token_symbol, token_address, trade_id FROM {{ ref('magiceden_trades') }}) | ||
{% if is_incremental() %} | ||
-- this filter will only be applied on an incremental run | ||
where block_time > (select max(block_time) from {{ this }}) | ||
{% endif %} |
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
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
Oops, something went wrong.