-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Added Spaceharpoon Polygon Nft Trades #6708
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not look like you are using any events or calls that are specific to spaceharpoon, can you expand a bit on what you are trying to achieve in this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you expand on your reasoning? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
{{ config( | ||
schema = 'spaceharpoon_polygon', | ||
alias = 'nft_trades', | ||
partition_by = ['block_month'], | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['tx_hash', 'evt_index', 'nft_token_id', 'nft_amount'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] | ||
) | ||
}} | ||
|
||
WITH | ||
|
||
fungible_transfers as ( | ||
SELECT | ||
CASE WHEN token_standard = 'native' THEN 0x0000000000000000000000000000000000001010 | ||
else contract_address end as token_address, | ||
"from" as wallet_address, | ||
amount as amount, | ||
tx_hash, | ||
block_time | ||
FROM | ||
{{ source('tokens_polygon', 'transfers') }} | ||
WHERE token_standard IN ('native', 'erc20') | ||
{% if is_incremental() %} | ||
AND {{incremental_predicate('block_time')}} | ||
{% endif %} | ||
|
||
union all | ||
|
||
SELECT | ||
CASE WHEN token_standard = 'native' THEN 0x0000000000000000000000000000000000001010 | ||
else contract_address end as token_address, | ||
to as wallet_address, | ||
-amount as amount, | ||
tx_hash, | ||
block_time | ||
FROM | ||
{{ source('tokens_polygon', 'transfers') }} | ||
WHERE token_standard IN ('native', 'erc20') | ||
{% if is_incremental() %} | ||
AND {{incremental_predicate('block_time')}} | ||
{% endif %} | ||
), | ||
|
||
transfers_aggregated_tmp as ( | ||
SELECT | ||
SUM(amount) as cum_amt, | ||
wallet_address, | ||
token_address, | ||
tx_hash, | ||
block_time | ||
FROM | ||
fungible_transfers | ||
GROUP BY 2, 3, 4, 5 | ||
HAVING SUM(amount) > 0 | ||
), | ||
|
||
prices as ( | ||
SELECT | ||
date_trunc('hour', minute) as time, | ||
contract_address, | ||
symbol, | ||
AVG(price) as price, | ||
AVG(decimals) as decimals | ||
FROM | ||
{{ source('prices', 'usd_forward_fill') }} | ||
WHERE 1 = 1 | ||
AND blockchain = 'polygon' | ||
{% if is_incremental() %} | ||
AND {{incremental_predicate('minute')}} | ||
{% endif %} | ||
GROUP BY 1, 2, 3 | ||
), | ||
|
||
transfers_aggregated as ( | ||
SELECT | ||
SUM(ta.cum_amt) as amount, | ||
SUM(ta.cum_amt * p.price) as amount_usd, | ||
array_agg(ta.wallet_address) as interacting_addresses, | ||
ta.tx_hash, | ||
ta.block_time | ||
FROM | ||
transfers_aggregated_tmp ta | ||
INNER JOIN | ||
prices p | ||
ON date_trunc('hour', ta.block_time) = p.time | ||
AND ta.token_address = p.contract_address | ||
GROUP BY 4, 5 | ||
), | ||
|
||
nft_transfers as ( | ||
SELECT | ||
block_time, | ||
block_number, | ||
tx_hash, | ||
contract_address, | ||
"from", | ||
to, | ||
amount, | ||
token_id, | ||
transfer_type, | ||
evt_index | ||
FROM | ||
{{ source('nft', 'transfers') }} | ||
WHERE 1 = 1 | ||
AND blockchain = 'polygon' | ||
{% if is_incremental() %} | ||
AND {{incremental_predicate('block_time')}} | ||
{% endif %} | ||
) | ||
|
||
SELECT | ||
'polygon' as blockchain, | ||
'New Methodology' as project, | ||
'1' as project_version, | ||
CAST(date_trunc('day', nt.block_time) as date) as block_date, | ||
CAST(date_trunc('month', nt.block_time) as date) as block_month, | ||
nt.block_time, | ||
nt.block_number, | ||
nt.tx_hash, | ||
nt.evt_index, | ||
tx.to as project_contract_address, | ||
CAST(NULL as VARCHAR) as trade_category, | ||
CAST(NULL as VARCHAR) as trade_type, | ||
CAST(NULL as VARBINARY) as buyer, | ||
CAST(NULL as VARBINARY) as seller, | ||
nt.contract_address as nft_contract_address, | ||
nt.token_id as nft_token_id, | ||
nt.amount as nft_amount, | ||
CAST(NULL as VARBINARY) as currency_contract, | ||
CAST(NULL as UINT256) as platform_fee_amount_raw, | ||
CAST(NULL as UINT256) as royalty_fee_amount_raw, | ||
CAST(NULL as VARBINARY) as platform_fee_address, | ||
CAST(NULL as VARBINARY) as royalty_fee_address, | ||
tx."from" as tx_from, | ||
tx.to as tx_to, | ||
nft.name as nft_collection, | ||
nft.standard as nft_standard, | ||
CAST(NULL as VARCHAR) as currency_symbol, | ||
ta.amount as price, | ||
CAST(NULL as double) as platform_fee_amount, | ||
CAST(NULL as double) as royalty_fee_amount, | ||
ta.amount_usd as price_usd, | ||
CAST(NULL as double) as platform_fee_amount_usd, | ||
CAST(NULL as double) as royalty_fee_amount_usd, | ||
CAST(NULL as double) as platform_fee_percentage, | ||
CAST(NULL as double) as royalty_fee_percentage, | ||
agg.contract_address as aggregator_address, | ||
CASE | ||
WHEN agg.name = 'Gem' AND nt.block_number >= 16971894 THEN 'OpenSea Pro' -- 16971894 is the first block of 2023-04-04 which is when Gem rebranded to OpenSea Pro | ||
ELSE agg.name | ||
END as aggregator_name | ||
FROM | ||
nft_transfers nt | ||
INNER JOIN | ||
transfers_aggregated ta | ||
ON nt.tx_hash = ta.tx_hash | ||
INNER JOIN | ||
{{ source('polygon', 'transactions') }} tx | ||
ON tx.block_number = nt.block_number | ||
AND tx.hash = nt.tx_hash | ||
{% if is_incremental() %} | ||
AND {{incremental_predicate('tx.block_time')}} | ||
{% endif %} | ||
LEFT JOIN | ||
{{ source('tokens', 'nft') }} nft | ||
ON nft.blockchain = 'polygon' | ||
AND nft.contract_address = nt.contract_address | ||
LEFT JOIN | ||
{{ source('nft', 'aggregators') }} agg | ||
ON agg.blockchain = 'polygon' | ||
AND tx.to = agg.contract_address |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: spaceharpoon_polygon_nft_trades | ||
meta: | ||
blockchain: polygon | ||
sector: nft | ||
contributors: Sofiat | ||
config: | ||
tags: [ 'nft', 'polygon' ] | ||
description: > | ||
NFT trades | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- tx_hash | ||
- evt_index | ||
- nft_token_id | ||
- nft_amount | ||
columns: | ||
- &blockchain | ||
name: blockchain | ||
description: "Blockchain" | ||
- &project | ||
name: project | ||
description: "Project" | ||
- &project_version | ||
name: project_version | ||
description: "Project version" | ||
- &block_time | ||
name: block_time | ||
description: "UTC event block time" | ||
- &evt_index | ||
name: evt_index | ||
description: "Transaction EVT Index" | ||
- &nft_token_id | ||
name: nft_token_id | ||
description: "NFT Token ID" | ||
- &nft_collection | ||
name: nft_collection | ||
description: "NFT collection name" | ||
- &price_usd | ||
name: price_usd | ||
description: "USD value of the trade at time of execution" | ||
tests: | ||
- dbt_utils.accepted_range: | ||
max_value: 1000000000 # $1b is an arbitrary number, intended to flag outlier amounts early | ||
- &nft_standard | ||
name: nft_standard | ||
description: "NFT standard" | ||
- &trade_type | ||
name: trade_type | ||
description: "Identify whether it was a single NFT trade or multiple NFTs traded" | ||
- &trade_category | ||
name: trade_category | ||
description: "How was this NFT traded ? (Direct buy, auction, etc...)" | ||
- &seller | ||
name: seller | ||
description: "Seller wallet address" | ||
- &buyer | ||
name: buyer | ||
description: "Buyer wallet address" | ||
- ¤cy_symbol | ||
name: currency_symbol | ||
description: "Symbol of original currency used for payment" | ||
- ¤cy_contract | ||
name: currency_contract | ||
description: "Contract address of original token used for payment, with ETH contract address swapped for WETH" | ||
- &nft_contract_address | ||
name: nft_contract_address | ||
description: "NFT contract address, only if 1 nft was transacted" | ||
- &project_contract_address | ||
name: project_contract_address | ||
description: "Contract address used by the project, in this case wyvern contract" | ||
- &aggregator_name | ||
name: aggregator_name | ||
description: "If the trade was performed via an aggregator, displays aggregator name" | ||
- &aggregator_address | ||
name: aggregator_address | ||
description: "If the trade was performed via an aggregator, displays aggregator address" | ||
- &tx_hash | ||
name: tx_hash | ||
description: "Transaction hash" | ||
- &block_number | ||
name: block_number | ||
description: "Block number in which the transaction was executed " | ||
- &tx_from | ||
name: tx_from | ||
description: "Address that initiated the transaction" | ||
- &tx_to | ||
name: tx_to | ||
description: "Address that received the transaction" | ||
- &platform_fee_amount_raw | ||
name: platform_fee_amount_raw | ||
description: "Raw numerical amount for platform fees" | ||
- &platform_fee_amount | ||
name: platform_fee_amount | ||
description: "Platform fee amount in original token currency (properly formatted in decimals)" | ||
- &platform_fee_amount_usd | ||
name: platform_fee_amount_usd | ||
description: "Platform fee amount in USD" | ||
- &platform_fee_percentage | ||
name: platform_fee_percentage | ||
description: "Platform fee in % of the amount paid for a given trade" | ||
- &royalty_fee_receive_address | ||
name: royalty_fee_receive_address | ||
description: "Wallet addresses receiving fees from the transaction" | ||
- &royalty_fee_amount_raw | ||
name: royalty_fee_amount_raw | ||
description: "Raw numerical amount for royalty fees" | ||
- &royalty_fee_amount | ||
name: royalty_fee_amount | ||
description: "Royalty fee amount in original token currency (properly formatted in decimals)" | ||
- &royalty_fee_amount_usd | ||
name: royalty_fee_amount_usd | ||
description: "Royalty fee amount in USD" | ||
- &royalty_fee_percentage | ||
name: royalty_fee_percentage | ||
description: "Royalty fee in % of the amount paid for a given trade" | ||
- &block_date | ||
name: block_date | ||
description: "Date of the transaction" | ||
- &block_month | ||
name: block_month | ||
description: "Month of the transaction" |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is added by accident to this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. It was a mistake There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you remove it? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{% macro uniswap_compatible_v2_trades( | ||
blockchain = null | ||
, project = null | ||
, version = null | ||
, Pair_evt_Swap = null | ||
, Factory_evt_PairCreated = null | ||
, pair_column_name = 'pair' | ||
) | ||
%} | ||
WITH dexs AS | ||
( | ||
SELECT | ||
t.evt_block_number AS block_number | ||
, t.evt_block_time AS block_time | ||
, t.to AS taker | ||
, t.contract_address AS maker | ||
, CASE WHEN amount0Out = UINT256 '0' THEN amount1Out ELSE amount0Out END AS token_bought_amount_raw | ||
, CASE WHEN amount0In = UINT256 '0' OR amount1Out = UINT256 '0' THEN amount1In ELSE amount0In END AS token_sold_amount_raw | ||
, CASE WHEN amount0Out = UINT256 '0' THEN f.token1 ELSE f.token0 END AS token_bought_address | ||
, CASE WHEN amount0In = UINT256 '0' OR amount1Out = UINT256 '0' THEN f.token1 ELSE f.token0 END AS token_sold_address | ||
, t.contract_address AS project_contract_address | ||
, t.evt_tx_hash AS tx_hash | ||
, t.evt_index AS evt_index | ||
FROM | ||
{{ Pair_evt_Swap }} t | ||
INNER JOIN | ||
{{ Factory_evt_PairCreated }} f | ||
ON f.{{ pair_column_name }} = t.contract_address | ||
{% if is_incremental() %} | ||
WHERE | ||
{{ incremental_predicate('t.evt_block_time') }} | ||
{% endif %} | ||
) | ||
|
||
SELECT | ||
'{{ blockchain }}' AS blockchain | ||
, '{{ project }}' AS project | ||
, '{{ version }}' AS version | ||
, CAST(date_trunc('month', dexs.block_time) AS date) AS block_month | ||
, CAST(date_trunc('day', dexs.block_time) AS date) AS block_date | ||
, dexs.block_time | ||
, dexs.block_number | ||
, dexs.token_bought_amount_raw | ||
, dexs.token_sold_amount_raw | ||
, dexs.token_bought_address | ||
, dexs.token_sold_address | ||
, dexs.taker | ||
, dexs.maker | ||
, dexs.project_contract_address | ||
, dexs.tx_hash | ||
, dexs.evt_index | ||
FROM | ||
dexs | ||
{% endmacro %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these lines are not needed (as we define the schema in the inline config in the models)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted!