Skip to content

fix(dex): use sold-token ERC4626 price for Balancer V3 amount_usd fallback#9809

Open
tiagoponciano wants to merge 1 commit into
duneanalytics:mainfrom
neo-empresarial:@tpa/fixing/token-prices
Open

fix(dex): use sold-token ERC4626 price for Balancer V3 amount_usd fallback#9809
tiagoponciano wants to merge 1 commit into
duneanalytics:mainfrom
neo-empresarial:@tpa/fixing/token-prices

Conversation

@tiagoponciano

Copy link
Copy Markdown

Summary

  • Fixes a bug in enrich_balancer_v3_dex_trades where the ERC4626 fallback for amount_usd multiplied token_sold_amount by the bought token price (erc4626a.price) instead of the sold token price (erc4626b.price).
  • Aligns the sold-side USD fallback with the existing joins: erc4626a is keyed on token_bought_address, erc4626b on token_sold_address.

Context

When add_amount_usd_dex_trades does not produce amount_usd, the macro falls back to ERC4626 median prices:

COALESCE(
    dexs.amount_usd,
    dexs.token_bought_amount * erc4626a.price,
    dexs.token_sold_amount * erc4626b.price  -- was erc4626a.price
) AS amount_usd

Using the bought-token price for sold quantity understated or overstated USD volume on trades where only the sold leg is an ERC4626 wrapper and the bought leg is not (or has no price at that minute).

Files changed

File Change
dbt_subprojects/dex/macros/models/enrich_balancer_v3_dex_trades.sql token_sold_amount * erc4626a.priceerc4626b.price

@github-actions github-actions Bot marked this pull request as draft June 18, 2026 13:00
@github-actions github-actions Bot added WIP work in progress dbt: dex covers the DEX dbt subproject labels Jun 18, 2026
@tiagoponciano tiagoponciano marked this pull request as ready for review June 18, 2026 13:00
@github-actions github-actions Bot added ready-for-review this PR development is complete, please review and removed WIP work in progress labels Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dbt: dex covers the DEX 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