From c95b6c112c1e4c1769cd7abe295f82f0229e4ff5 Mon Sep 17 00:00:00 2001 From: "A.L." Date: Fri, 14 Jun 2024 23:06:48 +0200 Subject: [PATCH] fix: make `priceType` immutable --- src/ReservoirPriceOracle.sol | 16 +++++----------- test/unit/ReservoirPriceOracle.t.sol | 6 ------ 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/ReservoirPriceOracle.sol b/src/ReservoirPriceOracle.sol index df29180..824f411 100644 --- a/src/ReservoirPriceOracle.sol +++ b/src/ReservoirPriceOracle.sol @@ -42,6 +42,9 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. event SetPriceType(PriceType priceType); event TwapPeriod(uint256 newPeriod); + /// @notice The type of price queried and stored, possibilities as defined by `PriceType`. + PriceType public immutable priceType; + /////////////////////////////////////////////////////////////////////////////////////////////// // STORAGE // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -50,7 +53,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. /// @dev If `address(0)` then there is no fallback. address public fallbackOracle; - // The following 4 storage variables take up 1 storage slot. + // The following 3 storage variables take up 1 storage slot. /// @notice percentage change greater than which, a price update may result in a reward payout of native tokens, /// subject to availability of rewards. @@ -63,10 +66,6 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. /// @notice TWAP period (in seconds) for querying the oracle uint64 public twapPeriod; - // TODO: What's the use case for changing between price types? Should this be immutable or removed and one type be hardcoded? - /// @notice The type of price queried and stored, possibilities as defined by `PriceType`. - PriceType public priceType; - /// @notice Designated pairs to serve as price feed for a certain token0 and token1 mapping(address token0 => mapping(address token1 => ReservoirPair pair)) public pairs; @@ -82,7 +81,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. updatePriceDeviationThreshold(aThreshold); updateTwapPeriod(aTwapPeriod); updateRewardGasAmount(aMultiplier); - setPriceType(aType); + priceType = aType; } /// @dev contract will hold native tokens to be distributed as gas bounty for updating the prices @@ -526,11 +525,6 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg. emit DesignatePair(aToken0, aToken1, ReservoirPair(address(0))); } - function setPriceType(PriceType aType) public onlyOwner { - priceType = aType; - emit SetPriceType(aType); - } - // TODO: What's the use case for these vaults? Is it to price wrapped tokens // without needing a market? function setResolvedVault(address aVault, bool aSet) external onlyOwner { diff --git a/test/unit/ReservoirPriceOracle.t.sol b/test/unit/ReservoirPriceOracle.t.sol index 484bcb5..f6c9c50 100644 --- a/test/unit/ReservoirPriceOracle.t.sol +++ b/test/unit/ReservoirPriceOracle.t.sol @@ -983,12 +983,6 @@ contract ReservoirPriceOracleTest is BaseTest { _oracle.updatePrice(address(_tokenB), address(_tokenC), address(0)); } - function setPriceType() external { - vm.prank(address(123)); - vm.expectRevert("UNAUTHORIZED"); - _oracle.setPriceType(PriceType.RAW_PRICE); - } - function testSetRoute_SameToken() external { // arrange address lToken0 = address(0x1);