diff --git a/src/ReservoirPriceOracle.sol b/src/ReservoirPriceOracle.sol index 03fade8..70dc080 100644 --- a/src/ReservoirPriceOracle.sol +++ b/src/ReservoirPriceOracle.sol @@ -26,10 +26,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. using LibSort for address[]; using FlagsLib for *; using QueryProcessor for ReservoirPair; - // REVIEW: It doesn't make sense for calculateSlot to be attached to address - // as it is a function that maps `(addr, addr) -> u256`, not anything that - // operates on a single `address`. - using Utils for *; + using Utils for address; /////////////////////////////////////////////////////////////////////////////////////////////// // EVENTS // @@ -279,7 +276,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. returns (address[] memory rRoute, int256 rDecimalDiff, uint256 rPrice) { address[] memory lResults = new address[](Constants.MAX_ROUTE_LENGTH); - bytes32 lSlot = aToken0.calculateSlot(aToken1); + bytes32 lSlot = Utils.calculateSlot(aToken0, aToken1); bytes32 lFirstWord; uint256 lRouteLength; @@ -333,7 +330,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. function _checkAndPopulateIntermediateRoute(address aToken0, address aToken1) internal { (address lLowerToken, address lHigherToken) = aToken0.sortTokens(aToken1); - bytes32 lSlot = lLowerToken.calculateSlot(lHigherToken); + bytes32 lSlot = Utils.calculateSlot(lLowerToken, lHigherToken); bytes32 lData; assembly { lData := sload(lSlot) @@ -352,7 +349,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. view returns (uint256 rPrice, int256 rDecimalDiff) { - bytes32 lSlot = aToken0.calculateSlot(aToken1); + bytes32 lSlot = Utils.calculateSlot(aToken0, aToken1); bytes32 lData; assembly { @@ -367,7 +364,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. function _writePriceCache(address aToken0, address aToken1, uint256 aNewPrice) internal { if (aNewPrice == 0 || aNewPrice > Constants.MAX_SUPPORTED_PRICE) revert OracleErrors.PriceOutOfRange(aNewPrice); - bytes32 lSlot = aToken0.calculateSlot(aToken1); + bytes32 lSlot = Utils.calculateSlot(aToken0, aToken1); bytes32 lData; assembly { lData := sload(lSlot) @@ -534,7 +531,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. if (lRouteLength > Constants.MAX_ROUTE_LENGTH || lRouteLength < 2) revert OracleErrors.InvalidRouteLength(); if (aRoute[0] != aToken0 || aRoute[lRouteLength - 1] != aToken1) revert OracleErrors.InvalidRoute(); - bytes32 lSlot = aToken0.calculateSlot(aToken1); + bytes32 lSlot = Utils.calculateSlot(aToken0, aToken1); // simple route if (lRouteLength == 2) { @@ -585,7 +582,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. (address[] memory lRoute,,) = _getRouteDecimalDifferencePrice(aToken0, aToken1); - bytes32 lSlot = aToken0.calculateSlot(aToken1); + bytes32 lSlot = Utils.calculateSlot(aToken0, aToken1); // clear the storage slot that the route has written to previously assembly { diff --git a/src/libraries/Utils.sol b/src/libraries/Utils.sol index 880db57..2e8dae8 100644 --- a/src/libraries/Utils.sol +++ b/src/libraries/Utils.sol @@ -2,11 +2,6 @@ pragma solidity ^0.8.0; library Utils { - /// @dev Square of 1e18 (WAD) - uint256 internal constant WAD_SQUARED = 1e36; - - error OutOfRange(uint256 value); - // returns the lower address followed by the higher address function sortTokens(address tokenA, address tokenB) internal pure returns (address, address) { return tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); @@ -16,10 +11,4 @@ library Utils { function calculateSlot(address aToken0, address aToken1) internal pure returns (bytes32) { return keccak256(abi.encode(aToken0, aToken1)); } - - function invertWad(uint256 x) internal pure returns (uint256) { - if (x == 0 || x > WAD_SQUARED) revert OutOfRange(x); - - return WAD_SQUARED / x; - } }