Skip to content

Commit ab80c50

Browse files
ENS Spells Migration (#1245)
Height Task: https://dune.height.app/T-13877 *For Dune Engine V2* I've checked that: * [x] I tested the query on dune.com after compiling the model with dbt compile (compiled queries are written to the target directory) * [x] I used "refs" to reference other models in this repo and "sources" to reference raw or decoded tables * [x] if adding a new model, I added a test * [x] the filename is unique and ends with .sql * [x] each sql file is a select statement and has only one view, table or function defined * [x] column names are `lowercase_snake_cased` When you are ready for a review, tag duneanalytics/data-experience. We will re-open your forked pull request as an internal pull request. Then your spells will run in dbt and the logs will be avaiable in Github Actions DBT Slim CI. This job will only run the models and tests changed by your PR compared to the production project.
1 parent 82d9870 commit ab80c50

16 files changed

+4308
-1
lines changed

Diff for: spellbook/dbt_project.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ clean-targets: # directories to be removed by `dbt clean`
2626
# Full documentation: https://docs.getdbt.com/docs/configuring-models
2727
models:
2828
spellbook:
29+
ens:
30+
+schema: ens
31+
+materialized: view
2932
nft:
3033
+schema: nft
3134
+materialized: view
@@ -126,5 +129,7 @@ seeds:
126129
block_time: timestamp
127130
tx_hash: string
128131
amount: string
129-
132+
ens:
133+
+enabled: true
134+
+schema: test_data
130135

Diff for: spellbook/macros/alter_table_properties.sql

+40
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,42 @@ ALTER VIEW seaport_ethereum.view_transactions SET TBLPROPERTIES('dune.public'='t
181181
'dune.data_explorer.contributors'='["sohawk","soispoke"]');
182182
{% endset %}
183183

184+
{% set ens_view_expirations %}
185+
ALTER VIEW ens.view_expirations SET TBLPROPERTIES('dune.public'='true',
186+
'dune.data_explorer.blockchains'='["ethereum"]',
187+
'dune.data_explorer.category'='abstraction',
188+
'dune.data_explorer.abstraction.type'='project',
189+
'dune.data_explorer.abstraction.name'='ens',
190+
'dune.data_explorer.contributors'='["antonio-mendes","mewwts"]');
191+
{% endset %}
192+
193+
{% set ens_view_registrations %}
194+
ALTER VIEW ens.view_registrations SET TBLPROPERTIES('dune.public'='true',
195+
'dune.data_explorer.blockchains'='["ethereum"]',
196+
'dune.data_explorer.category'='abstraction',
197+
'dune.data_explorer.abstraction.type'='project',
198+
'dune.data_explorer.abstraction.name'='ens',
199+
'dune.data_explorer.contributors'='["antonio-mendes","mewwts"]');
200+
{% endset %}
201+
202+
{% set ens_view_registries %}
203+
ALTER VIEW ens.view_registries SET TBLPROPERTIES('dune.public'='true',
204+
'dune.data_explorer.blockchains'='["ethereum"]',
205+
'dune.data_explorer.category'='abstraction',
206+
'dune.data_explorer.abstraction.type'='project',
207+
'dune.data_explorer.abstraction.name'='ens',
208+
'dune.data_explorer.contributors'='["antonio-mendes","mewwts"]');
209+
{% endset %}
210+
211+
{% set ens_view_renewals %}
212+
ALTER VIEW ens.view_renewals SET TBLPROPERTIES('dune.public'='true',
213+
'dune.data_explorer.blockchains'='["ethereum"]',
214+
'dune.data_explorer.category'='abstraction',
215+
'dune.data_explorer.abstraction.type'='project',
216+
'dune.data_explorer.abstraction.name'='ens',
217+
'dune.data_explorer.contributors'='["antonio-mendes","mewwts"]');
218+
{% endset %}
219+
184220
{% do run_query(balances_ethereum_erc20_day) %}
185221
{% do run_query(balances_ethereum_erc20_hour) %}
186222
{% do run_query(balances_ethereum_erc20_latest) %}
@@ -201,6 +237,10 @@ ALTER VIEW seaport_ethereum.view_transactions SET TBLPROPERTIES('dune.public'='t
201237
{% do run_query(tokens_ethereum_nft) %}
202238
{% do run_query(seaport_ethereum_view_transactions) %}
203239
{% do run_query(uniswap_trades) %}
240+
{% do run_query(ens_view_expirations) %}
241+
{% do run_query(ens_view_registrations) %}
242+
{% do run_query(ens_view_registries) %}
243+
{% do run_query(ens_view_renewals) %}
204244

205245
{% do log("Tables generated", info=True) %}
206246
{%- else -%}

Diff for: spellbook/models/ens/ens_ethereum_schema.yml

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
version: 2
2+
3+
models:
4+
- name: ens_view_expirations
5+
meta:
6+
blockchain: ethereum
7+
project: ethereum_name_service
8+
contributors: mewwts, antonio-mendes
9+
config:
10+
tags: ['ethereum','ens','ethereum_name_service','ethereumnameservice']
11+
description: >
12+
View expirations of ENS registrations
13+
columns:
14+
- &label
15+
name: label
16+
description: "Hashed individual component of ENS name"
17+
- name: min_expires
18+
description: "Minimum expiration date UTC for domain"
19+
- name: max_expires
20+
description: "Maximum expiration date UTC for domain"
21+
- name: min_evt_block_time
22+
description: "Block time UTC of first name registration"
23+
- name: max_evt_block_time
24+
description: "Block time UTC of last name renewal"
25+
- name: count
26+
description: "Number of times expiration was extended"
27+
28+
- name: ens_view_registrations
29+
meta:
30+
blockchain: ethereum
31+
project: ethereum_name_service
32+
contributors: mewwts, antonio-mendes
33+
config:
34+
tags: ['ethereum','ens','ethereum_name_service','ethereumnameservice']
35+
description: >
36+
View ENS registrations
37+
columns:
38+
- *label
39+
- &name
40+
name: name
41+
description: "Name component of ENS"
42+
- name: owner
43+
description: "Address that owns the ENS name"
44+
- &cost
45+
name: cost
46+
description: "Registration cost in Wei"
47+
- &expires
48+
name: expires
49+
description: "Expiry data in epoch time"
50+
- &contract_address
51+
name: contract_address
52+
description: "Address of smart contract interacted with"
53+
- &evt_tx_hash
54+
name: evt_tx_hash
55+
description: "Transaction hash"
56+
- &evt_index
57+
name: evt_index
58+
description: "Index of event in transaction"
59+
- &evt_block_time
60+
name: evt_block_time
61+
description: "Block time UTC"
62+
- &evt_block_number
63+
name: evt_block_number
64+
description: "Block number"
65+
66+
- name: ens_view_renewals
67+
meta:
68+
blockchain: ethereum
69+
project: ethereum_name_service
70+
contributors: mewwts, antonio-mendes
71+
config:
72+
tags: ['ethereum','ens','ethereum_name_service','ethereumnameservice']
73+
description: >
74+
View ENS renewals
75+
columns:
76+
- *name
77+
- *label
78+
- *cost
79+
- *expires
80+
- *contract_address
81+
- *evt_tx_hash
82+
- *evt_index
83+
- *evt_block_time
84+
- *evt_block_number
85+
86+
- name: ens_view_registries
87+
meta:
88+
blockchain: ethereum
89+
project: ethereum_name_service
90+
contributors: mewwts, antonio-mendes
91+
config:
92+
tags: ['ethereum','ens','ethereum_name_service','ethereumnameservice']
93+
description: >
94+
View ENS registry
95+
columns:
96+
- *label
97+
- name: node
98+
description: "A cryptographic hash uniquely identifying a name"
99+
- name: min_evt_block_time
100+
description: "Block time UTC of first registry for node"
101+
- name: max_evt_block_time
102+
description: "Block time UTC of latest registry for node"
103+
- name: count
104+
description: "Total number of node registries"

Diff for: spellbook/models/ens/ens_ethereum_sources.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: 2
2+
3+
sources:
4+
- name: ethereumnameservice_ethereum
5+
freshness:
6+
warn_after: { count: 12, period: hour }
7+
error_after: { count: 24, period: hour }
8+
tables:
9+
- name: BaseRegistrarImplementation_evt_NameRegistered
10+
loaded_at_field: evt_block_time
11+
- name: BaseRegistrarImplementation_evt_NameRenewed
12+
loaded_at_field: evt_block_time
13+
- name: ETHRegistrarController_1_evt_NameRegistered
14+
loaded_at_field: evt_block_time
15+
- name: ETHRegistrarController_2_evt_NameRegistered
16+
loaded_at_field: evt_block_time
17+
- name: ETHRegistrarController_3_evt_NameRegistered
18+
loaded_at_field: evt_block_time
19+
- name: ENSRegistry_evt_NewOwner
20+
loaded_at_field: evt_block_time
21+
- name: ENSRegistryWithFallback_evt_NewOwner
22+
loaded_at_field: evt_block_time
23+
- name: ETHRegistrarController_1_evt_NameRenewed
24+
loaded_at_field: evt_block_time
25+
- name: ETHRegistrarController_2_evt_NameRenewed
26+
loaded_at_field: evt_block_time
27+
- name: ETHRegistrarController_3_evt_NameRenewed
28+
loaded_at_field: evt_block_time

Diff for: spellbook/models/ens/ens_view_expirations.sql

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{config(alias='view_expirations')}}
2+
SELECT
3+
label,
4+
TO_TIMESTAMP(min(expires)) AS min_expires,
5+
min(evt_block_time) AS min_evt_block_time,
6+
TO_TIMESTAMP(max(expires)) AS max_expires,
7+
max(evt_block_time) AS max_evt_block_time,
8+
count(*) AS count
9+
FROM (
10+
SELECT
11+
numeric2bytea(id) AS label,
12+
expires,
13+
evt_block_time
14+
FROM {{source('ethereumnameservice_ethereum', 'BaseRegistrarImplementation_evt_NameRegistered')}}
15+
UNION
16+
SELECT
17+
numeric2bytea(id) AS label,
18+
expires,
19+
evt_block_time
20+
FROM {{source('ethereumnameservice_ethereum', 'BaseRegistrarImplementation_evt_NameRenewed')}}
21+
) AS r
22+
GROUP BY label;

Diff for: spellbook/models/ens/ens_view_registrations.sql

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{config(alias='view_registrations')}}
2+
SELECT *
3+
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_1_evt_NameRegistered')}}
4+
UNION
5+
SELECT *
6+
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_2_evt_NameRegistered')}}
7+
UNION
8+
SELECT *
9+
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_3_evt_NameRegistered')}}

Diff for: spellbook/models/ens/ens_view_registries.sql

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{config(alias='view_registries')}}
2+
SELECT
3+
node,
4+
label,
5+
min(evt_block_time) AS min_evt_block_time,
6+
max(evt_block_time) AS max_evt_block_time,
7+
count(*) as count_ens_registries
8+
FROM (
9+
SELECT *
10+
FROM {{source('ethereumnameservice_ethereum', 'ENSRegistry_evt_NewOwner')}}
11+
UNION
12+
SELECT * FROM {{source('ethereumnameservice_ethereum', 'ENSRegistryWithFallback_evt_NewOwner')}}
13+
) r
14+
GROUP BY node, label;

Diff for: spellbook/models/ens/ens_view_renewals.sql

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{config(alias='view_renewals')}}
2+
SELECT *
3+
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_1_evt_NameRenewed')}}
4+
UNION
5+
SELECT *
6+
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_2_evt_NameRenewed')}}
7+
UNION
8+
SELECT *
9+
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_3_evt_NameRenewed')}};

0 commit comments

Comments
 (0)