@@ -47,7 +47,7 @@ pub struct MostLiquidAlgorithm {
4747pub struct DepthAndPrice {
4848 /// Spot price (token_out per token_in) for this edge direction.
4949 pub spot_price : f64 ,
50- /// Liquidity depth normalized to gas token (ETH ) units.
50+ /// Liquidity depth normalized to gas token (native token ) units.
5151 pub depth : f64 ,
5252}
5353
@@ -119,28 +119,53 @@ impl crate::graph::EdgeWeightFromSimAndDerived for DepthAndPrice {
119119 }
120120 } ;
121121
122- // Normalize depth from raw token_in units to gas token (ETH) units.
122+ // Normalize depth from raw token_in units to gas token units.
123123 // TokenGasPrices stores Price { numerator, denominator } where
124124 // numerator/denominator = "token units per gas token unit".
125- // To convert token->ETH: depth_eth = raw_depth * denominator / numerator.
125+ // To convert to gas token: depth_gas = raw_depth * denominator / numerator.
126126 let depth = match derived
127127 . token_prices ( )
128128 . and_then ( |p| p. get ( & token_in. address ) )
129129 {
130130 Some ( price) => {
131- let num = price. numerator . to_f64 ( ) . unwrap_or ( 0.0 ) ;
132- let den = price
133- . denominator
134- . to_f64 ( )
135- . unwrap_or ( 0.0 ) ;
136- if num == 0.0 || den == 0.0 {
137- trace ! (
138- component_id = %component_id,
139- token_in = %token_in. address,
140- "token price has zero numerator or denominator, skipping edge"
141- ) ;
142- return None ;
143- }
131+ let num = match price. numerator . to_f64 ( ) {
132+ Some ( v) if v > 0.0 => v,
133+ Some ( _) => {
134+ trace ! (
135+ component_id = %component_id,
136+ token_in = %token_in. address,
137+ "token price numerator is zero, skipping edge"
138+ ) ;
139+ return None ;
140+ }
141+ None => {
142+ trace ! (
143+ component_id = %component_id,
144+ token_in = %token_in. address,
145+ "token price numerator overflows f64, skipping edge"
146+ ) ;
147+ return None ;
148+ }
149+ } ;
150+ let den = match price. denominator . to_f64 ( ) {
151+ Some ( v) if v > 0.0 => v,
152+ Some ( _) => {
153+ trace ! (
154+ component_id = %component_id,
155+ token_in = %token_in. address,
156+ "token price denominator is zero, skipping edge"
157+ ) ;
158+ return None ;
159+ }
160+ None => {
161+ trace ! (
162+ component_id = %component_id,
163+ token_in = %token_in. address,
164+ "token price denominator overflows f64, skipping edge"
165+ ) ;
166+ return None ;
167+ }
168+ } ;
144169 raw_depth * den / num
145170 }
146171 None => {
@@ -653,7 +678,7 @@ impl Algorithm for MostLiquidAlgorithm {
653678 fn computation_requirements ( & self ) -> ComputationRequirements {
654679 // MostLiquidAlgorithm uses token prices for two purposes:
655680 // 1. Converting gas costs from wei to output token terms (net_amount_out)
656- // 2. Normalizing pool depth to ETH units for path scoring (from_sim_and_derived)
681+ // 2. Normalizing pool depth to gas token units for path scoring (from_sim_and_derived)
657682 //
658683 // Token prices are marked as `allow_stale` since they don't change much
659684 // block-to-block. Stale prices affect scoring order (not correctness)
0 commit comments