fix(dex): use sold-token ERC4626 price for Balancer V3 amount_usd fallback#9809
Open
tiagoponciano wants to merge 1 commit into
Open
fix(dex): use sold-token ERC4626 price for Balancer V3 amount_usd fallback#9809tiagoponciano wants to merge 1 commit into
amount_usd fallback#9809tiagoponciano wants to merge 1 commit into
Conversation
…sold_amount calculation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
enrich_balancer_v3_dex_tradeswhere the ERC4626 fallback foramount_usdmultipliedtoken_sold_amountby the bought token price (erc4626a.price) instead of the sold token price (erc4626b.price).erc4626ais keyed ontoken_bought_address,erc4626bontoken_sold_address.Context
When
add_amount_usd_dex_tradesdoes not produceamount_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_usdUsing 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
dbt_subprojects/dex/macros/models/enrich_balancer_v3_dex_trades.sqltoken_sold_amount * erc4626a.price→erc4626b.price