Skip to content

Commit

Permalink
ENS Spells Migration (#1245)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antonio-mendes authored Jul 6, 2022
1 parent 82d9870 commit ab80c50
Show file tree
Hide file tree
Showing 16 changed files with 4,308 additions and 1 deletion.
7 changes: 6 additions & 1 deletion spellbook/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ clean-targets: # directories to be removed by `dbt clean`
# Full documentation: https://docs.getdbt.com/docs/configuring-models
models:
spellbook:
ens:
+schema: ens
+materialized: view
nft:
+schema: nft
+materialized: view
Expand Down Expand Up @@ -126,5 +129,7 @@ seeds:
block_time: timestamp
tx_hash: string
amount: string

ens:
+enabled: true
+schema: test_data

40 changes: 40 additions & 0 deletions spellbook/macros/alter_table_properties.sql
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,42 @@ ALTER VIEW seaport_ethereum.view_transactions SET TBLPROPERTIES('dune.public'='t
'dune.data_explorer.contributors'='["sohawk","soispoke"]');
{% endset %}

{% set ens_view_expirations %}
ALTER VIEW ens.view_expirations SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.blockchains'='["ethereum"]',
'dune.data_explorer.category'='abstraction',
'dune.data_explorer.abstraction.type'='project',
'dune.data_explorer.abstraction.name'='ens',
'dune.data_explorer.contributors'='["antonio-mendes","mewwts"]');
{% endset %}

{% set ens_view_registrations %}
ALTER VIEW ens.view_registrations SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.blockchains'='["ethereum"]',
'dune.data_explorer.category'='abstraction',
'dune.data_explorer.abstraction.type'='project',
'dune.data_explorer.abstraction.name'='ens',
'dune.data_explorer.contributors'='["antonio-mendes","mewwts"]');
{% endset %}

{% set ens_view_registries %}
ALTER VIEW ens.view_registries SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.blockchains'='["ethereum"]',
'dune.data_explorer.category'='abstraction',
'dune.data_explorer.abstraction.type'='project',
'dune.data_explorer.abstraction.name'='ens',
'dune.data_explorer.contributors'='["antonio-mendes","mewwts"]');
{% endset %}

{% set ens_view_renewals %}
ALTER VIEW ens.view_renewals SET TBLPROPERTIES('dune.public'='true',
'dune.data_explorer.blockchains'='["ethereum"]',
'dune.data_explorer.category'='abstraction',
'dune.data_explorer.abstraction.type'='project',
'dune.data_explorer.abstraction.name'='ens',
'dune.data_explorer.contributors'='["antonio-mendes","mewwts"]');
{% endset %}

{% do run_query(balances_ethereum_erc20_day) %}
{% do run_query(balances_ethereum_erc20_hour) %}
{% do run_query(balances_ethereum_erc20_latest) %}
Expand All @@ -201,6 +237,10 @@ ALTER VIEW seaport_ethereum.view_transactions SET TBLPROPERTIES('dune.public'='t
{% do run_query(tokens_ethereum_nft) %}
{% do run_query(seaport_ethereum_view_transactions) %}
{% do run_query(uniswap_trades) %}
{% do run_query(ens_view_expirations) %}
{% do run_query(ens_view_registrations) %}
{% do run_query(ens_view_registries) %}
{% do run_query(ens_view_renewals) %}

{% do log("Tables generated", info=True) %}
{%- else -%}
Expand Down
104 changes: 104 additions & 0 deletions spellbook/models/ens/ens_ethereum_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
version: 2

models:
- name: ens_view_expirations
meta:
blockchain: ethereum
project: ethereum_name_service
contributors: mewwts, antonio-mendes
config:
tags: ['ethereum','ens','ethereum_name_service','ethereumnameservice']
description: >
View expirations of ENS registrations
columns:
- &label
name: label
description: "Hashed individual component of ENS name"
- name: min_expires
description: "Minimum expiration date UTC for domain"
- name: max_expires
description: "Maximum expiration date UTC for domain"
- name: min_evt_block_time
description: "Block time UTC of first name registration"
- name: max_evt_block_time
description: "Block time UTC of last name renewal"
- name: count
description: "Number of times expiration was extended"

- name: ens_view_registrations
meta:
blockchain: ethereum
project: ethereum_name_service
contributors: mewwts, antonio-mendes
config:
tags: ['ethereum','ens','ethereum_name_service','ethereumnameservice']
description: >
View ENS registrations
columns:
- *label
- &name
name: name
description: "Name component of ENS"
- name: owner
description: "Address that owns the ENS name"
- &cost
name: cost
description: "Registration cost in Wei"
- &expires
name: expires
description: "Expiry data in epoch time"
- &contract_address
name: contract_address
description: "Address of smart contract interacted with"
- &evt_tx_hash
name: evt_tx_hash
description: "Transaction hash"
- &evt_index
name: evt_index
description: "Index of event in transaction"
- &evt_block_time
name: evt_block_time
description: "Block time UTC"
- &evt_block_number
name: evt_block_number
description: "Block number"

- name: ens_view_renewals
meta:
blockchain: ethereum
project: ethereum_name_service
contributors: mewwts, antonio-mendes
config:
tags: ['ethereum','ens','ethereum_name_service','ethereumnameservice']
description: >
View ENS renewals
columns:
- *name
- *label
- *cost
- *expires
- *contract_address
- *evt_tx_hash
- *evt_index
- *evt_block_time
- *evt_block_number

- name: ens_view_registries
meta:
blockchain: ethereum
project: ethereum_name_service
contributors: mewwts, antonio-mendes
config:
tags: ['ethereum','ens','ethereum_name_service','ethereumnameservice']
description: >
View ENS registry
columns:
- *label
- name: node
description: "A cryptographic hash uniquely identifying a name"
- name: min_evt_block_time
description: "Block time UTC of first registry for node"
- name: max_evt_block_time
description: "Block time UTC of latest registry for node"
- name: count
description: "Total number of node registries"
28 changes: 28 additions & 0 deletions spellbook/models/ens/ens_ethereum_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2

sources:
- name: ethereumnameservice_ethereum
freshness:
warn_after: { count: 12, period: hour }
error_after: { count: 24, period: hour }
tables:
- name: BaseRegistrarImplementation_evt_NameRegistered
loaded_at_field: evt_block_time
- name: BaseRegistrarImplementation_evt_NameRenewed
loaded_at_field: evt_block_time
- name: ETHRegistrarController_1_evt_NameRegistered
loaded_at_field: evt_block_time
- name: ETHRegistrarController_2_evt_NameRegistered
loaded_at_field: evt_block_time
- name: ETHRegistrarController_3_evt_NameRegistered
loaded_at_field: evt_block_time
- name: ENSRegistry_evt_NewOwner
loaded_at_field: evt_block_time
- name: ENSRegistryWithFallback_evt_NewOwner
loaded_at_field: evt_block_time
- name: ETHRegistrarController_1_evt_NameRenewed
loaded_at_field: evt_block_time
- name: ETHRegistrarController_2_evt_NameRenewed
loaded_at_field: evt_block_time
- name: ETHRegistrarController_3_evt_NameRenewed
loaded_at_field: evt_block_time
22 changes: 22 additions & 0 deletions spellbook/models/ens/ens_view_expirations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{config(alias='view_expirations')}}
SELECT
label,
TO_TIMESTAMP(min(expires)) AS min_expires,
min(evt_block_time) AS min_evt_block_time,
TO_TIMESTAMP(max(expires)) AS max_expires,
max(evt_block_time) AS max_evt_block_time,
count(*) AS count
FROM (
SELECT
numeric2bytea(id) AS label,
expires,
evt_block_time
FROM {{source('ethereumnameservice_ethereum', 'BaseRegistrarImplementation_evt_NameRegistered')}}
UNION
SELECT
numeric2bytea(id) AS label,
expires,
evt_block_time
FROM {{source('ethereumnameservice_ethereum', 'BaseRegistrarImplementation_evt_NameRenewed')}}
) AS r
GROUP BY label;
9 changes: 9 additions & 0 deletions spellbook/models/ens/ens_view_registrations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{config(alias='view_registrations')}}
SELECT *
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_1_evt_NameRegistered')}}
UNION
SELECT *
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_2_evt_NameRegistered')}}
UNION
SELECT *
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_3_evt_NameRegistered')}}
14 changes: 14 additions & 0 deletions spellbook/models/ens/ens_view_registries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{config(alias='view_registries')}}
SELECT
node,
label,
min(evt_block_time) AS min_evt_block_time,
max(evt_block_time) AS max_evt_block_time,
count(*) as count_ens_registries
FROM (
SELECT *
FROM {{source('ethereumnameservice_ethereum', 'ENSRegistry_evt_NewOwner')}}
UNION
SELECT * FROM {{source('ethereumnameservice_ethereum', 'ENSRegistryWithFallback_evt_NewOwner')}}
) r
GROUP BY node, label;
9 changes: 9 additions & 0 deletions spellbook/models/ens/ens_view_renewals.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{config(alias='view_renewals')}}
SELECT *
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_1_evt_NameRenewed')}}
UNION
SELECT *
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_2_evt_NameRenewed')}}
UNION
SELECT *
FROM {{source('ethereumnameservice_ethereum', 'ETHRegistrarController_3_evt_NameRenewed')}};
Loading

0 comments on commit ab80c50

Please sign in to comment.