File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
src/evm/protocol/uniswap_v4 Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use std::{any::Any, collections::HashMap};
22
33use alloy:: primitives:: { Address , Sign , I256 , U256 } ;
44use num_bigint:: BigUint ;
5- use num_traits:: { ToPrimitive , Zero } ;
5+ use num_traits:: { CheckedSub , ToPrimitive , Zero } ;
66use revm:: primitives:: I128 ;
77use tracing:: trace;
88use tycho_common:: {
@@ -383,8 +383,19 @@ impl ProtocolSim for UniswapV4State {
383383 let y2 = self . get_amount_out ( x2. clone ( ) , base, quote) ?;
384384
385385 // Calculate the marginal price
386- let num = & y2. amount - & y1. amount ;
387- let den = & x2 - & x1;
386+ let num = y2
387+ . amount
388+ . checked_sub ( & y1. amount )
389+ . ok_or_else ( || {
390+ SimulationError :: FatalError (
391+ "Cannot calculate spot price: y2 < y1" . to_string ( ) ,
392+ )
393+ } ) ?;
394+ let den = x2. checked_sub ( & x1) . ok_or_else ( || {
395+ SimulationError :: FatalError (
396+ "Cannot calculate spot price: x2 < x1" . to_string ( ) ,
397+ )
398+ } ) ?;
388399
389400 if den == BigUint :: from ( 0u64 ) {
390401 return Err ( SimulationError :: FatalError (
You can’t perform that action at this time.
0 commit comments