Skip to content

Commit 272b674

Browse files
committed
fix: addresses #6
1 parent 97d95ff commit 272b674

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/ReservoirPriceOracle.sol

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuar
123123
/// @param aToken1 Address of the higher token.
124124
/// @return rPrice The cached price of aToken0/aToken1 for simple routes. Returns 0 for prices of composite routes.
125125
/// @return rDecimalDiff The difference in decimals as defined by aToken1.decimals() - aToken0.decimals(). Only valid for simple routes.
126-
/// @return rRewardThreshold The number of basis points of difference in price at and beyond which a reward is applicable for a price update.
126+
/// @return rRewardThreshold The difference in price in WAD at and beyond which a reward is applicable for a price update.
127127
function priceCache(address aToken0, address aToken1)
128128
external
129129
view
@@ -242,7 +242,7 @@ contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuar
242242
/// @return rRoute The route to determine the price between aToken0 and aToken1. Returns an empty array if there is no route.
243243
/// @return rDecimalDiff The result of token1.decimals() - token0.decimals() if it's a simple route. 0 otherwise.
244244
/// @return rPrice The price of aToken0/aToken1 if it's a simple route (i.e. rRoute.length == 2). 0 otherwise.
245-
/// @return rRewardThreshold The number of basis points of difference in price at and beyond which a reward is applicable for a price update.
245+
/// @return rRewardThreshold The difference in price in WAD at and beyond which a reward is applicable for a price update.
246246
function _getRouteDecimalDifferencePrice(address aToken0, address aToken1)
247247
private
248248
view
@@ -484,20 +484,27 @@ contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuar
484484
/// @param aToken0 Address of the lower token.
485485
/// @param aToken1 Address of the higher token.
486486
/// @param aRoute Path with which the price between aToken0 and aToken1 should be derived.
487-
/// @param aRewardThresholds Array of basis points at and beyond which a reward is applicable for a price update.
487+
/// @param aRewardThresholds Array of reward thresholds in WAD and beyond which a reward is applicable for a price update.
488488
function setRoute(address aToken0, address aToken1, address[] memory aRoute, uint64[] memory aRewardThresholds)
489489
public
490490
onlyOwner
491491
{
492-
uint256 lRouteLength = aRoute.length;
493-
494492
_validateTokens(aToken0, aToken1);
493+
494+
uint256 lRouteLength = aRoute.length;
495495
require(lRouteLength > 1 && lRouteLength <= Constants.MAX_ROUTE_LENGTH, OracleErrors.InvalidRouteLength());
496496
require(aRoute[0] == aToken0 && aRoute[lRouteLength - 1] == aToken1, OracleErrors.InvalidRoute());
497497
require(aRewardThresholds.length == lRouteLength - 1, OracleErrors.InvalidRewardThresholdsLength());
498498

499499
bytes32 lSlot = Utils.calculateSlot(aToken0, aToken1);
500500

501+
bytes32 lSlotData;
502+
assembly ("memory-safe") {
503+
lSlotData := sload(lSlot)
504+
}
505+
// clear existing route first if there is one
506+
if (lSlotData != 0) clearRoute(aToken0, aToken1);
507+
501508
// simple route
502509
if (lRouteLength == 2) {
503510
uint256 lToken0Decimals = IERC20(aToken0).decimals();
@@ -548,7 +555,7 @@ contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuar
548555
/// @notice Clears the defined route and the corresponding storage slots.
549556
/// @param aToken0 Address of the lower token.
550557
/// @param aToken1 Address of the higher token.
551-
function clearRoute(address aToken0, address aToken1) external onlyOwner {
558+
function clearRoute(address aToken0, address aToken1) public onlyOwner {
552559
_validateTokens(aToken0, aToken1);
553560

554561
(address[] memory lRoute,,,) = _getRouteDecimalDifferencePrice(aToken0, aToken1);

0 commit comments

Comments
 (0)