diff --git a/src/ReservoirPriceOracle.sol b/src/ReservoirPriceOracle.sol index 368adfa..0201a19 100644 --- a/src/ReservoirPriceOracle.sol +++ b/src/ReservoirPriceOracle.sol @@ -5,7 +5,7 @@ import { IERC20 } from "forge-std/interfaces/IERC20.sol"; import { IERC4626 } from "forge-std/interfaces/IERC4626.sol"; import { OracleErrors } from "src/libraries/OracleErrors.sol"; -import { IReservoirPriceOracle, OracleAverageQuery, OracleLatestQuery } from "src/interfaces/IReservoirPriceOracle.sol"; +import { OracleAverageQuery } from "src/Structs.sol"; import { IPriceOracle } from "src/interfaces/IPriceOracle.sol"; import { QueryProcessor, ReservoirPair, PriceType } from "src/libraries/QueryProcessor.sol"; import { Utils } from "src/libraries/Utils.sol"; @@ -16,7 +16,7 @@ import { LibSort } from "lib/solady/src/utils/LibSort.sol"; import { Constants } from "src/libraries/Constants.sol"; import { RoutesLib } from "src/libraries/RoutesLib.sol"; -contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.sender), ReentrancyGuard { +contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuard { using FixedPointMathLib for uint256; using LibSort for address[]; using RoutesLib for bytes32; @@ -158,32 +158,6 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. } } - // IReservoirPriceOracle - - // REVIEW: This let's anyone read the Reservoir oracle without paying right? - /// @inheritdoc IReservoirPriceOracle - function getTimeWeightedAverage(OracleAverageQuery[] memory aQueries) - external - view - returns (uint256[] memory rResults) - { - rResults = new uint256[](aQueries.length); - for (uint256 i = 0; i < aQueries.length; ++i) { - rResults[i] = _getTimeWeightedAverageSingle(aQueries[i]); - } - } - - // REVIEW: What value is there in this? - /// @inheritdoc IReservoirPriceOracle - function getLatest(OracleLatestQuery calldata aQuery) external view returns (uint256) { - ReservoirPair lPair = pairs[aQuery.base][aQuery.quote]; - _validatePair(lPair); - - (,,, uint256 lIndex) = lPair.getReserves(); - uint256 lResult = lPair.getInstantValue(aQuery.priceType, lIndex); - return lResult; - } - /////////////////////////////////////////////////////////////////////////////////////////////// // PRIVATE FUNCTIONS // /////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/interfaces/IReservoirPriceOracle.sol b/src/interfaces/IReservoirPriceOracle.sol deleted file mode 100644 index 22d3b8a..0000000 --- a/src/interfaces/IReservoirPriceOracle.sol +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -pragma solidity ^0.8.0; - -import { OracleAverageQuery, OracleLatestQuery } from "src/Structs.sol"; - -/** - * @dev Interface for querying historical data from a Pool that can be used as a Price Oracle. - * - * This lets third parties retrieve average prices of tokens held by a Pool over a given period of time, as well as the - * price of the Pool share token (BPT) and invariant. Since the invariant is a sensible measure of Pool liquidity, it - * can be used to compare two different price sources, and choose the most liquid one. - * - * Once the oracle is fully initialized, all queries are guaranteed to succeed as long as they require no data that - * is not older than the largest safe query window. - */ -interface IReservoirPriceOracle { - /** - * @dev Returns the time average weighted price corresponding to each of `queries`. Prices are represented as 18 - * decimal fixed point values. - */ - function getTimeWeightedAverage(OracleAverageQuery[] memory queries) - external - view - returns (uint256[] memory results); - - /** - * @dev Returns latest sample of `priceType`. Prices are represented as 18 decimal fixed point values. - */ - function getLatest(OracleLatestQuery calldata priceType) external view returns (uint256); -} diff --git a/test/__fixtures/BaseTest.t.sol b/test/__fixtures/BaseTest.t.sol index 68adf70..39aec87 100644 --- a/test/__fixtures/BaseTest.t.sol +++ b/test/__fixtures/BaseTest.t.sol @@ -11,7 +11,7 @@ import { Constants } from "amm-core/Constants.sol"; import { FactoryStoreLib } from "amm-core/libraries/FactoryStore.sol"; import { MintableERC20 } from "lib/amm-core/test/__fixtures/MintableERC20.sol"; -import { ReservoirPriceOracle, IReservoirPriceOracle, PriceType, IPriceOracle } from "src/ReservoirPriceOracle.sol"; +import { ReservoirPriceOracle, PriceType, IPriceOracle } from "src/ReservoirPriceOracle.sol"; contract BaseTest is Test { using FactoryStoreLib for GenericFactory; diff --git a/test/unit/ReservoirPriceOracle.t.sol b/test/unit/ReservoirPriceOracle.t.sol index dcc0a44..f315c50 100644 --- a/test/unit/ReservoirPriceOracle.t.sol +++ b/test/unit/ReservoirPriceOracle.t.sol @@ -8,7 +8,6 @@ import { FixedPointMathLib, PriceType, OracleErrors, - OracleLatestQuery, OracleAverageQuery, ReservoirPriceOracle, IERC20, @@ -753,40 +752,6 @@ contract ReservoirPriceOracleTest is BaseTest { assertEq(lData, 0); } - function testGetTimeWeightedAverage() external { - // arrange - skip(60); - _pair.sync(); - skip(60); - _pair.sync(); - _oracle.designatePair(address(_tokenA), address(_tokenB), _pair); - OracleAverageQuery[] memory lQueries = new OracleAverageQuery[](1); - lQueries[0] = OracleAverageQuery(PriceType.RAW_PRICE, address(_tokenA), address(_tokenB), 10, 0); - - // act - uint256[] memory lResults = _oracle.getTimeWeightedAverage(lQueries); - - // assert - assertEq(lResults[0], 98_918_868_099_219_913_512); - } - - function testGetLatest(uint32 aFastForward) public { - // assume - latest price should always be the same no matter how much time has elapsed - uint32 lFastForward = uint32(bound(aFastForward, 1, 2 ** 31 - 2)); - - // arrange - skip(lFastForward); - _pair.sync(); - _oracle.designatePair(address(_tokenA), address(_tokenB), _pair); - - // act - uint256 lLatestPrice = - _oracle.getLatest(OracleLatestQuery(PriceType.RAW_PRICE, address(_tokenA), address(_tokenB))); - - // assert - assertEq(lLatestPrice, 98_918_868_099_219_913_512); - } - function testDesignatePair() external { // act vm.expectEmit(false, false, false, true); @@ -823,30 +788,6 @@ contract ReservoirPriceOracleTest is BaseTest { // ERROR CONDITIONS // /////////////////////////////////////////////////////////////////////////////////////////////// - function testGetLatest_Inverted() external { - // arrange - testGetLatest(5); - - // act & assert - vm.expectRevert(OracleErrors.NoDesignatedPair.selector); - _oracle.getLatest(OracleLatestQuery(PriceType.RAW_PRICE, address(_tokenB), address(_tokenA))); - } - - function testGetTimeWeightedAverage_Inverted() external { - // arrange - skip(60); - _pair.sync(); - skip(60); - _pair.sync(); - _oracle.designatePair(address(_tokenB), address(_tokenA), _pair); - OracleAverageQuery[] memory lQueries = new OracleAverageQuery[](1); - lQueries[0] = OracleAverageQuery(PriceType.RAW_PRICE, address(_tokenB), address(_tokenA), 10, 0); - - // act & assert - vm.expectRevert(OracleErrors.NoDesignatedPair.selector); - _oracle.getTimeWeightedAverage(lQueries); - } - function testSetFallbackOracle_NotOwner() external { vm.prank(address(123)); vm.expectRevert("UNAUTHORIZED");