Skip to content

Commit

Permalink
fix: use revert instead of assert for designatePair
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jun 14, 2024
1 parent c95b6c1 commit cae20e7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
15 changes: 7 additions & 8 deletions src/ReservoirPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,14 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
}

/// @notice Sets the pair to serve as price feed for a given route.
// TODO: Should be TokenA & TokenB because this function sorts them?
function designatePair(address aToken0, address aToken1, ReservoirPair aPair) external onlyOwner {
(aToken0, aToken1) = aToken0.sortTokens(aToken1);
// TODO: Should be require as it's possible to fail right? Generally
// assert is used for symbolic provers to find invariants they can break.
assert(aToken0 == address(aPair.token0()) && aToken1 == address(aPair.token1()));
function designatePair(address aTokenA, address aTokenB, ReservoirPair aPair) external onlyOwner {
(aTokenA, aTokenB) = aTokenA.sortTokens(aTokenB);
if (aTokenA != address(aPair.token0()) || aTokenB != address(aPair.token1())) {
revert OracleErrors.IncorrectTokensDesignatePair();
}

pairs[aToken0][aToken1] = aPair;
emit DesignatePair(aToken0, aToken1, aPair);
pairs[aTokenA][aTokenB] = aPair;
emit DesignatePair(aTokenA, aTokenB, aPair);
}

function undesignatePair(address aToken0, address aToken1) external onlyOwner {
Expand Down
1 change: 1 addition & 0 deletions src/libraries/OracleErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
/// @dev Collection of all oracle related errors.
library OracleErrors {
// config errors
error IncorrectTokensDesignatePair();
error InvalidRoute();
error InvalidRouteLength();
error InvalidTwapPeriod();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ReservoirPriceOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ contract ReservoirPriceOracleTest is BaseTest {

function testDesignatePair_IncorrectPair() external {
// act & assert
vm.expectRevert();
vm.expectRevert(OracleErrors.IncorrectTokensDesignatePair.selector);
_oracle.designatePair(address(_tokenA), address(_tokenC), _pair);
}

Expand Down

0 comments on commit cae20e7

Please sign in to comment.