Conversation
📝 WalkthroughWalkthroughAdds Tron support for JustLend lending: introduces new borrow and supply models (base, platform, enriched, final), schema updates (rename Changes
Sequence Diagram(s)sequenceDiagram
participant Source as JustLend Tron Events
participant Platform as justlend_tron_base_borrow<br/> (platform incremental)
participant TronBase as lending_tron_base_borrow<br/> (union view)
participant Enrich as lending_enrich_borrow<br/> (macro)
participant Final as lending_tron_borrow<br/> (final incremental)
Source->>Platform: Emit raw borrow events
Platform->>Platform: Parse/normalize via macro
Platform->>TronBase: Provide base records
TronBase->>TronBase: UNION ALL across platforms
TronBase->>Enrich: Supply base borrow rows
Enrich->>Final: Emit enriched rows
Final->>Final: Transform addresses, cast fields, partition by block_month
sequenceDiagram
participant Source2 as JustLend Tron Events
participant Platform2 as justlend_tron_base_supply<br/> (platform incremental)
participant TronBase2 as lending_tron_base_supply<br/> (union view)
participant Enrich2 as lending_enrich_supply<br/> (macro)
participant Final2 as lending_tron_supply<br/> (final incremental)
Source2->>Platform2: Emit raw supply events
Platform2->>Platform2: Parse/normalize via macro
Platform2->>TronBase2: Provide base records
TronBase2->>TronBase2: UNION ALL across platforms
TronBase2->>Enrich2: Supply base supply rows
Enrich2->>Final2: Emit enriched rows
Final2->>Final2: Transform addresses, cast fields, partition by block_month
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/lending_tron_borrow.sql (2)
24-45: Consider adding explicit table aliases to column references.Per coding guidelines for SQL files: "Always use explicit table aliases — prefix all columns." The columns in the final select should be prefixed with the CTE alias.
♻️ Proposed fix
select - blockchain, - project, - version, - transaction_type, - loan_type, - symbol, - to_tron_address(token_address) as token_address, - to_tron_address(borrower) as borrower, - to_tron_address(on_behalf_of) as on_behalf_of, - to_tron_address(repayer) as repayer, - to_tron_address(liquidator) as liquidator, - amount, - amount_raw, - amount_usd, - block_month, - block_time, - block_number, - to_tron_address(project_contract_address) as project_contract_address, - lower(to_hex(tx_hash)) as tx_hash, - evt_index -from borrow_enriched + be.blockchain, + be.project, + be.version, + be.transaction_type, + be.loan_type, + be.symbol, + to_tron_address(be.token_address) as token_address, + to_tron_address(be.borrower) as borrower, + to_tron_address(be.on_behalf_of) as on_behalf_of, + to_tron_address(be.repayer) as repayer, + to_tron_address(be.liquidator) as liquidator, + be.amount, + be.amount_raw, + be.amount_usd, + be.block_month, + be.block_time, + be.block_number, + to_tron_address(be.project_contract_address) as project_contract_address, + lower(to_hex(be.tx_hash)) as tx_hash, + be.evt_index +from borrow_enriched as be🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/lending_tron_borrow.sql` around lines 24 - 45, The SELECT uses unprefixed columns from the CTE/table borrow_enriched which violates the rule to prefix all columns with explicit table aliases; update the query to introduce an alias (e.g., "be" or "borrow_enriched") and prefix every column reference and function input (e.g., blockchain, project, token_address, borrower, on_behalf_of, repayer, liquidator, project_contract_address, tx_hash, evt_index, amount, amount_raw, amount_usd, block_month, block_time, block_number) with that alias, and update calls like to_tron_address(token_address) and lower(to_hex(tx_hash)) to use the aliased names (e.g., to_tron_address(be.token_address), lower(to_hex(be.tx_hash))) while keeping the final column aliases the same.
5-9: Addblock_monthtounique_keyfor partition-aligned incremental merges.The model partitions by
block_month(line 5) but theunique_key(line 9) doesn't include it. As per coding guidelines: "For incremental models, include the partition column in unique_key."♻️ Proposed fix
- unique_key = ['blockchain', 'project', 'version', 'transaction_type', 'token_address', 'tx_hash', 'evt_index'], + unique_key = ['blockchain', 'project', 'version', 'transaction_type', 'token_address', 'tx_hash', 'evt_index', 'block_month'],🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/lending_tron_borrow.sql` around lines 5 - 9, The incremental model is partitioned by block_month but block_month is missing from the unique_key; update the model configuration so the unique_key array (the unique_key setting) includes block_month alongside ['blockchain','project','version','transaction_type','token_address','tx_hash','evt_index'] to ensure partition-aligned incremental merges for functions/configs in this file (the partition_by = ['block_month'] and unique_key = [...] settings).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sql`:
- Around line 24-44: The SELECT list uses unqualified columns from
supply_enriched; add an explicit table alias (e.g., alias the table as s or se
in the FROM clause) and prefix every projected identifier and function argument
with that alias (for example, s.blockchain, s.token_address,
to_tron_address(s.token_address), lower(to_hex(s.tx_hash)), s.evt_index, etc.)
so that all references to columns and usages in to_tron_address/to_hex are fully
qualified and consistent with DuneSQL/Trino guidelines.
- Around line 5-10: The incremental config is inconsistent with partitioning:
add the partition column block_month to unique_key and change the incremental
predicate to use block_date instead of block_time; specifically update the model
config where partition_by = ['block_month'], unique_key = [...] (add
'block_month') and replace incremental_predicate('DBT_INTERNAL_DEST.block_time')
with a predicate referencing DBT_INTERNAL_DEST.block_date so merge correctness
and partition pruning work as intended.
In
`@dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/tron/platforms/justlend_tron_base_supply.sql`:
- Around line 2-10: The incremental predicate currently targets
DBT_INTERNAL_DEST.block_time; change it to use the partition/date column (e.g.,
DBT_INTERNAL_DEST.block_date) so partition pruning works: update the config
incremental_predicates entry (the incremental_predicate(...) call) to reference
block_date instead of block_time and ensure downstream incremental WHERE and any
JOINs inside the incremental model include the partition column (block_date) so
partitions are always used for pruning; keep the materialized='incremental' and
unique_key settings unchanged.
---
Nitpick comments:
In
`@dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/lending_tron_borrow.sql`:
- Around line 24-45: The SELECT uses unprefixed columns from the CTE/table
borrow_enriched which violates the rule to prefix all columns with explicit
table aliases; update the query to introduce an alias (e.g., "be" or
"borrow_enriched") and prefix every column reference and function input (e.g.,
blockchain, project, token_address, borrower, on_behalf_of, repayer, liquidator,
project_contract_address, tx_hash, evt_index, amount, amount_raw, amount_usd,
block_month, block_time, block_number) with that alias, and update calls like
to_tron_address(token_address) and lower(to_hex(tx_hash)) to use the aliased
names (e.g., to_tron_address(be.token_address), lower(to_hex(be.tx_hash))) while
keeping the final column aliases the same.
- Around line 5-9: The incremental model is partitioned by block_month but
block_month is missing from the unique_key; update the model configuration so
the unique_key array (the unique_key setting) includes block_month alongside
['blockchain','project','version','transaction_type','token_address','tx_hash','evt_index']
to ensure partition-aligned incremental merges for functions/configs in this
file (the partition_by = ['block_month'] and unique_key = [...] settings).
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
dbt_subprojects/hourly_spellbook/seeds/_sector/lending/justlend_tron_base_borrow_seed.csvis excluded by!**/*.csvdbt_subprojects/hourly_spellbook/seeds/_sector/lending/justlend_tron_base_supply_seed.csvis excluded by!**/*.csv
📒 Files selected for processing (13)
dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/_schema.ymldbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/lending_tron_borrow.sqldbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/_schema.ymldbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/lending_tron_base_borrow.sqldbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/platforms/justlend_tron_base_borrow.sqldbt_subprojects/hourly_spellbook/models/_sector/lending/ctokens/justlend_tron_ctokens.sqldbt_subprojects/hourly_spellbook/models/_sector/lending/supply/_schema.ymldbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sqldbt_subprojects/hourly_spellbook/models/_sector/lending/supply/tron/_schema.ymldbt_subprojects/hourly_spellbook/models/_sector/lending/supply/tron/lending_tron_base_supply.sqldbt_subprojects/hourly_spellbook/models/_sector/lending/supply/tron/platforms/justlend_tron_base_supply.sqldbt_subprojects/hourly_spellbook/seeds/_sector/lending/_schema.ymlsources/justlend/tron/sources.yml
dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sql
Show resolved
Hide resolved
dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sql
Outdated
Show resolved
Hide resolved
.../hourly_spellbook/models/_sector/lending/supply/tron/platforms/justlend_tron_base_supply.sql
Show resolved
Hide resolved
There was a problem hiding this comment.
♻️ Duplicate comments (1)
dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sql (1)
5-10:⚠️ Potential issue | 🟠 MajorSwitch the incremental predicate off
block_time.Line 10 still predicates on
DBT_INTERNAL_DEST.block_time, which is misaligned withpartition_by = ['block_month']and weakens pruning/merge efficiency.Suggested fix
- incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_month')]Based on learnings: Applies to **/*.sql : Filter on block_date (not block_time) for partition pruning, and always include partition columns in WHERE and JOIN conditions.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sql` around lines 5 - 10, The incremental_predicates currently reference DBT_INTERNAL_DEST.block_time which conflicts with partition_by = ['block_month']; change the predicate to use the partition-aligned column (e.g., DBT_INTERNAL_DEST.block_date or a derived block_month) instead of block_time, and ensure any incremental WHERE/JOIN conditions include the partition column block_month (or block_date) so pruning/merge efficiency is preserved; update the incremental_predicates expression(s) and any related joins/filters in this model (look for uses of incremental_predicate, incremental_predicates, partition_by, block_month, and DBT_INTERNAL_DEST.block_time) accordingly.
🧹 Nitpick comments (1)
dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/_schema.yml (1)
12-18: Deduplicate repeated unique-key test config to avoid drift.The same
dbt_utils.unique_combination_of_columnsblock appears in both models. Consider anchoring it once and reusing it, so future key changes stay consistent.♻️ Suggested DRY refactor
- name: lending_tron_base_borrow @@ - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - transaction_type - - token_address - - tx_hash - - evt_index + data_tests: + - &borrow_unique_key_test + dbt_utils.unique_combination_of_columns: + combination_of_columns: + - transaction_type + - token_address + - tx_hash + - evt_index @@ - name: justlend_tron_base_borrow @@ - data_tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - transaction_type - - token_address - - tx_hash - - evt_index + data_tests: + - *borrow_unique_key_test - check_lending_base_borrow_seed: seed_file: ref('justlend_tron_base_borrow_seed')Also applies to: 105-110
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/_schema.yml` around lines 12 - 18, The duplicate dbt_utils.unique_combination_of_columns test block should be centralized using a YAML anchor and alias so the unique key stays consistent; create a single anchor (e.g. &unique_tx_key) for the block including combination_of_columns: [transaction_type, token_address, tx_hash, evt_index] in the schema file and replace the repeated blocks with the alias (<<: *unique_tx_key) in each model's data_tests entry (referencing the dbt_utils.unique_combination_of_columns block and its combination_of_columns keys) so future changes only need to be made once.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In
`@dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sql`:
- Around line 5-10: The incremental_predicates currently reference
DBT_INTERNAL_DEST.block_time which conflicts with partition_by =
['block_month']; change the predicate to use the partition-aligned column (e.g.,
DBT_INTERNAL_DEST.block_date or a derived block_month) instead of block_time,
and ensure any incremental WHERE/JOIN conditions include the partition column
block_month (or block_date) so pruning/merge efficiency is preserved; update the
incremental_predicates expression(s) and any related joins/filters in this model
(look for uses of incremental_predicate, incremental_predicates, partition_by,
block_month, and DBT_INTERNAL_DEST.block_time) accordingly.
---
Nitpick comments:
In
`@dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/_schema.yml`:
- Around line 12-18: The duplicate dbt_utils.unique_combination_of_columns test
block should be centralized using a YAML anchor and alias so the unique key
stays consistent; create a single anchor (e.g. &unique_tx_key) for the block
including combination_of_columns: [transaction_type, token_address, tx_hash,
evt_index] in the schema file and replace the repeated blocks with the alias
(<<: *unique_tx_key) in each model's data_tests entry (referencing the
dbt_utils.unique_combination_of_columns block and its combination_of_columns
keys) so future changes only need to be made once.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/lending_tron_borrow.sqldbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/_schema.ymldbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sqldbt_subprojects/hourly_spellbook/models/_sector/lending/supply/tron/_schema.yml
🚧 Files skipped from review as they are similar to previous changes (2)
- dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/lending_tron_borrow.sql
- dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/tron/_schema.yml
Thank you for contributing to Spellbook 🪄
Please open the PR in draft and mark as ready when you want to request a review.
Description:
[...]
quick links for more information: