refactor: replace DFS market price with Bellman-Ford SPFA#103
Conversation
ae6e485 to
856187b
Compare
| //! propagating to all reachable tokens within `max_hops`. Uses forbid-revisits to prevent | ||
| //! paths through arbitrage loops that would distort prices. | ||
| //! | ||
| //! This is the pricing counterpart to the routing BF in `bellman_ford.rs`: |
There was a problem hiding this comment.
bellman_ford.rs doesn't exist in this branch
There was a problem hiding this comment.
Fixed. Rebased on main (which now includes PR #43), and changed this to a proper module link: [bellman_ford](super::bellman_ford).
| #[allow(dead_code)] | ||
| pub fn amount_at(&self, node: NodeIndex) -> &BigUint { | ||
| &self.distance[node.index()] | ||
| } |
There was a problem hiding this comment.
let's not introduce dead code if we don't need it 🧹
There was a problem hiding this comment.
Removed from production code. Moved behind #[cfg(test)] since it's only used in test assertions.
| let state_override = if is_vm { | ||
| vm_state_override.as_ref() | ||
| } else { | ||
| native_state_overrides.get(component_id) | ||
| }; |
There was a problem hiding this comment.
why is this needed?
There was a problem hiding this comment.
Good catch, it wasn't needed. Forbid-revisits guarantees each pool appears at most once in a path, so state overrides can never trigger. Removed the entire VM/native state-override tracking, the EVMPoolState downcast, and the related imports.
Add bellman_ford_pricing.rs with flat-array SPFA that prices all tokens from gas_token in a single traversal, using simulation during relaxation instead of the DFS + spot-price heuristic approach. Rewrite token_gas_price.rs to use BF forward pass + reverse simulation per token. Removes SpotPrices dependency entirely. Selects paths by highest forward output (most liquid) rather than lowest spread. 12/12 tests pass. No regressions in full suite. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove unused Path::reversed() method (was only needed by DFS-based pricing) - Update dependency graph docs: TokenGasPriceComputation no longer depends on spot_prices - Fix PoolDepthComputation dependency comment (it depends on spot_prices, not "no dependencies") Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… resimulate - Extract shared helpers (path_has_conflict, reconstruct_path, extract_subgraph_edges) into bf_helpers.rs, used by both routing and pricing BF modules - Remove dead amount_at method (moved to #[cfg(test)] only) - Simplify resimulate_path: remove state-override tracking since forbid-revisits guarantees each pool appears at most once - Fix doc comment to use proper module link instead of file reference - Remove unused ProtocolSim import and dead simulation_amount accessor Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
856187b to
b90fb3e
Compare
|
Addressed all review comments. Rebased on main (which now includes PR #43) and deduplicated the shared code:
285 lib tests pass, zero clippy warnings. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dianacarvalho1
left a comment
There was a problem hiding this comment.
Thank you @Haikane
Resolve conflict in token_gas_price.rs by taking the BF branch version, which replaces the DFS-based pricing entirely with Bellman-Ford SPFA. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Let's not merge this now as it interferes with https://github.com/propeller-heads/fynd/pull/95/changes |
Summary
TokenGasPriceComputationwith Bellman-Ford SPFA one-to-all pricingbellman_ford_pricing.rsmodule: single SPFA pass from WETH prices all tokens using actualget_amount_out()simulation during relaxation, replacing DFS path enumeration + spot-price heuristic scoringSpotPriceComputationdependency from token gas pricing (still used by pool depths and MostLiquid)Benchmark results
Token coverage is 0.1-1.9% lower due to BF's forbid-revisits pruning marginal paths through low-liquidity pools.
Test plan
cargo clippy --lib -- -D warnings: zero warnings