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

Move nft tokens metadata to tokens subproject #6034

Merged
merged 17 commits into from
May 31, 2024
Merged
65 changes: 0 additions & 65 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -452,50 +452,6 @@ models:
+schema: tokens
+materialized: table
+file_format: delta
ethereum:
+schema: tokens_ethereum
+materialized: table
+file_format: delta
optimism:
+schema: tokens_optimism
+materialized: table
+file_format: delta
avalanche_c:
+schema: tokens_avalanche_c
+materialized: table
+file_format: delta
bnb:
+schema: tokens_bnb
+materialized: table
+file_format: delta
gnosis:
+schema: tokens_gnosis
+materialized: table
+file_format: delta
arbitrum:
+schema: tokens_arbitrum
+materialized: table
+file_format: delta
polygon:
+schema: tokens_polygon
+materialized: table
+file_format: delta
fantom:
+schema: tokens_fantom
+materialized: table
+file_format: delta
solana:
+schema: tokens_solana
+materialized: table
+file_format: delta
base:
+schema: tokens_base
+materialized: table
+file_format: delta
celo:
+schema: tokens_celo
+materialized: table
+file_format: delta

solana_utils:
+schema: solana_utils
Expand Down Expand Up @@ -1038,30 +994,9 @@ models:
ethereum:
+schema: tokemak_ethereum

sound_xyz:
+schema: sound_xyz
optimism:
+schema: sound_xyz_optimism


quests:
+schema: quests

zora:
+schema: zora
optimism:
+schema: zora_optimism

decent:
+schema: decent
optimism:
+schema: decent_optimism

mirror:
+schema: mirror
optimism:
+schema: mirror_optimism

worldcoin:
+schema: worldcoin
optimism:
Expand Down
26 changes: 13 additions & 13 deletions macros/models/_sector/contracts/contracts_contract_mapping.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ WITH get_contracts as (
as {{ col }}
{% endfor %}
FROM (
select
select
c.blockchain
,c.trace_creator_address
,c.contract_address
Expand All @@ -50,10 +50,10 @@ WITH get_contracts as (
,t_mapped.symbol as token_symbol
,c.creator_address
,c.trace_deployer_address
,c.created_time
,c.created_time
,c.created_month


,c.created_tx_hash
,c.created_block_number
,c.created_tx_from
Expand All @@ -75,7 +75,7 @@ WITH get_contracts as (
,c.code_deploy_rank_by_chain
,c.is_self_destruct
,map_rank
from
from
(
SELECT
blockchain, trace_creator_address, contract_address, creator_address, trace_deployer_address,created_time, created_month
Expand All @@ -86,7 +86,7 @@ WITH get_contracts as (
,1 as map_rank
FROM {{ ref('contracts_' + chain + '_base_iterated_creators') }} b

UNION ALL
UNION ALL

SELECT
p.blockchain, trace_creator_address, contract_address, creator_address, creator_address AS trace_deployer_address, created_time, DATE_TRUNC('month',created_time) AS created_month
Expand All @@ -102,7 +102,7 @@ WITH get_contracts as (
WHERE p.blockchain = '{{chain}}'

) c
left join {{ ref('contracts_contract_creator_address_list') }} as cc
left join {{ ref('contracts_contract_creator_address_list') }} as cc
on c.creator_address = cc.creator_address
left join {{ ref('contracts_contract_creator_address_list') }} as ccd
on c.trace_creator_address = ccd.creator_address
Expand All @@ -119,17 +119,17 @@ WITH get_contracts as (
-- WHERE e.blockchain = '{{chain}}'
GROUP BY 1,2,3,4
UNION ALL
select
select
'{{chain}}' as bblockchain ,t.contract_address ,t.name as symbol, standard AS token_standard
from {{ ref('tokens_' + chain + '_nft') }} as t --chain-specific NFT model
from {{ source('tokens_' + chain, 'nft') }} as t --chain-specific NFT model
-- WHERE t.blockchain = '{{chain}}'
group by 1, 2, 3, 4
) as t_mapped
on c.contract_address = t_mapped.contract_address
AND c.blockchain = t_mapped.blockchain
group by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
) a
where contract_address is not NULL
where contract_address is not NULL
group by 1,2
)

Expand Down Expand Up @@ -166,7 +166,7 @@ FROM (
, created_tx_to, created_tx_method_id, created_tx_index
, top_level_contract_address, top_level_time, top_level_tx_hash, top_level_block_number
, top_level_tx_from, top_level_tx_to , top_level_tx_method_id
, code_bytelength , token_standard
, code_bytelength , token_standard
, code
, code_deploy_rank_by_chain
, is_self_destruct
Expand All @@ -175,7 +175,7 @@ FROM (
, is_deterministic_deployer_deployed

FROM (
select
select
cast( created_month as date) AS created_month
,c.blockchain
,c.trace_creator_address
Expand Down Expand Up @@ -212,15 +212,15 @@ FROM (
,c.top_level_tx_from
,c.top_level_tx_to
,c.top_level_tx_method_id

,c.code_bytelength
,c.token_standard
,c.code
,c.code_deploy_rank_by_chain
,CASE WHEN c.trace_creator_address = c.created_tx_from THEN 1 ELSE 0 END AS is_eoa_deployed
,CASE WHEN c.top_level_tx_method_id in (SELECT method_id FROM {{ ref('evm_smart_account_method_ids') }}) THEN 1 ELSE 0 END AS is_smart_wallet_deployed
,CASE WHEN c.trace_creator_address in (SELECT creator_address from {{ref('contracts_deterministic_contract_creators')}} ) THEN 1 ELSE 0 END AS is_deterministic_deployer_deployed
from get_contracts as c
from get_contracts as c
left join {{ ref('contracts_project_name_mappings') }} as dnm -- fix names for decoded contracts
on lower(c.contract_project) = lower(dnm.dune_name)
left join {{ ref('contracts_contract_overrides') }} as co --override contract maps
Expand Down
2 changes: 1 addition & 1 deletion macros/models/_sector/nft/enrich_nft_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ SELECT
ELSE coalesce(agg_mark.aggregator_name, agg1.name, agg2.name)
END as aggregator_name
FROM {{base_trades}} base
LEFT JOIN {{ref('tokens_nft')}} nft
LEFT JOIN {{source('tokens', 'nft')}} nft
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi @0xRobin
we are looking to move nft token metadata to tokens subproject, similar to erc20, flipping to source is part of that

ON nft.blockchain = base.blockchain
AND nft.contract_address = base.nft_contract_address
LEFT JOIN {{ source('tokens', 'erc20') }} erc20
Expand Down
4 changes: 2 additions & 2 deletions macros/models/_sector/nft/nft_mints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ FROM
LEFT JOIN {{ ref('nft_aggregators') }} agg
ON etxs.to=agg.contract_address
AND agg.blockchain = '{{blockchain}}'
LEFT JOIN {{ ref('tokens_nft') }} tok
LEFT JOIN {{ source('tokens', 'nft') }} tok
ON tok.contract_address=nft_mints.contract_address
and tok.blockchain = '{{blockchain}}'
LEFT JOIN namespaces ec ON etxs.to=ec.address
{%- if blockchain == 'optimism' %}
LEFT JOIN {{ ref('tokens_optimism_nft_bridged_mapping') }} as bm
LEFT JOIN {{ source('tokens_optimism', 'nft_bridged_mapping') }} as bm
ON bm.contract_address=nft_mints.contract_address
{%- endif -%}
{% if is_incremental() %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ with source_ethereum_transactions as (
)
,ref_tokens_nft as (
select *
from {{ ref('tokens_nft') }}
from {{ source('tokens', 'nft') }}
where blockchain = '{{ blockchain }}'
)
,ref_tokens_erc20 as (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ with source_ethereum_transactions as (
)
,ref_tokens_nft as (
select *
from {{ ref('tokens_nft') }}
from {{ source('tokens', 'nft') }}
where blockchain = '{{ blockchain }}'
)
,ref_tokens_erc20 as (
Expand Down
2 changes: 1 addition & 1 deletion macros/models/_sector/tokens/balances_enrich.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ select
token_id,
nft_tokens.name as collection_name
from {{balances_raw}} balances
left join {{ ref('tokens_nft') }} nft_tokens on (
left join {{ source('tokens', 'nft') }} nft_tokens on (
nft_tokens.blockchain = balances.blockchain
AND nft_tokens.contract_address = balances.token_address
AND balances.token_standard in ('erc721', 'erc1155')
Expand Down
48 changes: 24 additions & 24 deletions models/astaria/ethereum/astaria_ethereum_daily_deposits.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{{ config(

alias = 'daily_deposits'
)
}}

WITH
WITH

deposit_events AS (
SELECT
collateralId as collateral_id,
collateralId as collateral_id,
tokenId AS collateral_token_id,
tokenContract AS collateral_token_contract,
evt_block_time AS event_time,
Expand All @@ -34,52 +34,52 @@ all_events AS (
),

time_seq AS (
SELECT
SELECT
sequence(
CAST('2023-04-27' as timestamp),
date_trunc('day', cast(now() as timestamp)),
interval '1' day
) AS time
) AS time
),

days AS (
SELECT
time.time AS day
SELECT
time.time AS day
FROM time_seq
CROSS JOIN unnest(time) AS time(time)
),

rolling_balance AS (
SELECT
CAST(date_trunc('DAY', event_time) AS date) as day,
SELECT
CAST(date_trunc('DAY', event_time) AS date) as day,
collateral_token_id,
collateral_token_contract,
SUM(balance_change) OVER (
PARTITION BY collateral_token_id, collateral_token_contract
PARTITION BY collateral_token_id, collateral_token_contract
ORDER BY CAST(date_trunc('DAY', event_time) AS date)
) AS balance_over_time,
lead(CAST(date_trunc('DAY', event_time) AS date), 1, current_timestamp) OVER (
PARTITION BY collateral_token_id, collateral_token_contract
PARTITION BY collateral_token_id, collateral_token_contract
ORDER BY CAST(date_trunc('DAY', event_time) AS date)
) AS next_day
FROM
FROM
all_events
),

daily_balances AS (
SELECT
d.day,
SELECT
d.day,
rb.collateral_token_id,
rb.collateral_token_contract,
COALESCE(SUM(rb.balance_over_time), 0) as daily_balance
FROM
rolling_balance rb
INNER JOIN
days d
ON rb.day <= d.day
FROM
rolling_balance rb
INNER JOIN
days d
ON rb.day <= d.day
AND d.day < rb.next_day
GROUP BY 1, 2, 3
),
),


nft_data AS (
Expand All @@ -89,7 +89,7 @@ nft_data AS (
symbol AS nft_symbol,
standard as nft_token_standard
FROM
{{ ref('tokens_nft') }}
{{ source('tokens', 'nft') }}
WHERE blockchain = 'ethereum'
),

Expand All @@ -102,16 +102,16 @@ collateral_ids AS (
deposit_events
)

SELECT
db.day,
SELECT
db.day,
db.collateral_token_id,
db.collateral_token_contract,
db.daily_balance,
nd.nft_collection,
nd.nft_symbol,
nd.nft_token_standard,
ci.collateral_Id
FROM
FROM
daily_balances db
LEFT JOIN
nft_data nd
Expand Down
Loading
Loading