Skip to content

Commit

Permalink
Add raw address table
Browse files Browse the repository at this point in the history
  • Loading branch information
Horace Liu authored and Horace Liu committed Dec 19, 2024
1 parent e838dd4 commit 68e9d90
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 53 deletions.
12 changes: 8 additions & 4 deletions macros/contracts/labeled_flipside_contracts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ with
then 'Bridge'
else null
end as category,
label_subtype as sub_category
label_subtype as sub_category,
modified_timestamp as last_updated
from {{ chain }}_flipside.core.dim_labels
),
manual_filter as (
Expand All @@ -54,7 +55,8 @@ with
case
when namespace = 'wormhole' then 'Bridge' else category
end as category,
sub_category
sub_category,
last_updated
from chain_labels
where namespace is not null and namespace <> ''
),
Expand All @@ -65,7 +67,8 @@ with
, name
, namespace
, category
, null as sub_category
, null as sub_category,
last_updated
from {{ ref( token_type_identifier ~ "_token_type")}}
union
select
Expand All @@ -75,10 +78,11 @@ with
, namespace
, category
, sub_category
, last_updated
from manual_filter
where address not in (select address from {{ ref( token_type_identifier ~ "_token_type")}})
)
select address, chain, name, namespace, category, sub_category
select address, chain, name, namespace, category, sub_category, last_updated
from token_filter

{% endmacro %}
3 changes: 2 additions & 1 deletion models/dimensions/contracts/dim_dune_contracts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ select
source_json:address::string as address,
max_by(source_json:namespace::string, extraction_date) as namespace,
max_by(source_json:name::string, extraction_date) as name,
source_json:chain::string as chain
source_json:chain::string as chain,
MAX(extraction_date) AS last_updated
from {{ source("PROD_LANDING", "raw_dune_contracts") }}
group by address, chain
20 changes: 10 additions & 10 deletions models/dimensions/contracts/dim_flipside_contracts.sql
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{{ config(materialized="table") }}
with
flipside_contract as (
select address, name, namespace, sub_category, category, 'arbitrum' as chain
select address, name, namespace, sub_category, category, 'arbitrum' as chain, last_updated
from {{ ref("dim_flipside_arbitrum_contracts") }}

union
select address, name, namespace, sub_category, category, 'avalanche' as chain
select address, name, namespace, sub_category, category, 'avalanche' as chain, last_updated
from {{ ref("dim_flipside_avalanche_contracts") }}

union
select address, name, namespace, sub_category, category, 'base' as chain
select address, name, namespace, sub_category, category, 'base' as chain, last_updated
from {{ ref("dim_flipside_base_contracts") }}

union
select address, name, namespace, sub_category, category, 'bsc' as chain
select address, name, namespace, sub_category, category, 'bsc' as chain, last_updated
from {{ ref("dim_flipside_bsc_contracts") }}

union
select address, name, namespace, sub_category, category, 'ethereum' as chain
select address, name, namespace, sub_category, category, 'ethereum' as chain, last_updated
from {{ ref("dim_flipside_ethereum_contracts") }}

union
select address, name, namespace, sub_category, category, 'polygon' as chain
select address, name, namespace, sub_category, category, 'polygon' as chain, last_updated
from {{ ref("dim_flipside_polygon_contracts") }}

union
select address, name, namespace, sub_category, category, 'optimism' as chain
select address, name, namespace, sub_category, category, 'optimism' as chain, last_updated
from {{ ref("dim_flipside_optimism_contracts") }}

union
select address, name, namespace, sub_category, category, 'near' as chain
select address, name, namespace, sub_category, category, 'near' as chain, last_updated
from {{ ref("dim_flipside_near_contracts") }}

union
select address, name, namespace, sub_category, category, 'solana' as chain
select address, name, namespace, sub_category, category, 'solana' as chain, last_updated
from {{ ref("dim_flipside_solana_contracts") }}

union
select address, name, namespace, sub_category, category, 'sei' as chain
select address, name, namespace, sub_category, category, 'sei' as chain, last_updated
from {{ ref("dim_flipside_sei_contracts") }}
)
select
Expand Down
19 changes: 11 additions & 8 deletions models/dimensions/contracts/dim_flipside_near_contracts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

with
deployed_contracts as (
select tx_signer as address
from near_flipside.core.fact_actions_events
select tx_signer as address,
ft.modified_timestamp
from near_flipside.core.fact_actions_events fae
join
near_flipside.core.fact_transactions
on near_flipside.core.fact_actions_events.tx_hash
= near_flipside.core.fact_transactions.tx_hash
where action_name = 'DeployContract' and tx_receiver = tx_signer
near_flipside.core.fact_transactions ft
on fae.tx_hash
= ft.tx_hash
where fae.action_name = 'DeployContract' and ft.tx_receiver = ft.tx_signer
group by 1
),
contracts_tagged as (
Expand All @@ -35,7 +36,8 @@ with
when label_type = 'bridge'
then 'Bridge'
else null
end as category
end as category,
contracts.modified_timestamp
from near_flipside.core.dim_address_labels as labels
full join deployed_contracts as contracts on labels.address = contracts.address
)
Expand Down Expand Up @@ -272,5 +274,6 @@ select
else namespace
end as namespace,
sub_category,
category
category,
modified_timestamp as last_updated
from contracts_tagged
9 changes: 6 additions & 3 deletions models/dimensions/contracts/dim_flipside_sei_contracts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ with filtered_address as (
when label_type = 'cex'
then 'CEX'
else null
end as sub_category
end as sub_category,
modified_timestamp
from sei_flipside.core.dim_labels as labels
union all
select
Expand All @@ -69,7 +70,8 @@ with filtered_address as (
then 'Token'
else null
end as category,
null as sub_category
null as sub_category,
modified_timestamp
from sei_flipside.core_evm.dim_contracts
)
select
Expand Down Expand Up @@ -97,5 +99,6 @@ select
when namespace = 'webump' or namespace = 'pallet' then 'NFT Apps'
else category
end as category,
sub_category
sub_category,
modified_timestamp as last_updated
from filtered_address
8 changes: 5 additions & 3 deletions models/dimensions/contracts/dim_flipside_solana_contracts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ with
then 'Bridge'
else null
end as category,
label_subtype as sub_category
label_subtype as sub_category,
modified_timestamp
from solana_flipside.core.dim_labels as labels
),
manual_filter as (
Expand All @@ -47,9 +48,10 @@ with
case
when namespace = 'wormhole' then 'Bridge' else category
end as category,
sub_category
sub_category,
modified_timestamp
from solana_labels
where namespace is not null and namespace <> ''
)
select address, chain, name, namespace, category, sub_category
select address, chain, name, namespace, category, sub_category, modified_timestamp as last_updated
from manual_filter
37 changes: 37 additions & 0 deletions models/dimensions/labeling/dim_all_addresses_silver.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{
config(
materialized="incremental",
unique_key=["address", "chain", "source"],
incremental_strategy="merge",
)
}}

-- There will inevitably be addres + chain duplicates, but we will take care of this downstream when we don't care about the source anymore
with unioned_table as (
SELECT address, chain, 'sigma' AS source, OBJECT_CONSTRUCT(
'name', name
) AS metadata,
last_updated
FROM {{ ref("dim_legacy_sigma_tagged_contracts") }}
UNION ALL
SELECT address, chain, 'dune' AS source, OBJECT_CONSTRUCT(
'name', name
) AS metadata,
last_updated
FROM {{ ref("dim_dune_contracts") }}
UNION ALL
SELECT address, chain, 'sui' AS source, OBJECT_CONSTRUCT(
'name', name, 'icon', icon
) AS metadata,
last_updated
FROM {{ ref("dim_sui_contracts") }}
UNION ALL
SELECT address, chain, 'flipside' AS source, OBJECT_CONSTRUCT(
'name', name
) AS metadata,
last_updated
FROM {{ ref("dim_flipside_contracts") }}
) select * from unioned_table
{% if is_incremental() %}
where last_updated > (SELECT MAX(last_updated) FROM {{ this }})
{% endif %}
Empty file.
Empty file.
8 changes: 5 additions & 3 deletions models/dimensions/token_types/arb_token_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ with
)
then 'NFT'
else 'Token'
end as token_standard
end as token_standard,
modified_timestamp
from arbitrum_flipside.core.fact_event_logs
where
lower(topics[0]) in (
Expand All @@ -36,14 +37,15 @@ with
coalesce(a.address, l.address, c.address, null) address,
coalesce(l.address_name, c.name, null) name,
coalesce(l.project_name, c.symbol, null) namespace,
coalesce(a.token_standard, null) category
coalesce(a.token_standard, null) category,
modified_timestamp
from contract_standard a
left join
arbitrum_flipside.core.dim_contracts c
on lower(a.address) = lower(c.address)
left join
arbitrum_flipside.core.dim_labels l on lower(a.address) = lower(l.address)
)
select address, max(name) name, max(namespace) namespace, max(category) category
select address, max(name) name, max(namespace) namespace, max(category) category, max(modified_timestamp) as last_updated
from flipside_labels
group by address
8 changes: 5 additions & 3 deletions models/dimensions/token_types/avax_token_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ with
)
then 'NFT'
else 'Token'
end as token_standard
end as token_standard,
modified_timestamp
from avalanche_flipside.core.fact_event_logs
where
lower(topics[0]) in (
Expand All @@ -36,14 +37,15 @@ with
coalesce(a.address, l.address, c.address, null) address,
coalesce(l.address_name, c.name, null) name,
coalesce(l.project_name, c.symbol, null) namespace,
coalesce(a.token_standard, null) category
coalesce(a.token_standard, null) category,
modified_timestamp
from contract_standard a
left join
avalanche_flipside.core.dim_contracts c
on lower(a.address) = lower(c.address)
left join
avalanche_flipside.core.dim_labels l on lower(a.address) = lower(l.address)
)
select address, max(name) name, max(namespace) namespace, max(category) category
select address, max(name) name, max(namespace) namespace, max(category) category, max(modified_timestamp) as last_updated
from flipside_labels
group by address
8 changes: 5 additions & 3 deletions models/dimensions/token_types/base_token_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ with
)
then 'NFT'
else 'Token'
end as token_standard
end as token_standard,
modified_timestamp
from base_flipside.core.fact_event_logs
where
lower(topics[0]) in (
Expand All @@ -36,12 +37,13 @@ with
coalesce(a.address, l.address, c.address, null) address,
coalesce(l.address_name, c.name, null) name,
coalesce(l.project_name, c.symbol, null) namespace,
coalesce(a.token_standard, null) category
coalesce(a.token_standard, null) category,
modified_timestamp
from contract_standard a
left join
base_flipside.core.dim_contracts c on lower(a.address) = lower(c.address)
left join base_flipside.core.dim_labels l on lower(a.address) = lower(l.address)
)
select address, max(name) name, max(namespace) namespace, max(category) category
select address, max(name) name, max(namespace) namespace, max(category) category, max(modified_timestamp) as last_updated
from flipside_labels
group by address
8 changes: 5 additions & 3 deletions models/dimensions/token_types/bsc_token_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ with
)
then 'NFT'
else 'Token'
end as token_standard
end as token_standard,
modified_timestamp
from bsc_flipside.core.fact_event_logs
where
lower(topics[0]) in (
Expand All @@ -36,12 +37,13 @@ with
coalesce(a.address, l.address, c.address, null) address,
coalesce(l.address_name, c.name, null) name,
coalesce(l.project_name, c.symbol, null) namespace,
coalesce(a.token_standard, null) category
coalesce(a.token_standard, null) category,
modified_timestamp
from contract_standard a
left join
bsc_flipside.core.dim_contracts c on lower(a.address) = lower(c.address)
left join bsc_flipside.core.dim_labels l on lower(a.address) = lower(l.address)
)
select address, max(name) name, max(namespace) namespace, max(category) category
select address, max(name) name, max(namespace) namespace, max(category) category, max(modified_timestamp) as last_updated
from flipside_labels
group by address
8 changes: 5 additions & 3 deletions models/dimensions/token_types/eth_token_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ with
)
then 'NFT'
else 'Token'
end as token_standard
end as token_standard,
modified_timestamp
from ethereum_flipside.core.fact_event_logs
where
lower(topics[0]) in (
Expand All @@ -36,14 +37,15 @@ with
coalesce(a.address, l.address, c.address, null) address,
coalesce(l.address_name, c.name, null) name,
coalesce(l.label, c.symbol, null) namespace,
coalesce(a.token_standard, null) category
coalesce(a.token_standard, null) category,
modified_timestamp
from contract_standard a
left join
ethereum_flipside.core.dim_contracts c
on lower(a.address) = lower(c.address)
left join
ethereum_flipside.core.dim_labels l on lower(a.address) = lower(l.address)
)
select address, max(name) name, max(namespace) namespace, max(category) category
select address, max(name) name, max(namespace) namespace, max(category) category, max(modified_timestamp) as last_updated
from flipside_labels
group by address
8 changes: 5 additions & 3 deletions models/dimensions/token_types/opt_token_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ with
)
then 'NFT'
else 'Token'
end as token_standard
end as token_standard,
modified_timestamp
from optimism_flipside.core.fact_event_logs
where
lower(topics[0]) in (
Expand All @@ -36,14 +37,15 @@ with
coalesce(a.address, l.address, c.address, null) address,
coalesce(l.address_name, c.name, null) name,
coalesce(l.project_name, c.symbol, null) namespace,
coalesce(a.token_standard, null) category
coalesce(a.token_standard, null) category,
modified_timestamp
from contract_standard a
left join
optimism_flipside.core.dim_contracts c
on lower(a.address) = lower(c.address)
left join
optimism_flipside.core.dim_labels l on lower(a.address) = lower(l.address)
)
select address, max(name) name, max(namespace) namespace, max(category) category
select address, max(name) name, max(namespace) namespace, max(category) category, max(modified_timestamp) as last_updated
from flipside_labels
group by address
Loading

0 comments on commit 68e9d90

Please sign in to comment.