-
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.
Add Mavis Market to nft.trades (#7355)
* Add Mavis Market to nft.trades * Add Ronin Sources * Update _sources.yml Added Ronin * Update mavis_marketplace.sql * Update nft_base_trades.sql Added Ronin * Update nft_trades.sql * Create _schema.yml * Remove schema file * Update and rename dbt_subprojects/nft/models/_sector/trades/chains/ronin/platforms/_schema.yml to dbt_subprojects/nft/models/_sector/trades/chains/ronin/nft_ronin_base_trades.sql * Rename mavis_marketplace.sql to mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Update mavis_ronin_base_trades.sql * Create _schema.yml * Update _schema.yml * Update mavis_ronin_base_trades.sql Made changes based on Rob's suggestions. Thanks Rob! --------- Co-authored-by: 0xRob <[email protected]>
- Loading branch information
1 parent
0ab195d
commit 6ab44e7
Showing
7 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
dbt_subprojects/nft/models/_sector/trades/chains/ronin/nft_ronin_base_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,49 @@ | ||
{{ config( | ||
schema = 'nft_ronin', | ||
alias = 'base_trades', | ||
materialized = 'view' | ||
) | ||
}} | ||
-- (project, project_version, model) | ||
{% set nft_models = [ | ||
ref('mavis_ronin_base_trades') | ||
] %} | ||
|
||
with base_union as ( | ||
SELECT * FROM ( | ||
{% for nft_model in nft_models %} | ||
SELECT | ||
blockchain, | ||
project, | ||
project_version, | ||
block_time, | ||
block_date, | ||
block_month, | ||
block_number, | ||
tx_hash, | ||
project_contract_address, | ||
trade_category, | ||
trade_type, | ||
buyer, | ||
seller, | ||
nft_contract_address, | ||
nft_token_id, | ||
nft_amount, | ||
price_raw, | ||
currency_contract, | ||
platform_fee_amount_raw, | ||
royalty_fee_amount_raw, | ||
platform_fee_address, | ||
royalty_fee_address, | ||
sub_tx_trade_id, | ||
tx_from, | ||
tx_to, | ||
tx_data_marker | ||
FROM {{ nft_model }} | ||
{% if not loop.last %} | ||
UNION ALL | ||
{% endif %} | ||
{% endfor %} | ||
) | ||
) | ||
select * from base_union |
12 changes: 12 additions & 0 deletions
12
dbt_subprojects/nft/models/_sector/trades/chains/ronin/platforms/_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,12 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: mavis_ronin_base_trades | ||
meta: | ||
blockchain: ronin | ||
sector: nft | ||
project: mavis_ronin | ||
contributors: ['peterrliem' ] | ||
config: | ||
tags: [ 'ronin', 'nft', 'trades', 'mavis' ] | ||
description: "mavis marketplace base trades" |
92 changes: 92 additions & 0 deletions
92
dbt_subprojects/nft/models/_sector/trades/chains/ronin/platforms/mavis_ronin_base_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,92 @@ | ||
{{ config( | ||
schema = 'mavis_ronin', | ||
alias = 'base_trades', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['block_number','tx_hash','sub_tx_trade_id'], | ||
) | ||
}} | ||
|
||
|
||
with trade_details as ( | ||
|
||
select | ||
evt_block_time as block_time, | ||
evt_block_date as block_date, | ||
evt_block_number as block_number, | ||
evt_tx_hash as tx_hash, | ||
evt_tx_from as tx_from, | ||
evt_tx_to as tx_to, | ||
evt_index, | ||
contract_address, | ||
COALESCE(FROM_HEX(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[5].recipient')),FROM_HEX(json_extract_scalar(json_parse(json_extract_scalar("order", '$.info')), '$.maker'))) as seller, | ||
FROM_HEX(json_extract_scalar("order", '$.recipient')) as buyer, | ||
json_extract_scalar(json_parse(json_extract_scalar("order", '$.info')), '$.kind') as kind, | ||
cast(json_extract_scalar(replace(json_extract_scalar(json_parse(json_extract_scalar("order", '$.info')),'$.assets[0]'),'\\', ''),'$.erc') as double) as erc, | ||
FROM_HEX(json_extract_scalar(replace(json_extract_scalar(json_parse(json_extract_scalar("order", '$.info')),'$.assets[0]'),'\\', ''),'$.addr')) as nft_contract_address, | ||
cast(json_extract_scalar(replace(json_extract_scalar(json_parse(json_extract_scalar("order", '$.info')),'$.assets[0]'),'\\', ''),'$.id') as double) as nft_token_id, | ||
case | ||
when cast(json_extract_scalar(replace(json_extract_scalar(json_parse(json_extract_scalar("order", '$.info')),'$.assets[0]'),'\\', ''),'$.quantity') as double) = 0 then 1 | ||
else cast(json_extract_scalar(replace(json_extract_scalar(json_parse(json_extract_scalar("order", '$.info')),'$.assets[0]'),'\\', ''),'$.quantity') as double) | ||
end as quantity, | ||
FROM_HEX(json_extract_scalar(json_parse(json_extract_scalar("order", '$.info')), '$.paymentToken')) as currency_address, | ||
CAST(json_extract_scalar("order", '$.realPrice') AS DOUBLE) as price_raw, | ||
CAST(json_extract_scalar(json_parse(json_extract_scalar("order", '$.info')), '$.baseUnitPrice') AS DOUBLE) as base_unit_price_raw, | ||
FROM_HEX(json_extract_scalar("order", '$.refunder')) as refunder, | ||
FROM_HEX(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[1].recipient')) as platform_address, | ||
CAST(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[1].value') AS DOUBLE) as platform_fee_amount_raw, | ||
FROM_HEX(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[2].recipient')) as axie_treasury_address, | ||
CAST(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[2].ratio') AS DOUBLE) as axie_fee_raw, | ||
CAST(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[2].value') AS DOUBLE) as axie_fee_amount_raw, | ||
FROM_HEX(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[3].recipient')) as ronin_treasury_address, | ||
CAST(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[3].ratio') AS DOUBLE) as ronin_fee, | ||
CAST(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[3].value') AS DOUBLE) as ronin_treasury_fee_amount_raw, | ||
FROM_HEX(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[4].recipient')) as creator_royalty_address, | ||
CAST(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[4].ratio') AS DOUBLE) as creator_royalty_fee, | ||
CAST(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[4].value') AS DOUBLE) as creator_royalty_fee_amount_raw, | ||
CAST(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[5].ratio')AS DOUBLE) AS seller_percentage_fee, | ||
CAST(json_extract_scalar(json_parse(cast(concat('[', array_join(receivedAllocs, ','), ']') as varchar)),'$[5].value')AS DOUBLE) AS seller_amount_raw | ||
FROM | ||
{{ source('mavis_marketplace_ronin','MavisMarketPlace_evt_OrderMatched') }} | ||
{% if is_incremental() %} | ||
WHERE {{incremental_predicate('evt_block_time')}} | ||
{% endif %} | ||
), | ||
|
||
base_trades as ( | ||
|
||
select | ||
'ronin' as blockchain, | ||
'mavis market' as project, | ||
'v1' as project_version, | ||
block_time, | ||
cast(date_trunc('day', block_time) as date) as block_date, | ||
cast(date_trunc('month', block_time) as date) as block_month, | ||
block_number, | ||
nft_contract_address, | ||
nft_token_id, | ||
quantity as nft_amount, | ||
seller, | ||
buyer, | ||
'buy' as trade_category, | ||
'secondary' as trade_type, | ||
price_raw, | ||
currency_address as currency_contract, | ||
contract_address as project_contract_address, | ||
tx_hash, | ||
platform_address as platform_fee_address, | ||
platform_fee_amount_raw, | ||
creator_royalty_address as royalty_fee_address, | ||
creator_royalty_fee_amount_raw as royalty_fee_amount_raw, | ||
axie_fee_amount_raw, | ||
ronin_treasury_fee_amount_raw, | ||
evt_index as sub_tx_trade_id | ||
FROM trade_details | ||
) | ||
|
||
-- this will be removed once tx_from and tx_to are available in the base event tables | ||
{{ add_nft_tx_data('base_trades', 'ronin') }} | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,6 @@ sources: | |
- name: nft_sei | ||
tables: | ||
- name: transfers | ||
- name: nft_ronin | ||
tables: | ||
- name: transfers |
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,7 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: mavis_marketplace_ronin | ||
tables: | ||
- name: MavisMarketPlace_evt_OrderMatched | ||
|