Skip to content

Commit

Permalink
add etf update thresholds (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwes authored Nov 25, 2024
1 parent b672554 commit 37ebeb3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions models/staging/bitcoin/__bitcoin__sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sources:
- name: raw_bitcoin_etf_addresses
- name: raw_bitcoin_etf_metadata
- name: raw_bitcoin_fidelity_outflows
- name: raw_etf_update_thresholds

- name: BITCOIN_FLIPSIDE
schema: core
Expand Down
1 change: 1 addition & 0 deletions models/staging/bitcoin/fact_bitcoin_etf_flows.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ WITH unaggregated AS (
INNER JOIN {{ ref('fact_bitcoin_etf_metadata') }} eat ON a.issuer=eat.issuer
WHERE i.value > 0
AND i.block_timestamp > '2019-07-24'::date
AND i.block_timestamp < (select bitcoin_update_threshold from {{ ref('fact_bitcoin_etf_update_threshold') }})

UNION ALL

Expand Down
20 changes: 20 additions & 0 deletions models/staging/bitcoin/fact_bitcoin_etf_update_threshold.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{
config(
materialized='table',
snowflake_warehouse='BITCOIN'
)
}}

-- Credit to @hildobby for the original version of this dataset: https://dune.com/data/dune.hildobby.dataset_etf_update_thresholds

with
max_extraction as (
select max(extraction_date) as max_date
from {{ source("PROD_LANDING", "raw_etf_update_thresholds") }}
)
select
left(value:bitcoin, 10)::date as bitcoin_update_threshold
from
{{ source("PROD_LANDING", "raw_etf_update_thresholds") }},
lateral flatten(input => parse_json(source_json))
where extraction_date = (select max_date from max_extraction)
1 change: 1 addition & 0 deletions models/staging/ethereum/fact_ethereum_etf_flows.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ WITH time_series AS (
INNER JOIN {{ ref('fact_ethereum_etf_addresses') }} a ON a.address=t.from_address
AND a.track_outflow = true
WHERE t.block_timestamp >= date('2017-10-16')
AND t.block_timestamp < (select ethereum_update_threshold from {{ ref('fact_ethereum_etf_update_threshold') }})
GROUP BY 1, 2

UNION ALL
Expand Down
20 changes: 20 additions & 0 deletions models/staging/ethereum/fact_ethereum_etf_update_threshold.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{
config(
materialized='table',
snowflake_warehouse='ETHEREUM'
)
}}

-- Credit to @hildobby for the original version of this dataset: https://dune.com/data/dune.hildobby.dataset_etf_update_thresholds

with
max_extraction as (
select max(extraction_date) as max_date
from {{ source("PROD_LANDING", "raw_etf_update_thresholds") }}
)
select
left(value:ethereum, 10)::date as ethereum_update_threshold
from
{{ source("PROD_LANDING", "raw_etf_update_thresholds") }},
lateral flatten(input => parse_json(source_json))
where extraction_date = (select max_date from max_extraction)

0 comments on commit 37ebeb3

Please sign in to comment.