Skip to content

ST-203: tron justlend#9380

Merged
tomfutago merged 8 commits intomainfrom
ST-203-tron-justlend
Feb 27, 2026
Merged

ST-203: tron justlend#9380
tomfutago merged 8 commits intomainfrom
ST-203-tron-justlend

Conversation

@tomfutago
Copy link
Contributor

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:

@github-actions github-actions bot added WIP work in progress dbt: hourly covers the hourly dbt subproject labels Feb 27, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

Adds Tron support for JustLend lending: introduces new borrow and supply models (base, platform, enriched, final), schema updates (rename usd_amountamount_usd, add loan_type), seeds, ctokens mapping, and JustLend Tron source definitions.

Changes

Cohort / File(s) Summary
Lending — Borrow schema & models
dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/_schema.yml, .../borrow/lending_tron_borrow.sql, .../borrow/tron/_schema.yml, .../borrow/tron/lending_tron_base_borrow.sql, .../borrow/tron/platforms/justlend_tron_base_borrow.sql
Added loan_type, renamed usd_amountamount_usd in schema; added lending_tron_borrow (incremental enriched model), lending_tron_base_borrow (union view), and justlend_tron_base_borrow (platform incremental using lending_compound_v2 macro).
Lending — Supply schema & models
dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/_schema.yml, .../supply/lending_tron_supply.sql, .../supply/tron/_schema.yml, .../supply/tron/lending_tron_base_supply.sql, .../supply/tron/platforms/justlend_tron_base_supply.sql
Renamed usd_amountamount_usd; added lending_tron_supply (incremental enriched model), lending_tron_base_supply (union view), and justlend_tron_base_supply (platform incremental using lending_compound_v2 macro).
Supporting artifacts (ctokens, seeds, sources)
dbt_subprojects/hourly_spellbook/models/_sector/lending/ctokens/justlend_tron_ctokens.sql, dbt_subprojects/hourly_spellbook/seeds/_sector/lending/_schema.yml, sources/justlend/tron/sources.yml
Added JustLend TRON ctokens mapping (multiple token entries); added seeds justlend_tron_base_supply_seed and justlend_tron_base_borrow_seed (column types); added JustLend Tron source with event tables for jusdt/jusdd/cether.

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
Loading
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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description only contains template placeholder text with no actual technical details, context, or explanation of the changes being made. Replace the placeholder with a meaningful description explaining what Tron JustLend models are being added, why they are needed, and any relevant implementation details or testing information.
Title check ❓ Inconclusive The title 'ST-203: tron justlend' is vague and generic, using only task ID and vague technology terms without describing the actual change being implemented. Replace with a more descriptive title that explains what is being added, such as 'Add Tron JustLend lending borrow and supply models' to clearly convey the primary change.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@tomfutago tomfutago marked this pull request as ready for review February 27, 2026 13:59
@github-actions github-actions bot added ready-for-review this PR development is complete, please review and removed WIP work in progress labels Feb 27, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: Add block_month to unique_key for partition-aligned incremental merges.

The model partitions by block_month (line 5) but the unique_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

📥 Commits

Reviewing files that changed from the base of the PR and between 735c411 and 0b28c69.

⛔ Files ignored due to path filters (2)
  • dbt_subprojects/hourly_spellbook/seeds/_sector/lending/justlend_tron_base_borrow_seed.csv is excluded by !**/*.csv
  • dbt_subprojects/hourly_spellbook/seeds/_sector/lending/justlend_tron_base_supply_seed.csv is excluded by !**/*.csv
📒 Files selected for processing (13)
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/lending_tron_borrow.sql
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/lending_tron_base_borrow.sql
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/platforms/justlend_tron_base_borrow.sql
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/ctokens/justlend_tron_ctokens.sql
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sql
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/tron/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/tron/lending_tron_base_supply.sql
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/tron/platforms/justlend_tron_base_supply.sql
  • dbt_subprojects/hourly_spellbook/seeds/_sector/lending/_schema.yml
  • sources/justlend/tron/sources.yml

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sql (1)

5-10: ⚠️ Potential issue | 🟠 Major

Switch the incremental predicate off block_time.

Line 10 still predicates on DBT_INTERNAL_DEST.block_time, which is misaligned with partition_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_columns block 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0b28c69 and a032446.

📒 Files selected for processing (4)
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/lending_tron_borrow.sql
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/borrow/tron/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_sector/lending/supply/lending_tron_supply.sql
  • dbt_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

@tomfutago tomfutago merged commit 6d52774 into main Feb 27, 2026
4 of 5 checks passed
@tomfutago tomfutago deleted the ST-203-tron-justlend branch February 27, 2026 16:40
@github-actions github-actions bot locked and limited conversation to collaborators Feb 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

dbt: hourly covers the hourly dbt subproject ready-for-review this PR development is complete, please review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant