-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into Add-New-Event-Models-for-GMX-v2
- Loading branch information
Showing
160 changed files
with
6,132 additions
and
1,947 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_fees_evm.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,18 @@ | ||
{% macro metrics_fees_evm(blockchain) %} | ||
|
||
select | ||
blockchain | ||
, block_date | ||
, sum(tx_fee_usd) as gas_fees_usd | ||
from | ||
{{ source('gas', 'fees') }} | ||
where blockchain = '{{blockchain}}' | ||
{% if is_incremental() %} | ||
and | ||
{{ incremental_predicate('block_date') }} | ||
{% endif %} | ||
group by | ||
blockchain | ||
,block_date | ||
|
||
{% endmacro %} |
19 changes: 19 additions & 0 deletions
19
dbt_subprojects/daily_spellbook/macros/sector/metrics/metrics_transactions_evm.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 @@ | ||
{% macro metrics_transactions_evm(blockchain) %} | ||
|
||
select | ||
blockchain | ||
, block_date | ||
, approx_distinct(tx_hash) as tx_count --max 2% error, which is fine | ||
from | ||
{{ source('tokens', 'transfers') }} | ||
where | ||
blockchain = '{{ blockchain }}' | ||
and amount_usd >=1 | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('block_date') }} | ||
{% endif %} | ||
group by | ||
blockchain | ||
, block_date | ||
|
||
{% endmacro %} |
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
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
74 changes: 62 additions & 12 deletions
74
dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_daily.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 |
---|---|---|
@@ -1,21 +1,71 @@ | ||
{{ config( | ||
schema = 'metrics' | ||
, alias = 'dune_index_daily' | ||
, materialized = 'view' | ||
, materialized = 'incremental' | ||
, file_format = 'delta' | ||
, incremental_strategy = 'merge' | ||
, unique_key = ['blockchain', 'block_date'] | ||
, incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] | ||
) | ||
}} | ||
|
||
{% set baseline_date = '2018-01-01' %} | ||
{% set start_date = '2015-08-21' %} | ||
|
||
with | ||
fees as ( | ||
select | ||
blockchain | ||
, block_date | ||
, gas_fees_usd | ||
, (gas_fees_usd / (select sum(gas_fees_usd) from {{ ref('metrics_gas_fees_daily') }} where block_date = date '{{ baseline_date }}')) * 10 as fees_index | ||
from | ||
{{ ref('metrics_gas_fees_daily') }} | ||
where | ||
block_date >= date '{{ start_date }}' | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('block_date') }} | ||
{% endif %} | ||
), | ||
transactions as ( | ||
select | ||
blockchain | ||
, block_date | ||
, tx_count | ||
, (tx_count / cast((select sum(tx_count) from {{ ref('metrics_transactions_daily') }} where block_date = date '{{ baseline_date }}') as double)) * 10 as tx_index | ||
from | ||
{{ ref('metrics_transactions_daily') }} | ||
where | ||
block_date >= date '{{ start_date }}' | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('block_date') }} | ||
{% endif %} | ||
) | ||
,transfers as ( | ||
select | ||
blockchain | ||
, block_date | ||
, net_transfer_amount_usd | ||
, (net_transfer_amount_usd / cast((select sum(net_transfer_amount_usd) from {{ ref('metrics_transfers_daily') }} where block_date = date '{{ baseline_date }}') as double)) * 10 as transfers_index | ||
from | ||
{{ ref('metrics_transfers_daily') }} | ||
where | ||
block_date >= date '{{ start_date }}' | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('block_date') }} | ||
{% endif %} | ||
) | ||
|
||
select | ||
blockchain | ||
, block_date | ||
, coalesce(f.fees_index,0) as fees_index | ||
, coalesce(tr.transfers_index,0) as transfers_index | ||
, coalesce(tx.tx_index,0) as tx_index | ||
, coalesce(f.fees_index,0)*0.45 + coalesce(tr.transfers_index,0)*0.45 + coalesce(tx.tx_index,0)*0.10 as dune_index | ||
from {{ ref('metrics_fees_index_daily') }} as f | ||
left join | ||
{{ ref('metrics_transfers_index_daily') }} as tr | ||
using (blockchain, block_date) | ||
left join | ||
{{ ref('metrics_transactions_index_daily') }} as tx | ||
using (blockchain, block_date) | ||
, 0.45 * coalesce(fees_index,0) + 0.45 * coalesce(transfers_index,0) + 0.10 * coalesce(tx_index,0) as dune_index | ||
, coalesce(fees_index,0) as fees_index | ||
, coalesce(transfers_index,0) as transfers_index | ||
, coalesce(tx_index,0) as tx_index | ||
, gas_fees_usd | ||
, tx_count | ||
, net_transfer_amount_usd | ||
from fees | ||
left join transfers using (blockchain, block_date) | ||
left join transactions using (blockchain, block_date) |
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
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
15 changes: 15 additions & 0 deletions
15
dbt_subprojects/daily_spellbook/models/_metrics/fees/chains/bitcoin/_schema.yml
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,15 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: metrics_bitcoin_gas_fees_daily | ||
meta: | ||
sector: metrics | ||
contributors: jeff-dude | ||
config: | ||
tags: ['metrics', 'fees', 'gas', 'daily'] | ||
description: "Sum of total fees spent per day" | ||
data_tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- blockchain | ||
- block_date |
46 changes: 46 additions & 0 deletions
46
...ts/daily_spellbook/models/_metrics/fees/chains/bitcoin/metrics_bitcoin_gas_fees_daily.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,46 @@ | ||
{{ config( | ||
schema = 'metrics_bitcoin' | ||
, alias = 'gas_fees_daily' | ||
, materialized = 'incremental' | ||
, file_format = 'delta' | ||
, incremental_strategy = 'merge' | ||
, unique_key = ['blockchain', 'block_date'] | ||
, incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] | ||
) | ||
}} | ||
|
||
with prices as ( | ||
select | ||
day | ||
, price | ||
from | ||
{{ source('prices', 'usd_daily') }} | ||
where | ||
symbol = 'BTC' | ||
and blockchain is null | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('day') }} | ||
{% endif %} | ||
) | ||
, bitcoin_fees as ( | ||
select | ||
date as block_date | ||
, sum(total_fees) as daily_fee | ||
from | ||
{{ source('bitcoin', 'blocks') }} | ||
where | ||
date < cast(date_trunc('day', now()) as date) --exclude current day to match prices.usd_daily | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('date') }} | ||
{% endif %} | ||
group by | ||
date | ||
) | ||
select | ||
'bitcoin' as blockchain | ||
, block_date | ||
, (daily_fee * price) as gas_fees_usd | ||
from | ||
bitcoin_fees | ||
inner join prices | ||
on block_date = day |
Oops, something went wrong.