Skip to content
Merged
Show file tree
Hide file tree
Changes from 89 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
f2e0547
move to blockchains directory
jeff-dude Nov 7, 2025
b140a50
update silver block log to view
jeff-dude Nov 7, 2025
2412a15
update silver block pool depths to view
jeff-dude Nov 7, 2025
a5f34b1
remove incremental read on new view
jeff-dude Nov 7, 2025
446f470
update silver block log
jeff-dude Nov 7, 2025
c2ac6c2
update silver block pool depths
jeff-dude Nov 7, 2025
4236ed1
update silver update node account status events
jeff-dude Nov 7, 2025
8157df8
update silver swap events
jeff-dude Nov 7, 2025
6d8542f
update silver bond events
jeff-dude Nov 7, 2025
74facb2
update silver rune price
jeff-dude Nov 7, 2025
f4d431b
update silver rewards event entries
jeff-dude Nov 7, 2025
a07cd83
update silver prices
jeff-dude Nov 7, 2025
929871a
update silver block rewards
jeff-dude Nov 7, 2025
d205ba0
update silver prices column aliases
jeff-dude Nov 7, 2025
531fed2
update silver total block rewards
jeff-dude Nov 7, 2025
a437e1f
update thorchain silver daily earnings
jeff-dude Nov 7, 2025
c7047cd
update gold defi daily earnings
jeff-dude Nov 7, 2025
12a3535
update schema yml file
jeff-dude Nov 7, 2025
4548f53
Merge branch 'main' into thorchain-updates
jeff-dude Nov 7, 2025
b7c3f79
Revert "move to blockchains directory"
jeff-dude Nov 7, 2025
1381287
fix join condition to block log
jeff-dude Nov 7, 2025
15c6709
fix day column mismatch
jeff-dude Nov 7, 2025
3274589
update silver pool block balances
jeff-dude Nov 7, 2025
1dcb79d
calculate day the same across the model
jeff-dude Nov 7, 2025
9ca1c4c
update silver pool block fees
jeff-dude Nov 7, 2025
acd11a7
fix concat_ws data types
jeff-dude Nov 7, 2025
1f787f2
update silver pool block stats
jeff-dude Nov 7, 2025
bd1bd46
fix concat data types
jeff-dude Nov 7, 2025
7af84c6
fix model config for total block rewards
jeff-dude Nov 7, 2025
dbe7782
fix pool_name alias bug
jeff-dude Nov 7, 2025
2514816
update silver total value locked
jeff-dude Nov 8, 2025
c305ea6
update silver transfers
jeff-dude Nov 8, 2025
ba36a3d
update silver upgrades
jeff-dude Nov 8, 2025
4e4a0ab
update silver daily pool stats
jeff-dude Nov 8, 2025
a7bcff0
update silver daily tvl
jeff-dude Nov 8, 2025
1121e5b
update silver liquidty actions
jeff-dude Nov 8, 2025
52f2126
update silver swaps
jeff-dude Nov 8, 2025
c91a157
update gold block pool depths
jeff-dude Nov 8, 2025
3e51303
update gold defi block rewards
jeff-dude Nov 8, 2025
4468f21
update bond actions
jeff-dude Nov 8, 2025
3a1d915
update gold bond events
jeff-dude Nov 8, 2025
50f9628
update gold daily earnings
jeff-dude Nov 8, 2025
4c78f84
update gold daily pool stats
jeff-dude Nov 8, 2025
2372aaa
update gold defi daily tvl
jeff-dude Nov 8, 2025
5548749
update gold liquidty actions
jeff-dude Nov 8, 2025
05ce74d
update defi pool block balances
jeff-dude Nov 8, 2025
1ee3da3
update gold pool block fees
jeff-dude Nov 8, 2025
2fc9dd2
update gold pool block stats
jeff-dude Nov 8, 2025
efd9621
update gold rewards event entries
jeff-dude Nov 8, 2025
a3ee451
update gold swap events
jeff-dude Nov 8, 2025
3ed9f1b
update defi swaps
jeff-dude Nov 8, 2025
f56a7c0
update gold total block rewards
jeff-dude Nov 8, 2025
b800578
update gold total value locked
jeff-dude Nov 8, 2025
0c72c3e
update gold update node account status events
jeff-dude Nov 8, 2025
8b280b6
update gold defi udgrades
jeff-dude Nov 8, 2025
8ac91ff
fix gold update node account status events
jeff-dude Nov 10, 2025
4425aed
fix silver tvl
jeff-dude Nov 10, 2025
d9e2133
fix silver swaps model
jeff-dude Nov 10, 2025
a0d3da9
fix silver swaps function bug
jeff-dude Nov 10, 2025
efb3dfe
fix stake and withdraw events
jeff-dude Nov 10, 2025
61f6db0
fix missing col in silver withdraw events
jeff-dude Nov 10, 2025
0fa46c3
fix withdraw events bug
jeff-dude Nov 10, 2025
d816981
fix silver liquidity actions
jeff-dude Nov 10, 2025
3791bac
fix silver pool block stats
jeff-dude Nov 10, 2025
592d568
force incremental
jeff-dude Nov 10, 2025
04f5a6e
Revert "force incremental"
jeff-dude Nov 10, 2025
b2913b0
Reapply "force incremental"
jeff-dude Nov 10, 2025
ac97418
full run for models with target lookups
jeff-dude Nov 10, 2025
6411190
fix silver liquidity actions and pool block stats
jeff-dude Nov 10, 2025
fa16d85
fix bug in stats
jeff-dude Nov 10, 2025
e8dde09
fix silver swaps
jeff-dude Nov 10, 2025
70a6e92
Merge branch 'main' into thorchain-updates
jeff-dude Nov 11, 2025
c0269e8
temp to be reverted: update local setup
jeff-dude Nov 11, 2025
c1f2fce
fix outstanding bugs
jeff-dude Nov 11, 2025
672511f
Merge branch 'main' into thorchain-updates
jeff-dude Nov 12, 2025
0d007de
add missing cols
jeff-dude Nov 12, 2025
16420b7
Merge branch 'main' into thorchain-updates
jeff-dude Nov 12, 2025
e50450f
final bug fixes on current modified models
jeff-dude Nov 12, 2025
3dc6560
Revert "temp to be reverted: update local setup"
jeff-dude Nov 12, 2025
efd8c65
add final two models
jeff-dude Nov 12, 2025
35dddc5
simplify schema yml file
jeff-dude Nov 12, 2025
de8f53c
fix add events
jeff-dude Nov 12, 2025
eec1c93
fix bug in add events gold
jeff-dude Nov 12, 2025
741008f
add pool events
jeff-dude Nov 12, 2025
f1cd4a9
add rewards events
jeff-dude Nov 12, 2025
28f15aa
add silver transfer events
jeff-dude Nov 12, 2025
e0840b8
remove short timeframe
jeff-dude Nov 12, 2025
eb9a244
Merge branch 'main' into thorchain-updates
jeff-dude Nov 12, 2025
96f65da
fix latest model modification schema yml entries
jeff-dude Nov 13, 2025
e1a8980
fix schema file
jeff-dude Nov 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
692 changes: 692 additions & 0 deletions dbt_subprojects/daily_spellbook/models/thorchain/_schema.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{ config(
schema = 'thorchain',
alias = 'core_transfers',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['day', 'fact_transfers_id'],
partition_by = ['day'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_timestamp')],
tags = ['thorchain', 'defi', 'transfers', 'fact'],
post_hook='{{ expose_spells(\'["thorchain"]\',
"defi",
"defi_transfers",
\'["krishhh"]\') }}'
) }}

WITH base AS (
SELECT
block_id,
from_address,
to_address,
asset,
rune_amount,
rune_amount_usd,
_unique_key,
_INSERTED_TIMESTAMP
FROM
{{ ref('thorchain_silver_transfers') }}
{% if is_incremental() %}
WHERE {{ incremental_predicate('block_timestamp') }}
{% endif %}
)
SELECT
{{ dbt_utils.generate_surrogate_key(
['a._unique_key']
) }} AS fact_transfers_id,
cast(date_trunc('day', b.block_timestamp) AS date) AS day,
b.block_timestamp,
COALESCE(
b.dim_block_id,
'-1'
) AS dim_block_id,
from_address,
to_address,
asset,
rune_amount,
rune_amount_usd,
A._inserted_timestamp,
current_timestamp AS inserted_timestamp,
current_timestamp AS modified_timestamp
FROM
base A
JOIN {{ ref('thorchain_core_block') }} as b
ON A.block_id = b.block_id
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_month', 'tx_id', 'event_id'],
partition_by = ['block_month'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
unique_key = ['day', 'fact_add_events_id'],
partition_by = ['day'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_timestamp')],
tags = ['thorchain', 'defi', 'add_events', 'fact'],
post_hook='{{ expose_spells(\'["thorchain"]\',
"defi",
Expand All @@ -16,47 +16,56 @@

WITH base AS (
SELECT
raw_block_timestamp as block_timestamp,
tx_hash as tx_id,
rune_e8,
chain as blockchain,
asset_e8,
pool as pool_name,
memo,
to_addr as to_address,
from_addr as from_address,
asset,
event_id,
tx_type as _tx_type,
block_time -- Keep for incremental predicate
e.block_timestamp,
e.tx_id,
e.rune_e8,
e.blockchain,
e.asset_e8,
e.pool_name,
e.memo,
e.to_address,
e.from_address,
e.asset,
e.event_id,
e._TX_TYPE
FROM
{{ ref('thorchain_silver_add_events') }}
{{ ref('thorchain_silver_add_events') }} e
)

SELECT
a.block_time,
date(a.block_time) as block_date,
date_trunc('month', a.block_time) as block_month,
-1 AS block_height,
a.tx_id,
a.event_id,
a.rune_e8,
a.blockchain,
a.asset_e8,
a.pool_name,
a.memo,
a.to_address,
a.from_address,
a.asset,
a._tx_type,
{{ dbt_utils.generate_surrogate_key(
['a.event_id','a.tx_id','a.blockchain','a.from_address','a.to_address','a.asset','a.memo','a.block_timestamp']
) }} AS fact_add_events_id,
cast(date_trunc('day', b.block_timestamp) AS date) AS day,
b.block_timestamp,
COALESCE(
b.dim_block_id,
'-1'
) AS dim_block_id,
A.tx_id,
A.rune_e8,
A.blockchain,
A.asset_e8,
A.pool_name,
A.memo,
A.to_address,
A.from_address,
A.asset,
A._TX_TYPE,
current_timestamp AS inserted_timestamp,
current_timestamp AS modified_timestamp

FROM base a

FROM
base A
JOIN {{ ref('thorchain_core_block') }} as b
ON A.block_timestamp = b.timestamp
{% if is_incremental() %}
WHERE a.block_time >= (
SELECT MAX(block_time - INTERVAL '1' HOUR)
FROM {{ this }}
)
{% endif %}
WHERE
{{ incremental_predicate('b.block_timestamp') }}
OR tx_id IN (
SELECT
tx_id
FROM
{{ this }}
WHERE
dim_block_id = '-1'
)
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_month', 'fact_pool_depths_id'],
partition_by = ['block_month'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
unique_key = ['fact_pool_depths_id'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_timestamp')],
tags = ['thorchain', 'defi', 'pool_depths', 'fact'],
post_hook='{{ expose_spells(\'["thorchain"]\',
"defi",
Expand All @@ -20,43 +19,37 @@ WITH base AS (
asset_e8,
rune_e8,
synth_e8,
block_time,
raw_block_timestamp,
block_timestamp,
_inserted_timestamp
FROM {{ ref('thorchain_silver_block_pool_depths') }}
FROM
{{ ref('thorchain_silver_block_pool_depths') }}
)

SELECT
-- CRITICAL: Generate surrogate key (Trino equivalent of dbt_utils.generate_surrogate_key)
to_hex(sha256(to_utf8(concat(
COALESCE(a.pool_name, ''),
'|',
COALESCE(cast(a.block_time as varchar), '')
)))) AS fact_pool_depths_id,

-- CRITICAL: Always include partitioning columns first
a.block_time,
date(a.block_time) as block_date,
date_trunc('month', a.block_time) as block_month,
a.raw_block_timestamp,

-- Block dimension reference (set directly - no JOIN needed)
'-1' AS dim_block_id,

-- Pool depth data
a.rune_e8,
a.asset_e8,
a.synth_e8,
a.pool_name,

-- Audit fields (Trino conversions)
{{ dbt_utils.generate_surrogate_key(['a.pool_name','a.block_timestamp']) }} AS fact_pool_depths_id,
b.block_timestamp,
COALESCE(
b.dim_block_id,
'-1'
) AS dim_block_id,
rune_e8,
asset_e8,
synth_e8,
pool_name,
a._inserted_timestamp,
cast(from_hex(replace(cast(uuid() as varchar), '-', '')) as varchar) AS _audit_run_id, -- Trino equivalent of invocation_id
current_timestamp AS inserted_timestamp, -- Trino equivalent of SYSDATE()
current_timestamp AS inserted_timestamp,
current_timestamp AS modified_timestamp

FROM base a

FROM
base as a
JOIN {{ ref('thorchain_core_block') }} as b
ON a.block_timestamp = b.timestamp
{% if is_incremental() %}
WHERE {{ incremental_predicate('a.block_time') }}
{% endif %}
WHERE {{ incremental_predicate('b.block_timestamp') }}
OR pool_name IN (
SELECT
pool_name
FROM
{{ this }}
WHERE
dim_block_id = '-1'
)
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_month', 'fact_block_rewards_id'],
partition_by = ['block_month'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')],
unique_key = ['day', 'fact_block_rewards_id'],
partition_by = ['day'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.day')],
tags = ['thorchain', 'defi', 'block_rewards', 'fact'],
post_hook='{{ expose_spells(\'["thorchain"]\',
"defi",
Expand All @@ -16,42 +16,31 @@

WITH base AS (
SELECT
block_date,
day,
liquidity_fee,
block_rewards,
earnings,
bonding_earnings,
liquidity_earnings,
avg_node_count,
_inserted_timestamp,
block_month
FROM {{ ref('thorchain_silver_block_rewards') }}
_inserted_timestamp
FROM
{{ ref('thorchain_silver_block_rewards') }}
{% if is_incremental() -%}
WHERE {{ incremental_predicate('day') }}
{% endif -%}
)

SELECT
-- CRITICAL: Generate surrogate key (Trino equivalent of dbt_utils.generate_surrogate_key)
to_hex(sha256(to_utf8(cast(a.block_date as varchar)))) AS fact_block_rewards_id,

-- CRITICAL: Always include partitioning columns first
a.block_date,
a.block_month,

-- Block rewards data
a.liquidity_fee,
a.block_rewards,
a.earnings,
a.bonding_earnings,
a.liquidity_earnings,
a.avg_node_count,

-- Audit fields (Trino conversions)
{{ dbt_utils.generate_surrogate_key(['a.day']) }} AS fact_block_rewards_id,
day,
liquidity_fee,
block_rewards,
earnings,
bonding_earnings,
liquidity_earnings,
avg_node_count,
a._inserted_timestamp,
cast(from_hex(replace(cast(uuid() as varchar), '-', '')) as varchar) AS _audit_run_id, -- Trino equivalent of invocation_id
current_timestamp AS inserted_timestamp, -- Trino equivalent of SYSDATE()
current_timestamp AS inserted_timestamp,
current_timestamp AS modified_timestamp

FROM base a

{% if is_incremental() %}
WHERE {{ incremental_predicate('a.block_date') }}
{% endif %}
FROM
base as a
Loading
Loading