Skip to content

add files to connect four new EVM chains on balancerv3#9425

Merged
jeff-dude merged 16 commits intoduneanalytics:mainfrom
gustavobftorres:add-avalanche-to-balancer-hourly
Mar 31, 2026
Merged

add files to connect four new EVM chains on balancerv3#9425
jeff-dude merged 16 commits intoduneanalytics:mainfrom
gustavobftorres:add-avalanche-to-balancer-hourly

Conversation

@gustavobftorres
Copy link
Copy Markdown
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:

Connect Avalanche C chain into balancer_v3


quick links for more information:

@github-actions github-actions Bot marked this pull request as draft March 6, 2026 20:13
@github-actions github-actions Bot added WIP work in progress dbt: hourly covers the hourly dbt subproject labels Mar 6, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 6, 2026

📝 Walkthrough

Walkthrough

Adds Balancer v3 support for the Avalanche C chain: new schema declarations and ~30 dbt models (token balances, BPT, ERC4626, pools/LBPs, liquidity, protocol fees) and updates aggregation models to include the new Avalanche C sources.

Changes

Cohort / File(s) Summary
Balances (schema & models)
dbt_subprojects/hourly_spellbook/models/_project/balancer/balances/avalanche_c/_schema.yml, dbt_subprojects/hourly_spellbook/models/_project/balancer/balances/avalanche_c/balancer_v3_avalanche_c_token_balance_changes.sql, dbt_subprojects/hourly_spellbook/models/_project/balancer/balances/avalanche_c/balancer_v3_avalanche_c_token_balance_changes_daily.sql
Added two v3 token balance-change models and corresponding schema entries; materialized as delta tables and delegated to existing v3-compatible macros.
BPT (schema & models)
dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/avalanche_c/_schema.yml, .../bpt/avalanche_c/balancer_v3_avalanche_c_transfers_bpt.sql, .../bpt/avalanche_c/balancer_v3_avalanche_c_bpt_prices.sql, .../bpt/avalanche_c/balancer_v3_avalanche_c_bpt_supply.sql, .../bpt/avalanche_c/balancer_v3_avalanche_c_bpt_supply_changes.sql, .../bpt/avalanche_c/balancer_v3_avalanche_c_bpt_supply_changes_daily.sql
Added five BPT-related models (transfers, prices, supply, supply_changes, daily) and schema entries; incremental/table configs + macros.
ERC4626 (schema & models)
dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/avalanche_c/_schema.yml, .../erc4626_tokens/avalanche_c/balancer_v3_avalanche_c_erc4626_token_mapping.sql, .../erc4626_tokens/avalanche_c/balancer_v3_avalanche_c_erc4626_token_prices.sql
Added ERC4626 mapping and price models with schema defs; mapping links vault→underlying, prices compute median per-minute with incremental merge.
Pools & LBPs (schema & models)
dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/avalanche_c/_schema.yml, .../pools/avalanche_c/balancer_v3_avalanche_c_pools_tokens_weights.sql, .../pools/avalanche_c/balancer_v3_avalanche_c_lbps.sql
Added pools token-weights incremental model and LBP table model plus schema entries; weights model unnests token lists and scales normalized weights.
Liquidity (schema & model)
dbt_subprojects/hourly_spellbook/models/_project/balancer/liquidity/avalanche_c/_schema.yml, .../liquidity/avalanche_c/balancer_v3_avalanche_c_liquidity.sql
Added liquidity schema and a v3 liquidity table model that calls existing liquidity macro for Avalanche C.
Protocol Fee (schema & model)
dbt_subprojects/hourly_spellbook/models/_project/balancer/protocol_fee/avalanche_c/_schema.yml, .../protocol_fee/avalanche_c/balancer_v3_avalanche_c_protocol_fee.sql
Added protocol_fee schema and v3 protocol fee table model for Avalanche C using existing macro.
Aggregation updates
dbt_subprojects/hourly_spellbook/models/_project/balancer/.../balancer_token_balance_changes.sql, .../balancer_token_balance_changes_daily.sql, .../balancer_bpt_prices.sql, .../balancer_bpt_supply.sql, .../balancer_bpt_supply_changes.sql, .../balancer_bpt_supply_changes_daily.sql, .../balancer_transfers_bpt.sql, .../erc4626_tokens/balancer_v3_erc4626_token_mapping.sql, .../erc4626_tokens/balancer_v3_erc4626_token_prices.sql, .../balancer_liquidity.sql, .../balancer_v3_lbps.sql, .../balancer_protocol_fee.sql
Extended multiple aggregation/union models to include the new Avalanche C v3 model refs (added refs and adjusted commas); no control-flow changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

dbt: dex

Suggested reviewers

  • jeff-dude
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description provides a brief summary ('Connect Avalanche C chain into balancer_v3') but lacks detailed context about specific changes, testing, or technical implementation details expected in a repository with a defined template. Expand the description to explain which Balancer v3 components are being added for Avalanche C, any testing performed, and reference relevant documentation or issues.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main change: adding files to connect Avalanche C to Balancer v3, which is the primary objective evident from all file changes.
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.

Copy link
Copy Markdown

@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: 2

🤖 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/_project/balancer/erc4626_tokens/avalanche_c/balancer_v3_avalanche_c_erc4626_token_prices.sql`:
- Line 64: The LEAD(...) fallback uses CURRENT_DATE + INTERVAL '1' day which
makes next_change vary between runs; change the LEAD default for next_change
(the expression with LEAD(p.evt_block_time, 1, ... ) OVER (PARTITION BY
wrappedToken ORDER BY p.evt_block_time)) to use a stable far-future sentinel
timestamp (e.g. a constant like '9999-12-31' or similar) or alternatively modify
the incremental logic to always reprocess the previous terminal row per
wrappedToken so that the next_change value remains stable across runs; update
the LEAD fallback accordingly and ensure references to next_change continue to
use that column alias.
- Around line 49-50: The model currently joins on DATE_TRUNC('minute',
w.evt_block_time) but emits the raw evt_block_time as minute, causing sub-minute
rows; change the SELECT and any emitted minute column (and unique key) to use
DATE_TRUNC('minute', w.evt_block_time) (or p.minute) consistently so the
published minute grain is truncated to minute for functions/tables like minute
in the SELECT, the unique key, and any incremental filters (see the join using
w.evt_block_time, the emitted minute field, and the incremental block around
is_incremental()).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ae64a101-9a83-4936-a687-99d4c72ed4c9

📥 Commits

Reviewing files that changed from the base of the PR and between 5a27bde and b26fb7f.

📒 Files selected for processing (32)
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/balances/avalanche_c/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/balances/avalanche_c/balancer_v3_avalanche_c_token_balance_changes.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/balances/avalanche_c/balancer_v3_avalanche_c_token_balance_changes_daily.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/balances/balancer_token_balance_changes.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/balances/balancer_token_balance_changes_daily.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/avalanche_c/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/avalanche_c/balancer_v3_avalanche_c_bpt_prices.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/avalanche_c/balancer_v3_avalanche_c_bpt_supply.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/avalanche_c/balancer_v3_avalanche_c_bpt_supply_changes.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/avalanche_c/balancer_v3_avalanche_c_bpt_supply_changes_daily.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/avalanche_c/balancer_v3_avalanche_c_transfers_bpt.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/balancer_bpt_prices.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/balancer_bpt_supply.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/balancer_bpt_supply_changes.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/balancer_bpt_supply_changes_daily.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/bpt/balancer_transfers_bpt.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/avalanche_c/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/avalanche_c/balancer_v3_avalanche_c_erc4626_token_mapping.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/avalanche_c/balancer_v3_avalanche_c_erc4626_token_prices.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/balancer_v3_erc4626_token_mapping.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/balancer_v3_erc4626_token_prices.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/liquidity/avalanche_c/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/liquidity/avalanche_c/balancer_v3_avalanche_c_liquidity.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/liquidity/balancer_liquidity.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/avalanche_c/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/avalanche_c/balancer_avalanche_c_pools_tokens_weights.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/avalanche_c/balancer_v3_avalanche_c_lbps.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/avalanche_c/balancer_v3_avalanche_c_pools_tokens_weights.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/balancer_v3_lbps.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/protocol_fee/avalanche_c/_schema.yml
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/protocol_fee/avalanche_c/balancer_v3_avalanche_c_protocol_fee.sql
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/protocol_fee/balancer_protocol_fee.sql

@gustavobftorres gustavobftorres marked this pull request as ready for review March 6, 2026 20:43
@github-actions github-actions Bot added ready-for-review this PR development is complete, please review and removed WIP work in progress labels Mar 6, 2026
Copy link
Copy Markdown

@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/_project/balancer/erc4626_tokens/avalanche_c/balancer_v3_avalanche_c_erc4626_token_prices.sql (1)

19-20: ⚠️ Potential issue | 🟠 Major

Recompute the previous terminal row for touched tokens.

The incremental filters on Line 20 and Line 31 only rebuild recent events. When a wrapped_token changes again after that window, the older row already stored in {{ this }} keeps the far-future next_change from Line 64, and the new row gets one too. That leaves overlapping validity ranges for the same token, so downstream as-of joins can match both prices after the new event. Re-include the prior terminal row for each touched token in incremental runs, or otherwise update its next_change before the merge.

Based on learnings, incremental_predicate('evt_block_time') typically filters to the last ~3 days.

Also applies to: 30-31, 64-64

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/avalanche_c/balancer_v3_avalanche_c_erc4626_token_prices.sql`
around lines 19 - 20, The incremental WHERE using
incremental_predicate('evt_block_time') rebuilds only recent events and can
leave an older terminal row in {{ this }} with a far-future next_change for the
same wrapped_token, creating overlapping validity ranges; fix by, when
is_incremental() is true, identifying wrapped_token values touched by the
incremental window (using evt_block_time) and (a) re-selecting their previous
terminal rows from {{ this }} (rows where next_change IS NULL or >
max(evt_block_time)) into the incremental insert so the prior terminal row is
recomputed, or (b) updating that prior row’s next_change to the new event time
before the final merge — reference incremental_predicate('evt_block_time'),
is_incremental(), wrapped_token, evt_block_time, next_change and {{ this }} to
locate the code to change.
🤖 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/_project/balancer/erc4626_tokens/avalanche_c/balancer_v3_avalanche_c_erc4626_token_prices.sql`:
- Around line 19-20: The incremental WHERE using
incremental_predicate('evt_block_time') rebuilds only recent events and can
leave an older terminal row in {{ this }} with a far-future next_change for the
same wrapped_token, creating overlapping validity ranges; fix by, when
is_incremental() is true, identifying wrapped_token values touched by the
incremental window (using evt_block_time) and (a) re-selecting their previous
terminal rows from {{ this }} (rows where next_change IS NULL or >
max(evt_block_time)) into the incremental insert so the prior terminal row is
recomputed, or (b) updating that prior row’s next_change to the new event time
before the final merge — reference incremental_predicate('evt_block_time'),
is_incremental(), wrapped_token, evt_block_time, next_change and {{ this }} to
locate the code to change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ba79a840-b283-4505-8f5d-46f701c9d3fe

📥 Commits

Reviewing files that changed from the base of the PR and between b26fb7f and 7661468.

📒 Files selected for processing (1)
  • dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/avalanche_c/balancer_v3_avalanche_c_erc4626_token_prices.sql

@gustavobftorres
Copy link
Copy Markdown
Contributor Author

all four chains merged to this PR

@jeff-dude jeff-dude changed the title add files to connect avalanche on balancerv3 add files to connect four new EVM chains on balancerv3 Mar 24, 2026
@jeff-dude jeff-dude merged commit 523b020 into duneanalytics:main Mar 31, 2026
3 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 31, 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-merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants