Skip to content

Commit

Permalink
fix: rm IReservoirPriceOracle and associated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jul 8, 2024
1 parent 84b1cc5 commit cd6f68b
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 131 deletions.
30 changes: 2 additions & 28 deletions src/ReservoirPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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 //
///////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
43 changes: 0 additions & 43 deletions src/interfaces/IReservoirPriceOracle.sol

This file was deleted.

2 changes: 1 addition & 1 deletion test/__fixtures/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
59 changes: 0 additions & 59 deletions test/unit/ReservoirPriceOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
FixedPointMathLib,
PriceType,
OracleErrors,
OracleLatestQuery,
OracleAverageQuery,
ReservoirPriceOracle,
IERC20,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit cd6f68b

Please sign in to comment.