Skip to content

Commit

Permalink
Daily spellbook account abstractions (#6036)
Browse files Browse the repository at this point in the history
* Move account abstraction files and add schemas

* Move and enable seeds

* Drop schema in dbt_project.yml

* Make tests run

* Fix tests

Seems like these unfortunately need to be duplicated for now. DBT assumes they are under tests/generic

* Add schema to model

* Use incremental_predicate macro in models

* Update macros to use incremental_predicate
  • Loading branch information
aalan3 authored May 30, 2024
1 parent 6005396 commit 788df05
Show file tree
Hide file tree
Showing 74 changed files with 218 additions and 136 deletions.
7 changes: 4 additions & 3 deletions daily_spellbook/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ vars:
# You don't need to change these!
model-paths: ["models", "../sources"]
analysis-paths: ["analyses"]
# ../tests/* should be added to a separate shared folder
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["../macros"]
Expand All @@ -43,9 +44,9 @@ tests:
# For configuring individual seeds (e.g. overriding column types) we recommend a yml file nested in the same folder as the seed
# example: seeds/cryptopunks/schema.yml
# TODO: uncomment when seeds are added
# seeds:
# daily_spellbook:
# +schema: test_data
seeds:
daily_spellbook:
+schema: test_data

# defining search order of macro invokation
dispatch:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ config(
alias = 'account_deployed',

schema = 'account_abstraction_erc4337_arbitrum',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand All @@ -18,7 +18,7 @@
, ref('account_abstraction_erc4337_arbitrum_v0_6_account_deployed')
] %}

SELECT
SELECT
blockchain
, version
, block_time
Expand All @@ -31,7 +31,7 @@ SELECT
, factory
FROM (
{% for erc4337_model in erc4337_base_models %}
SELECT
SELECT
blockchain
, version
, block_time
Expand All @@ -43,9 +43,9 @@ FROM (
, paymaster
, factory
FROM {{ erc4337_model }}

{% if is_incremental() %}
WHERE block_time >= date_trunc('day', now() - interval '7' day)
WHERE {{ incremental_predicate('block_time') }}
{% endif %}

{% if not loop.last %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ config(
alias = 'userops',

schema = 'account_abstraction_erc4337_arbitrum',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand All @@ -27,7 +27,7 @@ with userop as(
SELECT *
FROM (
{% for erc4337_model in erc4337_models %}
SELECT
SELECT
blockchain
, version
, block_month
Expand All @@ -42,16 +42,16 @@ with userop as(
, beneficiary
FROM {{ erc4337_model }}
{% if is_incremental() %}
WHERE block_time >= date_trunc('day', now() - interval '7' day)
WHERE {{ incremental_predicate('block_time') }}
{% endif %}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
{% endfor %}
)
)
, txs as (
select
select
hash as tx_hash
, tx."from" as tx_from
, tx.to as tx_to
Expand All @@ -63,11 +63,11 @@ with userop as(
)
and block_time > date '{{deployed_date}}'
{% if is_incremental() %}
and block_time >= date_trunc('day', now() - interval '7' day)
and {{ incremental_predicate('block_time') }}
{% endif %}
)
, price as (
select symbol, decimals, minute, price
select symbol, decimals, minute, price
from {{source('prices','usd')}}
where minute > date '{{deployed_date}}'
and contract_address={{wrapped_gas_address}}
Expand All @@ -76,7 +76,7 @@ with userop as(
and minute >= date_trunc('day', now() - interval '7' day)
{% endif %}
)
select
select
userop.blockchain
, userop.version
, userop.block_month
Expand All @@ -95,6 +95,6 @@ select
, txs.tx_fee
, txs.tx_fee * price.price as tx_fee_usd
, userop.beneficiary
from userop
from userop
left join txs on userop.tx_hash = txs.tx_hash
left join price on date_trunc('minute', userop.block_time) = price.minute
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{ config
(
alias = 'v0_5_account_deployed',

schema = 'account_abstraction_erc4337_arbitrum',

partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{ config
(
alias = 'v0_5_userops_basics',

schema = 'account_abstraction_erc4337_arbitrum',

partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{ config
(
alias = 'v0_6_account_deployed',

schema = 'account_abstraction_erc4337_arbitrum',

partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config
(
alias = 'v0_6_userops_basics',

schema = 'account_abstraction_erc4337_arbitrum',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ config(
alias = 'account_deployed',


schema = 'account_abstraction_erc4337_avalanche_c',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand All @@ -18,7 +19,7 @@
, ref('account_abstraction_erc4337_avalanche_c_v0_6_account_deployed')
] %}

SELECT
SELECT
blockchain
, version
, block_time
Expand All @@ -31,7 +32,7 @@ SELECT
, factory
FROM (
{% for erc4337_model in erc4337_base_models %}
SELECT
SELECT
blockchain
, version
, block_time
Expand All @@ -43,9 +44,9 @@ FROM (
, paymaster
, factory
FROM {{ erc4337_model }}

{% if is_incremental() %}
WHERE block_time >= date_trunc('day', now() - interval '7' day)
WHERE {{ incremental_predicate('block_time') }}
{% endif %}

{% if not loop.last %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ config(
alias = 'userops',

schema = 'account_abstraction_erc4337_avalanche_c',

partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{ config
(
alias = 'v0_5_account_deployed',

schema = 'account_abstraction_erc4337_avalanche_c',

partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ config(
alias = 'v0_5_userops_basics',

schema = 'account_abstraction_erc4337_avalanche_c',

partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{ config
(
alias = 'v0_6_account_deployed',

schema = 'account_abstraction_erc4337_avalanche_c',

partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ config(
alias = 'v0_6_userops_basics',

schema = 'account_abstraction_erc4337_avalanche_c',

partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ config(
alias = 'account_deployed',

schema = 'account_abstraction_erc4337_base',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand All @@ -18,7 +18,7 @@
, ref('account_abstraction_erc4337_base_v0_7_account_deployed')
] %}

SELECT
SELECT
blockchain
, version
, block_time
Expand All @@ -31,7 +31,7 @@ SELECT
, factory
FROM (
{% for erc4337_model in erc4337_base_models %}
SELECT
SELECT
blockchain
, version
, block_time
Expand All @@ -43,9 +43,9 @@ FROM (
, paymaster
, factory
FROM {{ erc4337_model }}

{% if is_incremental() %}
WHERE block_time >= date_trunc('day', now() - interval '7' day)
WHERE {{ incremental_predicate('block_time') }}
{% endif %}

{% if not loop.last %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ config(
alias = 'userops',

schema = 'account_abstraction_erc4337_base',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand All @@ -16,7 +16,7 @@
{% set chain = 'base' %}
{% set gas_symbol = 'ETH' %}
--currently, base chain price data is not integrated in Dune, use optimism instead
{% set wrapped_gas_address = '0x4200000000000000000000000000000000000006' %}
{% set wrapped_gas_address = '0x4200000000000000000000000000000000000006' %}
{% set deployed_date = '2023-02-15' %}

{% set erc4337_models = [
Expand All @@ -28,7 +28,7 @@ with userop as(
SELECT *
FROM (
{% for erc4337_model in erc4337_models %}
SELECT
SELECT
blockchain
, version
, block_month
Expand All @@ -43,41 +43,41 @@ with userop as(
, beneficiary
FROM {{ erc4337_model }}
{% if is_incremental() %}
WHERE block_time >= date_trunc('day', now() - interval '7' day)
WHERE {{ incremental_predicate('block_time') }}
{% endif %}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
{% endfor %}
)
)
, txs as (
select
select
hash as tx_hash
, tx."from" as tx_from
, tx.to as tx_to
, '{{gas_symbol}}' as gas_symbol
, ((cast(gas_used as double) * gas_price)+l1_fee) / 1e18 as tx_fee
, ((cast(gas_used as double) * gas_price)+l1_fee) / 1e18 as tx_fee
from {{ source('base', 'transactions') }} tx
where hash in (
select tx_hash from userop
)
and block_time > date '{{deployed_date}}'
{% if is_incremental() %}
and block_time >= date_trunc('day', now() - interval '7' day)
and {{ incremental_predicate('block_time') }}
{% endif %}
)
, price as (
select symbol, decimals, minute, price
select symbol, decimals, minute, price
from {{source('prices','usd')}}
where minute > date '{{deployed_date}}'
where minute > date '{{deployed_date}}'
and contract_address={{wrapped_gas_address}}
and blockchain='optimism'
{% if is_incremental() %}
and minute >= date_trunc('day', now() - interval '7' day)
{% endif %}
)
select
select
userop.blockchain
, userop.version
, userop.block_month
Expand All @@ -96,6 +96,6 @@ select
, txs.tx_fee
, txs.tx_fee * price.price as tx_fee_usd
, userop.beneficiary
from userop
from userop
left join txs on userop.tx_hash = txs.tx_hash
left join price on date_trunc('minute', userop.block_time) = price.minute
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config
(
alias = 'v0_6_account_deployed',

schema = 'account_abstraction_erc4337_base',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{ config
(
alias = 'v0_6_userops_basics',

schema = 'account_abstraction_erc4337_base',

partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down
Loading

0 comments on commit 788df05

Please sign in to comment.