Skip to content

Commit

Permalink
factor out _validateTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverNChalk committed Jul 7, 2024
1 parent d67540c commit 1871c18
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/ReservoirPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,16 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
// INTERNAL FUNCTIONS //
///////////////////////////////////////////////////////////////////////////////////////////////

function _validatePair(ReservoirPair aPair) internal pure {
function _validatePair(ReservoirPair aPair) private pure {
if (address(aPair) == address(0)) revert OracleErrors.NoDesignatedPair();
}

function _validateTokens(address aToken0, address aToken1) private pure {
// REVIEW: Can be collapsed into `if (aToken1 <= aToken1) revert`.
if (aToken0 == aToken1) revert OracleErrors.SameToken();
if (aToken1 < aToken0) revert OracleErrors.TokensUnsorted();
}

function _getTimeWeightedAverageSingle(OracleAverageQuery memory aQuery) internal view returns (uint256 rResult) {
ReservoirPair lPair = pairs[aQuery.base][aQuery.quote];
_validatePair(lPair);
Expand Down Expand Up @@ -498,8 +504,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
function setRoute(address aToken0, address aToken1, address[] memory aRoute) public onlyOwner {
uint256 lRouteLength = aRoute.length;

if (aToken0 == aToken1) revert OracleErrors.SameToken();
if (aToken1 < aToken0) revert OracleErrors.TokensUnsorted();
_validateTokens(aToken0, aToken1);
if (lRouteLength > Constants.MAX_ROUTE_LENGTH || lRouteLength < 2) revert OracleErrors.InvalidRouteLength();
if (aRoute[0] != aToken0 || aRoute[lRouteLength - 1] != aToken1) revert OracleErrors.InvalidRoute();

Expand Down Expand Up @@ -546,8 +551,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
}

function clearRoute(address aToken0, address aToken1) external onlyOwner {
if (aToken0 == aToken1) revert OracleErrors.SameToken();
if (aToken1 < aToken0) revert OracleErrors.TokensUnsorted();
_validateTokens(aToken0, aToken1);

(address[] memory lRoute,,) = _getRouteDecimalDifferencePrice(aToken0, aToken1);

Expand Down

0 comments on commit 1871c18

Please sign in to comment.