Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
80fc3a3
thorchain phase 1 commit
krishgka Oct 7, 2025
6e4debb
Merge branch 'main' of https://github.com/duneanalytics/spellbook int…
krishgka Oct 8, 2025
1d1548e
changed ref to tokens prices
krishgka Oct 8, 2025
9b70158
prices.usd update
krishgka Oct 8, 2025
42082d8
adjustments
krishgka Oct 8, 2025
c0a226f
fix
krishgka Oct 8, 2025
55739b7
added partitioning
krishgka Oct 8, 2025
a34f688
update fix
krishgka Oct 9, 2025
56a70ce
last 7 days run
krishgka Oct 9, 2025
f07f253
adjusted last 7 days
krishgka Oct 9, 2025
2edd32d
adjusted prices to last 7d
krishgka Oct 9, 2025
dd77be1
updated for all joins
krishgka Oct 9, 2025
ca75676
update
krishgka Oct 9, 2025
60b086c
added block_month partitioning
krishgka Oct 9, 2025
de03ca7
reverted unique keys
krishgka Oct 9, 2025
acb5e7b
fixed unique key
krishgka Oct 9, 2025
3192051
fixes
krishgka Oct 9, 2025
5a5d16e
remove previously held columns from schema
krishgka Oct 9, 2025
b6ad822
removed duplicate variables
krishgka Oct 9, 2025
95d682b
changed txhash to txid
krishgka Oct 9, 2025
4423229
removed extra incremental
krishgka Oct 9, 2025
e8b2b17
update fixes
krishgka Oct 9, 2025
8fa0666
sorting spellbook structure
krishgka Oct 9, 2025
84ac587
removed timestamp for block_time
krishgka Oct 9, 2025
7f5c866
removed duplicate joins
krishgka Oct 9, 2025
7c5c899
schema fix
krishgka Oct 9, 2025
e2fd859
added Pool & TVL tables
krishgka Oct 10, 2025
cdb04d5
changed to lowercase
krishgka Oct 10, 2025
5758975
fixes for pools and tvl
krishgka Oct 10, 2025
a9942b9
changes update
krishgka Oct 10, 2025
2fe1b7b
fixes
krishgka Oct 10, 2025
5fdc14a
fix
krishgka Oct 10, 2025
436b2bd
update on pools
krishgka Oct 10, 2025
46271ce
removed meta
krishgka Oct 10, 2025
542ceca
balances fixes to downstream
krishgka Oct 10, 2025
fd2a5a6
updates prices to include block_id
krishgka Oct 10, 2025
78bab00
fixes again
krishgka Oct 10, 2025
6dd3582
updated config
krishgka Oct 12, 2025
758022a
block_time/date consistency
krishgka Oct 13, 2025
63edc10
minor fix
krishgka Oct 13, 2025
2149195
downstream changes made
krishgka Oct 13, 2025
64ee008
fix
krishgka Oct 13, 2025
9d65a96
changed date to be from 15 days ago
krishgka Oct 13, 2025
0eb91fa
pool block update
krishgka Oct 13, 2025
527c5bc
fixed pool block stat naming
krishgka Oct 13, 2025
f970b0b
update the stats
krishgka Oct 13, 2025
ec7b96b
test runs with 2 new lineages
krishgka Oct 13, 2025
4a0dbd4
added 60 models
krishgka Oct 14, 2025
a48d998
update, added more files
krishgka Oct 14, 2025
4e683dd
fixed error
krishgka Oct 14, 2025
2a96d74
updated changes
krishgka Oct 14, 2025
1feb85a
changed mapping for slash amounts/events
krishgka Oct 15, 2025
4c86575
scheduled_outbound_events fix
krishgka Oct 15, 2025
77241bc
update rune prices
krishgka Oct 15, 2025
a78c240
removed tx_id null tests from schema
krishgka Oct 15, 2025
f72180e
removed last incre. run
krishgka Oct 15, 2025
183d3f7
rerun with more data
krishgka Oct 15, 2025
110c7c9
still no data, changing lookback time
krishgka Oct 15, 2025
d58de4f
Remove silver folder - thorchain_gold PR will only contain gold folder
krishgka Oct 15, 2025
746fc78
Update schema.yml to only include gold models
krishgka Oct 15, 2025
92cfb54
added back core dim block
krishgka Oct 16, 2025
3deed56
Merge main into thorchain_gold - resolved schema.yml conflict
krishgka Oct 17, 2025
503ffdb
fixed swaps
krishgka Oct 19, 2025
91d31a6
changes to file names etc.
krishgka Oct 19, 2025
fbb858c
Fix seed file with correct full amounts (no division)
krishgka Oct 19, 2025
32df167
Revert "Fix seed file with correct full amounts (no division)"
krishgka Oct 19, 2025
768625d
changed file name
krishgka Oct 19, 2025
e94508c
added schema back
krishgka Oct 20, 2025
7b9a7b2
changed structure of only gold files
krishgka Oct 20, 2025
22cdcca
changed gold models
krishgka Oct 20, 2025
f33f5cd
fixes
krishgka Oct 20, 2025
d75a043
switched to block_timestamp
krishgka Oct 20, 2025
7692056
full run on refund events
krishgka Oct 20, 2025
bd3058c
testing with 16 days lookback
krishgka Oct 20, 2025
70527ed
fix for refund events
krishgka Oct 20, 2025
1e74b68
removing _updated_at
krishgka Oct 20, 2025
aeca267
unique test added to silver
krishgka Oct 20, 2025
3cdf612
added partition column to unique key
krishgka Oct 20, 2025
76f668a
added back updated_at after upstream fixes
krishgka Oct 21, 2025
a332abd
Revert "added back updated_at after upstream fixes"
krishgka Oct 21, 2025
afb9566
updated models and removed last 18 days rows filter
krishgka Oct 21, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{ config(
schema = 'thorchain',
alias = 'core_block',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_month', 'dim_block_id'],
partition_by = ['block_month'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
tags = ['thorchain', 'core', 'blocks'],
post_hook='{{ expose_spells(\'["thorchain"]\',
"core",
"core_block",
\'["krishhh"]\') }}'
) }}

WITH base AS (
SELECT
{{ dbt_utils.generate_surrogate_key(['cast(height as bigint)']) }} AS dim_block_id,
cast(height as bigint) AS block_id,
cast(from_unixtime(cast(timestamp / 1e9 as bigint)) as timestamp) AS block_time,
cast(from_unixtime(cast(timestamp / 1e9 as bigint)) as timestamp) AS block_timestamp,
date(from_unixtime(cast(timestamp / 1e9 as bigint))) AS block_date,
date_trunc('hour', from_unixtime(cast(timestamp / 1e9 as bigint))) AS block_hour,
date_trunc('week', from_unixtime(cast(timestamp / 1e9 as bigint))) AS block_week,
date_trunc('month', from_unixtime(cast(timestamp / 1e9 as bigint))) AS block_month,
quarter(from_unixtime(cast(timestamp / 1e9 as bigint))) AS block_quarter,
year(from_unixtime(cast(timestamp / 1e9 as bigint))) AS block_year,
day(from_unixtime(cast(timestamp / 1e9 as bigint))) AS block_dayofmonth,
day_of_week(from_unixtime(cast(timestamp / 1e9 as bigint))) AS block_dayofweek,
day_of_year(from_unixtime(cast(timestamp / 1e9 as bigint))) AS block_dayofyear,
timestamp,
hash,
agg_state,
current_timestamp AS _inserted_timestamp,
cast('{{ invocation_id }}' as varchar) AS _audit_run_id,
current_timestamp AS inserted_timestamp,
current_timestamp AS modified_timestamp
FROM {{ source('thorchain', 'block_log') }}
WHERE height IS NOT NULL
{% if is_incremental() %}
AND {{ incremental_predicate('cast(from_unixtime(cast(timestamp / 1e9 as bigint)) as timestamp)') }}
{% endif %}
)

SELECT * FROM base
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{{ config(
schema = 'thorchain',
alias = 'core_instantiate_events',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_month', 'fact_instantiate_events_id'],
partition_by = ['block_month'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
tags = ['thorchain', 'core', 'instantiate_events', 'fact'],
post_hook='{{ expose_spells(\'["thorchain"]\',
"core",
"core_instantiate_events",
\'["krishhh"]\') }}'
) }}

-- Deduplication and gold layer combined (no silver layer needed)
WITH deduplicated AS (
SELECT
tx_id,
contract_address,
admin_address,
code_id,
sender,
label,
msg,
funds,
event_id,
block_timestamp,

ROW_NUMBER() OVER (
PARTITION BY event_id
ORDER BY block_timestamp DESC
) AS rn
FROM {{ source('thorchain', 'instantiate_events') }}
{% if is_incremental() %}
WHERE {{ incremental_predicate('cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp)') }}
{% endif %}
),

base AS (
SELECT
tx_id,
contract_address,
admin_address,
code_id,
sender,
label,
msg,
funds,
event_id,
block_timestamp,
cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp) AS block_time,
date_trunc('month', cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp)) AS block_month,
current_timestamp AS _inserted_timestamp
FROM deduplicated
WHERE rn = 1
)

SELECT
{{ dbt_utils.generate_surrogate_key([
'a.event_id',
'a.contract_address',
'a.block_timestamp'
]) }} AS fact_instantiate_events_id,
b.block_time,
b.block_timestamp, -- Include for compatibility
b.block_month,
COALESCE(b.dim_block_id, '-1') AS dim_block_id,
a.tx_id,
a.contract_address,
a.admin_address,
a.code_id,
a.sender,
a.label,
a.msg,
a.funds,
a.event_id,
a._inserted_timestamp,
cast('{{ invocation_id }}' as varchar) AS _audit_run_id,
current_timestamp AS inserted_timestamp,
current_timestamp AS modified_timestamp
FROM base a
JOIN {{ ref('thorchain_core_block') }} b
ON a.block_timestamp = b.timestamp

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{ config(
schema = 'thorchain',
alias = 'core_network_version_events',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_month', 'fact_network_version_events_id'],
partition_by = ['block_month'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
tags = ['thorchain', 'core', 'network_version_events', 'fact'],
post_hook='{{ expose_spells(\'["thorchain"]\',
"core",
"core_network_version_events",
\'["krishhh"]\') }}'
) }}

-- Deduplication and gold layer combined (no silver layer needed)
WITH base_source AS (
SELECT
version,
event_id,
block_timestamp
FROM {{ source('thorchain', 'network_version_events') }}
{% if is_incremental() %}
WHERE {{ incremental_predicate('cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp)') }}
{% endif %}
),

deduplicated AS (
SELECT
version,
event_id,
block_timestamp,
ROW_NUMBER() OVER (
PARTITION BY event_id
ORDER BY block_timestamp DESC
) AS rn
FROM base_source
),

base AS (
SELECT
version,
event_id,
block_timestamp,
cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp) AS block_time,
date_trunc('month', cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp)) AS block_month,
current_timestamp AS _inserted_timestamp
FROM deduplicated
WHERE rn = 1
)

SELECT
{{ dbt_utils.generate_surrogate_key(['a.event_id']) }} AS fact_network_version_events_id,
b.block_time,
b.block_timestamp, -- Include for compatibility
b.block_month,
COALESCE(b.dim_block_id, '-1') AS dim_block_id,
a.version,
a.event_id,
a._inserted_timestamp,
cast('{{ invocation_id }}' as varchar) AS _audit_run_id,
current_timestamp AS inserted_timestamp,
current_timestamp AS modified_timestamp
FROM base a
JOIN {{ ref('thorchain_core_block') }} b
ON a.block_timestamp = b.timestamp

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{ config(
schema = 'thorchain',
alias = 'core_set_mimir_events',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_month', 'fact_set_mimir_events_id'],
partition_by = ['block_month'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
tags = ['thorchain', 'core', 'set_mimir_events', 'fact'],
post_hook='{{ expose_spells(\'["thorchain"]\',
"core",
"core_set_mimir_events",
\'["krishhh"]\') }}'
) }}

-- Deduplication and gold layer combined (no silver layer needed)
WITH deduplicated AS (
SELECT
key,
value,
event_id,
block_timestamp,

ROW_NUMBER() OVER (
PARTITION BY event_id
ORDER BY block_timestamp DESC
) AS rn
FROM {{ source('thorchain', 'set_mimir_events') }}
{% if is_incremental() %}
WHERE {{ incremental_predicate('cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp)') }}
{% endif %}
),

base AS (
SELECT
key,
value,
event_id,
block_timestamp,
cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp) AS block_time,
date_trunc('month', cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp)) AS block_month,
current_timestamp AS _inserted_timestamp
FROM deduplicated
WHERE rn = 1
)

SELECT
{{ dbt_utils.generate_surrogate_key([
'a.event_id',
'a.key',
'a.block_timestamp'
]) }} AS fact_set_mimir_events_id,
b.block_time,
b.block_timestamp, -- Include for compatibility
b.block_month,
COALESCE(b.dim_block_id, '-1') AS dim_block_id,
a.key,
a.value,
a.event_id,
a._inserted_timestamp,
cast('{{ invocation_id }}' as varchar) AS _audit_run_id,
current_timestamp AS inserted_timestamp,
current_timestamp AS modified_timestamp
FROM base a
JOIN {{ ref('thorchain_core_block') }} b
ON a.block_timestamp = b.timestamp

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{{ config(
schema = 'thorchain',
alias = 'core_thorname_change_events',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_month', 'fact_thorname_change_events_id'],
partition_by = ['block_month'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
tags = ['thorchain', 'core', 'thorname_change_events', 'fact'],
post_hook='{{ expose_spells(\'["thorchain"]\',
"core",
"core_thorname_change_events",
\'["krishhh"]\') }}'
) }}

-- Deduplication and gold layer combined (no silver layer needed)
WITH deduplicated AS (
SELECT
owner,
chain,
address,
expire,
name,
fund_amount_e8,
registration_fee_e8,
event_id,
block_timestamp,

ROW_NUMBER() OVER (
PARTITION BY event_id, block_timestamp, owner, chain, address, expire, name
ORDER BY block_timestamp DESC
) AS rn
FROM {{ source('thorchain', 'thorname_change_events') }}
{% if is_incremental() %}
WHERE {{ incremental_predicate('cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp)') }}
{% endif %}
),

base AS (
SELECT
owner,
chain,
address,
expire,
name,
fund_amount_e8,
registration_fee_e8,
event_id,
block_timestamp,
cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp) AS block_time,
date_trunc('month', cast(from_unixtime(cast(block_timestamp / 1e9 as bigint)) as timestamp)) AS block_month,
current_timestamp AS _inserted_timestamp
FROM deduplicated
WHERE rn = 1
)

SELECT
{{ dbt_utils.generate_surrogate_key([
'a.event_id',
'a.block_timestamp',
'a.owner',
'a.chain',
'a.address',
'a.expire',
'a.name'
]) }} AS fact_thorname_change_events_id,
b.block_time,
b.block_timestamp, -- Include for compatibility
b.block_month,
COALESCE(b.dim_block_id, '-1') AS dim_block_id,
a.owner,
a.chain,
a.address,
a.expire,
a.name,
a.fund_amount_e8,
a.registration_fee_e8,
a._inserted_timestamp,
cast('{{ invocation_id }}' as varchar) AS _audit_run_id,
current_timestamp AS inserted_timestamp,
current_timestamp AS modified_timestamp
FROM base a
JOIN {{ ref('thorchain_core_block') }} b
ON a.block_timestamp = b.timestamp

Loading