Skip to content

Commit

Permalink
fix: process 2 hop route before 3 hop route
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jul 7, 2024
1 parent 29107aa commit 81cdb3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/ReservoirPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/RoutesLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 81cdb3d

Please sign in to comment.