diff --git a/src/ReservoirPriceOracle.sol b/src/ReservoirPriceOracle.sol index 81a3549..5e9fe8d 100644 --- a/src/ReservoirPriceOracle.sol +++ b/src/ReservoirPriceOracle.sol @@ -271,8 +271,11 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. else if (lFirstWord.isCompositeRoute()) { address lSecondToken = lFirstWord.getTokenFirstWord(); - // REVIEW: Is it more logical to handle `is2HopRoute` then fallback to `assert(is3HopRoute)`? - if (lFirstWord.is3HopRoute()) { + if (lFirstWord.is2HopRoute()) { + rRoute = new address[](3); + rRoute[2] = aToken1; + } else { + assert(lFirstWord.is3HopRoute()); bytes32 lSecondWord; assembly { lSecondWord := sload(add(lSlot, 1)) @@ -282,16 +285,12 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. rRoute = new address[](4); rRoute[2] = lThirdToken; rRoute[3] = aToken1; - } else { - rRoute = new address[](3); - rRoute[2] = aToken1; } rRoute[0] = aToken0; rRoute[1] = lSecondToken; } // no route - // solhint-disable-next-line no-empty-blocks else if (lFirstWord.isUninitialized()) { rRoute = new address[](0); } diff --git a/src/libraries/RoutesLib.sol b/src/libraries/RoutesLib.sol index 0bc207c..72b4a83 100644 --- a/src/libraries/RoutesLib.sol +++ b/src/libraries/RoutesLib.sol @@ -19,6 +19,10 @@ library RoutesLib { return aData[0] & hex"02" > 0; } + function is2HopRoute(bytes32 aData) internal pure returns (bool) { + return aData[0] == FLAG_2_HOP_ROUTE; + } + function is3HopRoute(bytes32 aData) internal pure returns (bool) { return aData[0] == FLAG_3_HOP_ROUTE; }