Skip to content

Commit

Permalink
fix: write third token in second word for 3 hop route
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jul 4, 2024
1 parent b82d2e7 commit e8949c3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/ReservoirPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { OracleErrors } from "src/libraries/OracleErrors.sol";
import {
IReservoirPriceOracle,
OracleAverageQuery,
OracleLatestQuery,
OracleLatestQuery
} from "src/interfaces/IReservoirPriceOracle.sol";
import { IPriceOracle } from "src/interfaces/IPriceOracle.sol";
import { QueryProcessor, ReservoirPair, PriceType } from "src/libraries/QueryProcessor.sol";
Expand Down Expand Up @@ -277,7 +277,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
assembly {
lSecondWord := sload(add(lSlot, 1))
}
address lThirdToken = lFirstWord.getThirdToken(lSecondWord);
address lThirdToken = lSecondWord.getThirdToken();

lResults[2] = lThirdToken;
lResults[3] = aToken1;
Expand Down
14 changes: 4 additions & 10 deletions src/libraries/FlagsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ library FlagsLib {
pure
returns (bytes32 rFirstWord, bytes32 rSecondWord)
{
bytes32 lThirdTokenTop10Bytes = bytes32(bytes20(aThirdToken)) >> 176;
// Trim away the first 10 bytes since we only want the last 10 bytes.
bytes32 lThirdTokenBottom10Bytes = bytes32(bytes20(aThirdToken) << 80);

rFirstWord = FLAG_3_HOP_ROUTE | bytes32(bytes20(aSecondToken)) >> 8 | lThirdTokenTop10Bytes;
rSecondWord = lThirdTokenBottom10Bytes;
rFirstWord = FLAG_3_HOP_ROUTE | bytes32(bytes20(aSecondToken)) >> 8;
rSecondWord = bytes20(aThirdToken);
}

function getPrice(bytes32 aData) internal pure returns (uint256 rPrice) {
Expand All @@ -64,9 +60,7 @@ library FlagsLib {
address(uint160(uint256(aData & 0x00ffffffffffffffffffffffffffffffffffffffff0000000000000000000000) >> 88));
}

function getThirdToken(bytes32 aFirstWord, bytes32 aSecondWord) internal pure returns (address rToken) {
bytes32 lTop10Bytes = (aFirstWord & 0x00000000000000000000000000000000000000000000ffffffffffffffffffff) << 80;
bytes32 lBottom10Bytes = aSecondWord >> 176;
rToken = address(uint160(uint256(lTop10Bytes | lBottom10Bytes)));
function getThirdToken(bytes32 aSecondWord) internal pure returns (address rToken) {
rToken = address(bytes20(aSecondWord));
}
}
2 changes: 0 additions & 2 deletions test/unit/ReservoirPriceOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { BaseTest, console2, ReservoirPair, MintableERC20 } from "test/__fixture

import { Utils } from "src/libraries/Utils.sol";
import {
Buffer,
FixedPointMathLib,
PriceType,
OracleErrors,
OracleLatestQuery,
OracleAccumulatorQuery,
OracleAverageQuery,
ReservoirPriceOracle,
IERC20,
Expand Down

0 comments on commit e8949c3

Please sign in to comment.