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 Pancakeswap NFT Events #2255

Merged
merged 39 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7c1faee
add seed in yml file
thb030100 Dec 9, 2022
b070a76
Add Pancakeswap NFT V1 to nft trades
thb030100 Dec 7, 2022
9253811
delete tofu
thb030100 Dec 7, 2022
696da6a
Adjust
thb030100 Dec 7, 2022
cbc1215
update
thb030100 Dec 8, 2022
51898e0
update LOGIC
thb030100 Dec 8, 2022
e988e17
initial commit
thb030100 Dec 8, 2022
c7bf7b9
update
thb030100 Dec 8, 2022
3cabc2e
Merge pull request #1 from thb030100/liquidify
thb030100 Dec 9, 2022
01061e4
Update models/pancakeswap/bnb/pancakeswap_bnb_nft_market_v1_event.sql
thb030100 Dec 9, 2022
daeff3c
Update models/pancakeswap/bnb/pancakeswap_bnb_nft_market_v1_event.sql
thb030100 Dec 9, 2022
41d0d41
add test
thb030100 Dec 9, 2022
d64d33d
add
thb030100 Dec 9, 2022
9f773d6
Update models/pancakeswap/bnb/pancakeswap_bnb_nft_market_v1_event.sql
thb030100 Dec 9, 2022
0752c1d
delete liquidifty
thb030100 Dec 9, 2022
6ef5bb9
add test file
thb030100 Dec 9, 2022
76346a1
.
thb030100 Dec 9, 2022
e4d1f0b
update
thb030100 Dec 12, 2022
7bd6d7b
Merge branch 'duneanalytics:main' into main
thb030100 Dec 12, 2022
a0310fa
Merge branch 'main' into temp-main
0xRobin Dec 13, 2022
0595535
fix unique ID
0xRobin Dec 13, 2022
c577603
update sample file
thb030100 Dec 15, 2022
0c75d81
change pancakeswap seed schema
thb030100 Dec 19, 2022
74226dc
temporary comment trade section
thb030100 Dec 19, 2022
bf2e4d3
Merge branch 'duneanalytics:main' into main
thb030100 Dec 19, 2022
1c001e6
reinstate test and correct columns
0xRobin Dec 19, 2022
807eccf
change sample file
thb030100 Dec 19, 2022
fabbedd
change seed file
thb030100 Dec 20, 2022
3120b0d
Merge branch 'main' into main
thb030100 Dec 20, 2022
56849d6
Merge branch 'main' into main
thb030100 Dec 20, 2022
ff1a1ad
add pancakeswap to nft trades
0xRobin Dec 20, 2022
2ecb962
add royalty info
0xRobin Dec 20, 2022
a6b360a
fix currency_symbol
0xRobin Dec 20, 2022
7df4c29
guard fee logic
0xRobin Dec 20, 2022
f4b0cd4
cast null as string
0xRobin Dec 20, 2022
e2d140f
Merge branch 'duneanalytics:main' into main
thb030100 Dec 21, 2022
33a3cf2
remove double column
0xRobin Dec 21, 2022
8b18ce8
Merge branch 'main' of github.com:thb030100/spellbook into thb030100/…
0xRobin Dec 21, 2022
f0b3b0a
Merge branch 'main' into main
0xRobin Dec 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ models:
optimism:
+schema: aave_optimism
+materialized: view

balancer:
+schema: balancer
+materialized: view
Expand Down Expand Up @@ -1085,7 +1084,19 @@ seeds:
block_number: long
tx_hash: string
token_id: string
amount_original: double
pancakeswap:
bnb:
+enabled: true
+schema: test_data
pancakeswap_nft_trades_samples:
block_time: timestamp
token_id: int
seller: string
buyer: string
amount_original: int
tx_hash: string
block_number: int
amount_original: double

foundation:
ethereum:
Expand All @@ -1100,4 +1111,4 @@ seeds:
buyer: string
seller: string
platform_fee_amount: double
royalty_fee_amount: double
royalty_fee_amount: double
1 change: 1 addition & 0 deletions models/nft/nft_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
,ref('superrare_ethereum_events')
,ref('x2y2_ethereum_events')
,ref('zora_ethereum_events')
,ref('pancakeswap_bnb_nft_events')
] %}

SELECT *
Expand Down
1 change: 1 addition & 0 deletions models/nft/nft_fees.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
,ref('superrare_ethereum_fees')
,ref('x2y2_ethereum_fees')
,ref('zora_ethereum_fees')
,ref('pancakeswap_bnb_nft_fees')
] %}


Expand Down
1 change: 1 addition & 0 deletions models/nft/nft_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
,ref('superrare_ethereum_trades')
,ref('x2y2_ethereum_trades')
,ref('zora_ethereum_trades')
,ref('pancakeswap_bnb_nft_trades')
] %}

SELECT *
Expand Down
96 changes: 96 additions & 0 deletions models/pancakeswap/bnb/pancakeswap_bnb_nft_events.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{{ config(
alias = 'events',
partition_by = ['block_date'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_time', 'unique_trade_id'],
post_hook='{{ expose_spells(\'["ethereum"]\',
"project",
"pancakeswap",
\'["thb0301"]\') }}'
)
}}

WITH events AS (
SELECT
'bnb' AS blockchain,
'pancakeswap' AS project,
'v1' AS version,
evt_block_time AS block_time,
tokenId AS token_id,
'erc721' AS token_standard,
'Single Item Trade' AS trade_type,
1 AS number_of_items,
'Buy' AS trade_category,
buyer AS buyer,
seller AS seller,
askPrice AS amount_raw,
0.02 AS platform_fee_percentage,
case when askPrice > 0 and (netPrice/askPrice)<0.98 then (askPrice-netPrice)/askPrice - 0.02 else 0.0 end AS royalty_fee_percentage,
'0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c' AS currency_contract,
CASE when withBNB then 'BNB' else 'WBNB' end AS currency_symbol,
collection AS nft_contract_address,
contract_address AS project_contract_address,
evt_tx_hash AS tx_hash,
evt_block_number AS block_number,
evt_index
FROM {{source('pancakeswap_v2_bnb','ERC721NFTMarketV1_evt_Trade')}}
{% if is_incremental() %}
WHERE evt_block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
)
SELECT
events.blockchain,
events.project,
events.version,
events.block_time,
date_trunc('day', events.block_time) AS block_date,
events.token_id,
bnb_nft_tokens.name collection,
events.amount_raw/POWER(10, bnb_bep20_tokens.decimals)*prices.price AS amount_usd,
events.token_standard,
CASE WHEN agg.name IS NOT NULL THEN 'Bundle Trade' ELSE 'Single Item Trade' END AS trade_type,
CAST(events.number_of_items AS DECIMAL(38,0)) AS number_of_items,
events.trade_category,
'Trade' AS evt_type,
events.seller,
events.buyer,
events.amount_raw/POWER(10, bnb_bep20_tokens.decimals) AS amount_original,
CAST(events.amount_raw AS DECIMAL(38,0)) AS amount_raw,
COALESCE(events.currency_symbol, bnb_bep20_tokens.symbol) AS currency_symbol,
events.currency_contract,
events.nft_contract_address,
events.project_contract_address,
agg.name AS aggregator_name,
CASE WHEN agg.name IS NOT NULL THEN agg.contract_address END AS aggregator_address,
events.tx_hash,
events.block_number,
bt.from AS tx_from,
bt.to AS tx_to,
CAST(amount_raw * platform_fee_percentage AS DOUBLE) AS platform_fee_amount_raw,
(amount_raw * platform_fee_percentage)/POWER(10, bnb_bep20_tokens.decimals) AS platform_fee_amount,
(amount_raw * platform_fee_percentage)/POWER(10, bnb_bep20_tokens.decimals)*prices.price AS platform_fee_amount_usd,
CAST(100 * platform_fee_percentage AS DOUBLE) AS platform_fee_percentage,
CAST(amount_raw * royalty_fee_percentage AS DOUBLE) AS royalty_fee_amount_raw,
(amount_raw * royalty_fee_percentage)/POWER(10, bnb_bep20_tokens.decimals) AS royalty_fee_amount,
(amount_raw * royalty_fee_percentage)/POWER(10, bnb_bep20_tokens.decimals)*prices.price AS royalty_fee_amount_usd,
CAST(100*royalty_fee_percentage AS DOUBLE) AS royalty_fee_percentage,
CAST(null AS STRING) AS royalty_fee_receive_address,
COALESCE(events.currency_symbol, bnb_bep20_tokens.symbol) AS royalty_fee_currency_symbol,
events.block_number || '-' || events.tx_hash || '-' || events.evt_index AS unique_trade_id

FROM events
LEFT JOIN {{ ref('nft_aggregators') }} agg ON events.buyer=agg.contract_address AND agg.blockchain='bnb'
LEFT JOIN {{ ref('tokens_erc20') }} bnb_bep20_tokens ON bnb_bep20_tokens.contract_address=events.currency_contract AND bnb_bep20_tokens.blockchain='bnb'
LEFT JOIN {{ ref('tokens_nft') }} bnb_nft_tokens ON bnb_nft_tokens.contract_address=events.currency_contract AND bnb_nft_tokens.blockchain='bnb'
LEFT JOIN {{ source('prices', 'usd') }} prices ON prices.minute=date_trunc('minute', events.block_time)
AND (prices.contract_address=events.currency_contract AND prices.blockchain=events.blockchain)
{% if is_incremental() %}
AND prices.minute >= date_trunc("day", now() - interval '1 week')
{% endif %}
INNER JOIN {{ source('bnb','transactions') }} bt ON bt.hash=events.tx_hash
AND bt.block_time=events.block_time
{% if is_incremental() %}
AND bt.block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
44 changes: 44 additions & 0 deletions models/pancakeswap/bnb/pancakeswap_bnb_nft_fees.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{
config(
alias='fees',
post_hook='{{ expose_spells(\'["ethereum"]\',
"project",
"pancakeswap",
\'["thb0301"]\') }}'
)
}}

SELECT
blockchain,
project,
version,
block_time,
token_id,
collection,
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,
token_standard,
trade_type,
number_of_items,
trade_category,
evt_type,
seller,
buyer,
nft_contract_address,
project_contract_address,
aggregator_name,
aggregator_address,
tx_hash,
block_number,
tx_from,
tx_to,
unique_trade_id
FROM {{ ref('pancakeswap_bnb_nft_events') }}
40 changes: 40 additions & 0 deletions models/pancakeswap/bnb/pancakeswap_bnb_nft_trades.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{
config(
alias='trades',
post_hook='{{ expose_spells(\'["ethereum"]\',
"project",
"pancakeswap",
\'["thb0301"]\') }}'
)
}}

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,
tx_hash,
block_number,
tx_from,
tx_to,
unique_trade_id
FROM {{ ref('pancakeswap_bnb_nft_events') }}
WHERE evt_type = 'Trade'
Loading