-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Potential Bot Logic Macro, staging and int tables (#1705)
* add bot logic macro * add macro and stg tables * update macro and remove op and arbitrum for now * nits
- Loading branch information
Showing
9 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{% macro potential_bots(network_name) %} | ||
|
||
with sender_transfer_rates as ( | ||
select | ||
'{{ network_name }}' as chain_name | ||
,date_trunc(block_timestamp, hour) as hr | ||
,from_address as sender | ||
,min(block_timestamp) as min_block_time | ||
,max(block_timestamp) as max_block_time | ||
,count(*) as hr_txs | ||
from {{ source(network_name, "transactions") }} | ||
where | ||
gas_price > 0 | ||
and receipt_gas_used > 0 | ||
group by 1, 2, 3 | ||
) | ||
|
||
,first_pass_throughput_filter as ( | ||
select | ||
chain_name, | ||
sender, | ||
date_trunc(hr, week) as wk, | ||
sum(hr_txs) as wk_txs, | ||
max(hr_txs) as max_hr_txs, | ||
cast(count(*) as float64) / cast(7.0 * 24.0 as float64) as pct_weekly_hours_active, | ||
min(min_block_time) as min_block_time, | ||
max(max_block_time) as max_block_time | ||
from sender_transfer_rates | ||
group by 1, 2, 3 | ||
having | ||
max(hr_txs) >= 20 | ||
or cast(count(*) as float64) / cast(7.0 * 24.0 as float64) >= 0.5 | ||
) | ||
,aggregated_data as ( | ||
select | ||
chain_name, | ||
sender as address, | ||
max(wk_txs) as max_wk_txs, | ||
max(max_hr_txs) as max_hr_txs, | ||
avg(wk_txs) as avg_wk_txs, | ||
min(min_block_time) as min_block_time, | ||
max(max_block_time) as max_block_time, | ||
max(pct_weekly_hours_active) as max_pct_weekly_hours_active, | ||
avg(pct_weekly_hours_active) as avg_pct_weekly_hours_active, | ||
sum(wk_txs) as num_txs | ||
from first_pass_throughput_filter | ||
group by 1, 2 | ||
) | ||
select | ||
*, | ||
(cast(timestamp_diff(max_block_time, min_block_time, second) as float64) / (60.0 * 60.0)) as txs_per_hour | ||
from aggregated_data | ||
where | ||
( max_wk_txs >= 2000 and max_hr_txs >= 100 ) | ||
or ( max_wk_txs >= 4000 and max_hr_txs >= 50 ) | ||
or avg_wk_txs >= 1000 | ||
or ( | ||
(cast(timestamp_diff(max_block_time, min_block_time, second) as float64) / (60.0 * 60.0)) >= 25 | ||
and num_txs >= 100 | ||
) | ||
or avg_pct_weekly_hours_active > 0.5 | ||
or max_pct_weekly_hours_active > 0.95 | ||
|
||
{% endmacro %} |
19 changes: 19 additions & 0 deletions
19
warehouse/dbt/models/intermediate/directory/int_potential_bots.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% set network_names = [ | ||
'base', | ||
'ethereum', | ||
'frax', | ||
'metal', | ||
'mode', | ||
'pgn', | ||
'zora' | ||
] %} -- | ||
|
||
{% for network_name in network_names %} | ||
|
||
select * from {{ ref('stg_%s__potential_bots' % network_name) }} | ||
|
||
{% if not loop.last %} | ||
union all | ||
{% endif %} | ||
|
||
{% endfor %} |
12 changes: 12 additions & 0 deletions
12
warehouse/dbt/models/staging/base/stg_base__potential_bots.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{ config( | ||
materialized='table', | ||
partition_by={ | ||
"field": "min_block_time", | ||
"data_type": "timestamp", | ||
"granularity": "day", | ||
}, | ||
) }} | ||
|
||
{{ | ||
potential_bots("base") | ||
}} |
12 changes: 12 additions & 0 deletions
12
warehouse/dbt/models/staging/ethereum/stg_ethereum__potential_bots.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{ config( | ||
materialized='table', | ||
partition_by={ | ||
"field": "min_block_time", | ||
"data_type": "timestamp", | ||
"granularity": "day", | ||
}, | ||
) }} | ||
|
||
{{ | ||
potential_bots("ethereum") | ||
}} |
12 changes: 12 additions & 0 deletions
12
warehouse/dbt/models/staging/frax/stg_frax__potential_bots.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{ config( | ||
materialized='table', | ||
partition_by={ | ||
"field": "min_block_time", | ||
"data_type": "timestamp", | ||
"granularity": "day", | ||
}, | ||
) }} | ||
|
||
{{ | ||
potential_bots("frax") | ||
}} |
12 changes: 12 additions & 0 deletions
12
warehouse/dbt/models/staging/metal/stg_metal__potential_bots.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{ config( | ||
materialized='table', | ||
partition_by={ | ||
"field": "min_block_time", | ||
"data_type": "timestamp", | ||
"granularity": "day", | ||
}, | ||
) }} | ||
|
||
{{ | ||
potential_bots("metal") | ||
}} |
12 changes: 12 additions & 0 deletions
12
warehouse/dbt/models/staging/mode/stg_mode__potential_bots.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{ config( | ||
materialized='table', | ||
partition_by={ | ||
"field": "min_block_time", | ||
"data_type": "timestamp", | ||
"granularity": "day", | ||
}, | ||
) }} | ||
|
||
{{ | ||
potential_bots("mode") | ||
}} |
12 changes: 12 additions & 0 deletions
12
warehouse/dbt/models/staging/pgn/stg_pgn__potential_bots.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{ config( | ||
materialized='table', | ||
partition_by={ | ||
"field": "min_block_time", | ||
"data_type": "timestamp", | ||
"granularity": "day", | ||
}, | ||
) }} | ||
|
||
{{ | ||
potential_bots("pgn") | ||
}} |
12 changes: 12 additions & 0 deletions
12
warehouse/dbt/models/staging/zora/stg_zora__potential_bots.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{ config( | ||
materialized='table', | ||
partition_by={ | ||
"field": "min_block_time", | ||
"data_type": "timestamp", | ||
"granularity": "day", | ||
}, | ||
) }} | ||
|
||
{{ | ||
potential_bots("zora") | ||
}} |