Skip to content

Commit

Permalink
fix: disassociate address type with Utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jul 4, 2024
1 parent b34cd83 commit b82d2e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/ReservoirPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import {
IReservoirPriceOracle,
OracleAverageQuery,
OracleLatestQuery,
OracleAccumulatorQuery
} from "src/interfaces/IReservoirPriceOracle.sol";
import { IPriceOracle } from "src/interfaces/IPriceOracle.sol";
import { QueryProcessor, ReservoirPair, Buffer, PriceType } from "src/libraries/QueryProcessor.sol";
import { QueryProcessor, ReservoirPair, PriceType } from "src/libraries/QueryProcessor.sol";
import { Utils } from "src/libraries/Utils.sol";
import { Owned } from "lib/amm-core/lib/solmate/src/auth/Owned.sol";
import { ReentrancyGuard } from "lib/amm-core/lib/solmate/src/utils/ReentrancyGuard.sol";
Expand All @@ -26,7 +25,6 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
using LibSort for address[];
using FlagsLib for *;
using QueryProcessor for ReservoirPair;
using Utils for address;

///////////////////////////////////////////////////////////////////////////////////////////////
// EVENTS //
Expand Down Expand Up @@ -136,13 +134,13 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
/// @param aTokenB Address of one of the tokens for the price update. Does not have to be greater than address of aTokenA
/// @param aRewardRecipient The beneficiary of the reward. Must be able to receive ether. Set to address(0) if not seeking a reward
function updatePrice(address aTokenA, address aTokenB, address aRewardRecipient) public nonReentrant {
(address lToken0, address lToken1) = aTokenA.sortTokens(aTokenB);
(address lToken0, address lToken1) = Utils.sortTokens(aTokenA, aTokenB);

(address[] memory lRoute,, uint256 lPrevPrice) = _getRouteDecimalDifferencePrice(lToken0, lToken1);
if (lRoute.length == 0) revert OracleErrors.NoPath();

for (uint256 i = 0; i < lRoute.length - 1; ++i) {
(lToken0, lToken1) = lRoute[i].sortTokens(lRoute[i + 1]);
(lToken0, lToken1) = Utils.sortTokens(lRoute[i], lRoute[i + 1]);

uint256 lNewPrice = _getTimeWeightedAverageSingle(
OracleAverageQuery(
Expand Down Expand Up @@ -303,7 +301,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
/// route. If there isn't an existing route, we write it as well.
/// @dev assumed that aToken0 and aToken1 are not necessarily sorted
function _checkAndPopulateIntermediateRoute(address aToken0, address aToken1) internal {
(address lLowerToken, address lHigherToken) = aToken0.sortTokens(aToken1);
(address lLowerToken, address lHigherToken) = Utils.sortTokens(aToken0, aToken1);

bytes32 lSlot = Utils.calculateSlot(lLowerToken, lHigherToken);
bytes32 lData;
Expand Down Expand Up @@ -362,7 +360,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
if (aBase == aQuote) return (aAmount, aAmount);
if (aAmount > Constants.MAX_AMOUNT_IN) revert OracleErrors.AmountInTooLarge();

(address lToken0, address lToken1) = aBase.sortTokens(aQuote);
(address lToken0, address lToken1) = Utils.sortTokens(aBase, aQuote);
(address[] memory lRoute, int256 lDecimalDiff, uint256 lPrice) =
_getRouteDecimalDifferencePrice(lToken0, lToken1);

Expand Down Expand Up @@ -393,7 +391,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
assert(lRoute[0] == aBase);

for (uint256 i = 0; i < lRoute.length - 1; ++i) {
(address lLowerToken, address lHigherToken) = lRoute[i].sortTokens(lRoute[i + 1]);
(address lLowerToken, address lHigherToken) = Utils.sortTokens(lRoute[i], lRoute[i + 1]);
// it is assumed that intermediate routes defined here are simple routes and not composite routes
(lPrice, lDecimalDiff) = _priceCache(lLowerToken, lHigherToken);

Expand Down Expand Up @@ -478,7 +476,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.

/// @notice Sets the pair to serve as price feed for a given route.
function designatePair(address aTokenA, address aTokenB, ReservoirPair aPair) external onlyOwner {
(aTokenA, aTokenB) = aTokenA.sortTokens(aTokenB);
(aTokenA, aTokenB) = Utils.sortTokens(aTokenA, aTokenB);
if (aTokenA != address(aPair.token0()) || aTokenB != address(aPair.token1())) {
revert OracleErrors.IncorrectTokensDesignatePair();
}
Expand All @@ -488,7 +486,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
}

function undesignatePair(address aToken0, address aToken1) external onlyOwner {
(aToken0, aToken1) = aToken0.sortTokens(aToken1);
(aToken0, aToken1) = Utils.sortTokens(aToken0, aToken1);

delete pairs[aToken0][aToken1];
emit DesignatePair(aToken0, aToken1, ReservoirPair(address(0)));
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IReservoirPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

pragma solidity ^0.8.0;

import { OracleAverageQuery, OracleLatestQuery, OracleAccumulatorQuery } from "src/Structs.sol";
import { OracleAverageQuery, OracleLatestQuery } from "src/Structs.sol";

/**
* @dev Interface for querying historical data from a Pool that can be used as a Price Oracle.
Expand Down

0 comments on commit b82d2e7

Please sign in to comment.