fix: normalize pool depth to ETH for path scoring#175
Merged
Conversation
653a7d4 to
2982e49
Compare
tvinagre
commented
Apr 1, 2026
| // Look up pre-computed depth; skip edge if unavailable. | ||
| let depth = match derived | ||
| let raw_depth = match derived | ||
| .pool_depths() |
Collaborator
Author
There was a problem hiding this comment.
Please note that I chose to not change how pool_depth was calculated. It's still denominated in sell_token, we just normalize here for this algorithm usage.
Fixing the calculation would change a lot, as it would create another dependency layer (pool_depth needs token_prices). IMO this is fine to be done here - we can move to the derived_data layer if preferred.
louise-poole
approved these changes
Apr 1, 2026
Contributor
louise-poole
left a comment
There was a problem hiding this comment.
Two minor comments, otherwise looks good! Interesting that pre-normalising results had some better paths it found... I expected with normalising we'd find the same or better always. What max_routes value did you run these benchmarks with?
zizou0x
reviewed
Apr 1, 2026
4181b4a to
e5c03f6
Compare
Depth values were stored in raw token_in units, making min(depths) across hops meaningless when comparing different token denominations. Now converts depth to ETH-equivalent using TokenGasPrices. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Existing tests need token prices in DerivedData now that depth normalization requires them. Tests still verify the same conditions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… paths - Replace "ETH" with "gas token" / "native token" in comments and docs - Separate to_f64 overflow from zero-value in token price conversion so each failure case has a distinct trace message Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e5c03f6 to
0968040
Compare
|
This PR is included in version 0.44.1 🎉 |
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
token_inunits to ETH-equivalent inDepthAndPrice::from_sim_and_derived, usingTokenGasPricesalready available inDerivedDatamin(depths)comparison across hops — previously meaningless when comparing different token denominations (e.g., WETH 18 decimals vs USDC 6 decimals)Problem
MostLiquidAlgorithm::try_score_pathcomputesscore = product(spot_prices) × min(depths)to prioritize which paths to simulate. Depth was stored in rawtoken_inunits, so a WETH edge depth of1e18(1 WETH) appeared 10^12x larger than a USDC depth of1e9(1000 USDC). This caused misordered simulation priority, and withmax_routestruncation or timeout, genuinely good paths could be permanently excluded.Changes
Single file change:
fynd-core/src/algorithm/most_liquid.rsProduction code:
from_sim_and_derived: after reading rawBigUintdepth, converts to ETH usingdepth_eth = raw_depth * denominator / numeratorfromTokenGasPricesNone(skips edge) if token price is missing or has zero numerator/denominatordepthfield doc comment andcomputation_requirements()commentTests (6 new/updated):
DerivedDatatest_from_sim_and_derived_missing_token_price_returns_nonetest_from_sim_and_derived_normalizes_depth_to_eth(integer price ratio)test_from_sim_and_derived_normalizes_depth_fractional_price(fractional price ratio)Benchmark Results (500 requests,
fynd-benchmark compare)Key takeaways:
Test plan
-D warnings)🤖 Generated with Claude Code