Skip to content

Commit

Permalink
fix: introduce limits for threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Aug 8, 2024
1 parent ed8d0bc commit fddc674
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ReservoirPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuar

event DesignatePair(address token0, address token1, ReservoirPair pair);
event FallbackOracleSet(address fallbackOracle);
event PriceUpdateRewardThreshold(address token0, address token1, uint16 threshold);
event PriceUpdateRewardThreshold(address token0, address token1, uint256 threshold);
event RewardGasAmount(uint256 newAmount);
event Route(address token0, address token1, address[] route);
event TwapPeriod(uint256 newPeriod);
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/RoutesLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ library RoutesLib {
// Assumes that aDecimalDifference is between -18 and 18
// Assumes that aPrice is between 1 and 1e36
// Assumes that aRewardThreshold is <= Constants.BP_SCALE
function packSimplePrice(int256 aDecimalDifference, uint256 aPrice, uint16 aRewardThreshold)
function packSimplePrice(int256 aDecimalDifference, uint256 aPrice, uint256 aRewardThreshold)
internal
pure
returns (bytes32 rPacked)
Expand Down
20 changes: 20 additions & 0 deletions test/unit/ReservoirPriceOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ contract ReservoirPriceOracleTest is BaseTest {

address[] memory lRoute = new address[](2);
uint16[] memory lRewardThreshold = new uint16[](1);
lRewardThreshold[0] = Constants.BP_SCALE;
(lRoute[0], lRoute[1]) =
lTokenA < lTokenB ? (address(lTokenA), address(lTokenB)) : (address(lTokenB), address(lTokenA));
_oracle.setRoute(lRoute[0], lRoute[1], lRoute, lRewardThreshold);
Expand Down Expand Up @@ -329,6 +330,7 @@ contract ReservoirPriceOracleTest is BaseTest {
lRoute[1] = address(lTokenB);

uint16[] memory lRewardThreshold = new uint16[](2);
lRewardThreshold[0] = lRewardThreshold[1] = Constants.BP_SCALE;
_oracle.setRoute(lRoute[0], lRoute[2], lRoute, lRewardThreshold);
_writePriceCache(
address(lTokenA) < address(lTokenB) ? address(lTokenA) : address(lTokenB),
Expand All @@ -341,6 +343,7 @@ contract ReservoirPriceOracleTest is BaseTest {
lPrice2
);
}

// act
uint256 lAmtCOut = _oracle.getQuote(lAmtIn * 10 ** lTokenADecimal, address(lTokenA), address(lTokenC));

Expand Down Expand Up @@ -1024,6 +1027,23 @@ contract ReservoirPriceOracleTest is BaseTest {
_oracle.setRoute(lToken0, lToken1, lInvalidRoute2, lRewardThreshold);
}

function testSetRoute_InvalidRewardThreshold() external {
// arrange
address[] memory lRoute = new address[](2);
uint16[] memory lInvalidRewardThreshold = new uint16[](1);
lInvalidRewardThreshold[0] = Constants.BP_SCALE + 1;
lRoute[0] = address(_tokenC);
lRoute[1] = address(_tokenD);

// act & assert
vm.expectRevert(OracleErrors.InvalidRewardThreshold.selector);
_oracle.setRoute(lRoute[0], lRoute[1], lRoute, lInvalidRewardThreshold);

lInvalidRewardThreshold[0] = 0;
vm.expectRevert(OracleErrors.InvalidRewardThreshold.selector);
_oracle.setRoute(lRoute[0], lRoute[1], lRoute, lInvalidRewardThreshold);
}

function testUpdateRewardGasAmount_NotOwner() external {
// act & assert
vm.prank(address(123));
Expand Down

0 comments on commit fddc674

Please sign in to comment.