Skip to content

Commit

Permalink
Add Salvor Avalanche NFT Trades
Browse files Browse the repository at this point in the history
  • Loading branch information
henrystats committed Jun 15, 2024
1 parent ac97a0a commit 0a9c9b5
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
,ref('element_avalanche_c_base_trades')
,ref('opensea_v3_avalanche_c_base_trades')
,ref('opensea_v4_avalanche_c_base_trades')
,ref('salvor_avalanche_c_base_trades')
] %}


Expand Down
27 changes: 27 additions & 0 deletions nft/models/_sector/trades/chains/avalanche_c/platforms/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,30 @@ models:
- block_number
- tx_hash
- sub_tx_trade_id

- name: salvor_avalanche_c_base_trades
meta:
blockchain: avalanche_c
sector: nft
project: salvor
contributors: Henrystats
config:
tags: ['avalanche', 'nft', 'trades', 'salvor']
description: "Salvor base trades"
tests:
- check_columns_nft_base_trades
- dbt_utils.unique_combination_of_columns:
combination_of_columns: ['block_number','tx_hash','sub_tx_trade_id']
- check_seed:
seed_file: ref('salvor_avalanche_c_base_trades_seed')
match_columns:
- block_number
- tx_hash
- sub_tx_trade_id
check_columns:
- buyer
- seller
- nft_contract_address
- nft_token_id
- price_raw
- royalty_fee_amount_raw
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WITH
base_trades as (
SELECT
'avalanche_c' as blockchain,
'joepegs' as project,
'chikn' as project,
'v1' as project_version,
evt_block_time as block_time,
date_trunc('day', evt_block_time) as block_date,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{{ config(
schema='salvor_avalanche_c',
alias = 'base_trades',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_number','tx_hash','sub_tx_trade_id']
)}}

{% set project_start_date = '2023-09-01' %}

WITH

events as (
SELECT
evt_block_time,
tokenId as nft_token_id,
UINT256 '1' as nft_amount,
'Trade' as trade_category,
buyer,
bid as price_raw,
0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7 as currency_contract,
collection as nft_contract_address,
evt_tx_hash,
contract_address,
evt_block_number,
evt_index
FROM
{{ source('salvor_avalanche_c', 'Marketplace_evt_AcceptCollectionOffer') }}
{% if is_incremental() %}
WHERE {{incremental_predicate('evt_block_time')}}
{% endif %}
),

royalty_payment as (
SELECT
evt_tx_hash,
collection,
tokenId,
SUM(amount) as amount,
MIN_BY(royaltyReceiver, evt_index) as royaltyRecipient,
MIN_BY(_seller, evt_index) as seller,
COUNT(*) as number_of_payments -- when there are multiple payments, the royalty_fee_address & seller is null
FROM
{{ source('salvor_avalanche_c', 'PaymentManager_evt_RoyaltyReceived') }}
{% if is_incremental() %}
WHERE {{incremental_predicate('evt_block_time')}}
{% endif %}
GROUP BY 1, 2, 3
),

base_trades as (
SELECT
'avalanche_c' as blockchain,
'salvor' as project,
'v1' as project_version,
ee.evt_block_time as block_time,
date_trunc('day',ee.evt_block_time) as block_date,
date_trunc('month',ee.evt_block_time) as block_month,
ee.nft_token_id,
'secondary' as trade_type,
ee.nft_amount,
ee.trade_category,
CASE
WHEN number_of_payments = 1 THEN seller
ELSE CAST(NULL as VARBINARY)
END as seller,
ee.buyer,
ee.price_raw,
ee.currency_contract,
ee.nft_contract_address,
ee.evt_tx_hash as tx_hash,
ee.contract_address as project_contract_address,
ee.evt_block_number as block_number,
CAST(NULL as UINT256) as platform_fee_amount_raw,
ra.amount as royalty_fee_amount_raw,
CASE
WHEN number_of_payments = 1 THEN royaltyRecipient
ELSE CAST(NULL as VARBINARY)
END as royalty_fee_address,
CAST(NULL as VARBINARY) as platform_fee_address,
ee.evt_index as sub_tx_trade_id
FROM
events ee
LEFT JOIN
royalty_payment ra
ON ee.evt_tx_hash = ra.evt_tx_hash
AND ee.nft_contract_address = ra.collection
AND ee.nft_token_id = ra.tokenId
)

{{add_nft_tx_data('base_trades','avalanche_c')}}
11 changes: 11 additions & 0 deletions nft/seeds/trades/base_trades/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,14 @@ seeds:
token_id: uint256
block_date: date

- name: salvor_avalanche_c_base_trades_seed
config:
column_types:
tx_hash: varbinary
buyer: varbinary
seller: varbinary
nft_contract_address: varbinary
price_raw: uint256
royalty_fee_amount_raw: uint256
nft_token_id: uint256

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
block_number,tx_hash,sub_tx_trade_id,buyer,seller,nft_contract_address,nft_token_id,price_raw,royalty_fee_amount_raw
43243959,0xa278c982cf657e5c0198b5f463213267c3fc460a7fb144ae691271b1c87f7d45,12,0xa01c2eda113867352a5e30b3c052810478eff526,0x4f765b9fcd43712404dc32cee0bd4cadf073cc05,0x465e9486bd69155c91ba12fe56f679808e360302,2,650000000000000000,32500000000000000
43241144,0xc0583dd9ad6379b8975077e4b7bc23522a5b127a65069b981075390e24dd4d21,8,0x11c91012cfd0bfbae673f1fcf39b10b1c05b2201,0x8a7190b2db6fe5e6551180ddec53ae138bb401bc,0x956062f3299adeb15a8676426542e1f0c0e7ca09,0,51000000000000000,5100000000000000
6 changes: 5 additions & 1 deletion sources/_sector/nft/trades/avalanche_c_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ sources:
tables:
- name: JoepegExchange_evt_TakerBid
- name: JoepegExchange_evt_TakerAsk
- name: JoepegExchange_evt_RoyaltyPayment
- name: JoepegExchange_evt_RoyaltyPayment
- name: salvor_avalanche_c
tables:
- name: Marketplace_evt_AcceptCollectionOffer
- name: PaymentManager_evt_RoyaltyReceived

0 comments on commit 0a9c9b5

Please sign in to comment.