Skip to content

Commit

Permalink
Add arbitrum for good measure
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenac95 committed Mar 27, 2024
1 parent 18dbe62 commit 4c27297
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 37 deletions.
40 changes: 40 additions & 0 deletions warehouse/dbt/macros/models/goog_blockchain_deployers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{#
Using goog_blockchain_* public tables, this discovers deployers on a given network.
#}

{% macro goog_blockchain_deployers(network_name) %}
WITH {% if is_incremental() %} max_block_timestamp AS (
SELECT MAX(block_timestamp)
FROM {{ this }}
),
{% endif %}
logs AS (
-- transactions
SELECT *
FROM {{ oso_source(network_name, "logs") }}
{% if is_incremental() %}
WHERE
block_timestamp >= (
SELECT * FROM max_block_timestamp
)
AND block_timestamp < TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY)
{% endif %}
)

SELECT
t.block_timestamp AS block_timestamp,
t.transaction_hash AS transaction_hash,
t.from_address AS deployer_address,
l.address AS contract_address
FROM {{ oso_source(network_name, "transactions") }} AS t
INNER JOIN logs AS l
ON t.transaction_hash = l.transaction_hash
WHERE
t.to_address IS null
{% if is_incremental() %}
AND t.block_timestamp >= (
SELECT * FROM max_block_timestamp
)
AND t.block_timestamp < TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY)
{% endif %}
{% endmacro %}
12 changes: 12 additions & 0 deletions warehouse/dbt/models/arbitrum_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sources:
- name: arbitrum

database: bigquery-public-data

schema: goog_blockchain_arbitrum_one_us
tables:
- name: transactions
identifier: transactions

- name: logs
identifier: logs
13 changes: 13 additions & 0 deletions warehouse/dbt/models/playground/arbitrum__logs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{
config(
materialized='table',
) if target.name in ['playground', 'dev'] else config(
enabled=false,
)
}}
SELECT *
FROM {{ source("arbitrum", 'logs') }}
WHERE block_timestamp >= TIMESTAMP_TRUNC(
TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL -14 DAY),
DAY
)
13 changes: 13 additions & 0 deletions warehouse/dbt/models/playground/arbitrum__transactions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{
config(
materialized='table',
) if target.name in ['playground', 'dev'] else config(
enabled=false,
)
}}
SELECT *
FROM {{ source("arbitrum", 'transactions') }}
WHERE block_timestamp >= TIMESTAMP_TRUNC(
TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL -14 DAY),
DAY
)
16 changes: 16 additions & 0 deletions warehouse/dbt/models/staging/arbitrum/stg_arbitrum__deployers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{
config(
materialized='incremental',
partition_by={
"field": "block_timestamp",
"data_type": "timestamp",
"granularity": "day",
},
unique_id="transaction_hash",
on_schema_change="append_new_columns",
incremental_strategy="insert_overwrite"
) if target.name == 'production' else config(
materialized='table',
)
}}
{{ goog_blockchain_deployers("arbitrum") }}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ WHERE
AND receipt_status = 1
AND receipt_contract_address IS NOT NULL
{% if is_incremental() %}
AND TIMESTAMP_TRUNC(block_timestamp, DAY) >= (
SELECT TIMESTAMP_TRUNC(MAX(block_timestamp), DAY)
AND block_timestamp >= (
SELECT MAX(block_timestamp)
FROM {{ this }}
)
AND TIMESTAMP_TRUNC(block_timestamp, DAY) < CURRENT_TIMESTAMP()
AND block_timestamp < TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY)
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,4 @@
materialized='table',
)
}}
WITH {% if is_incremental() %} max_block_timestamp AS (
SELECT TIMESTAMP_TRUNC(MAX(block_timestamp), DAY)
FROM {{ this }}
),
{% endif %}
logs AS (
-- transactions
SELECT *
FROM {{ oso_source("optimism", "logs") }}
{% if is_incremental() %}
WHERE
TIMESTAMP_TRUNC(block_timestamp, DAY) >= (
SELECT * FROM max_block_timestamp
)
AND TIMESTAMP_TRUNC(block_timestamp, DAY) < CURRENT_TIMESTAMP()
{% endif %}
)

SELECT
t.block_timestamp AS block_timestamp,
t.transaction_hash AS transaction_hash,
t.from_address AS deployer_address,
l.address AS contract_address
FROM {{ oso_source("optimism", "transactions") }} AS t
INNER JOIN logs AS l
ON t.transaction_hash = l.transaction_hash
WHERE
t.to_address IS null
{% if is_incremental() %}
AND TIMESTAMP_TRUNC(t.block_timestamp, DAY) >= (
SELECT * FROM max_block_timestamp
)
AND TIMESTAMP_TRUNC(t.block_timestamp, DAY) < CURRENT_TIMESTAMP()
{% endif %}
{{ goog_blockchain_deployers("optimism") }}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ all_deployers AS (
*,
'MAINNET' AS network
FROM {{ ref("stg_ethereum__deployers") }}
UNION ALL
SELECT
*,
'ARBITRUM' AS network
FROM {{ ref("stg_arbitrum__deployers") }}
),

discovered_contracts AS (
Expand Down

0 comments on commit 4c27297

Please sign in to comment.