@@ -123,7 +123,7 @@ contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuar
123
123
/// @param aToken1 Address of the higher token.
124
124
/// @return rPrice The cached price of aToken0/aToken1 for simple routes. Returns 0 for prices of composite routes.
125
125
/// @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.
127
127
function priceCache (address aToken0 , address aToken1 )
128
128
external
129
129
view
@@ -242,7 +242,7 @@ contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuar
242
242
/// @return rRoute The route to determine the price between aToken0 and aToken1. Returns an empty array if there is no route.
243
243
/// @return rDecimalDiff The result of token1.decimals() - token0.decimals() if it's a simple route. 0 otherwise.
244
244
/// @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.
246
246
function _getRouteDecimalDifferencePrice (address aToken0 , address aToken1 )
247
247
private
248
248
view
@@ -484,20 +484,27 @@ contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuar
484
484
/// @param aToken0 Address of the lower token.
485
485
/// @param aToken1 Address of the higher token.
486
486
/// @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.
488
488
function setRoute (address aToken0 , address aToken1 , address [] memory aRoute , uint64 [] memory aRewardThresholds )
489
489
public
490
490
onlyOwner
491
491
{
492
- uint256 lRouteLength = aRoute.length ;
493
-
494
492
_validateTokens (aToken0, aToken1);
493
+
494
+ uint256 lRouteLength = aRoute.length ;
495
495
require (lRouteLength > 1 && lRouteLength <= Constants.MAX_ROUTE_LENGTH, OracleErrors.InvalidRouteLength ());
496
496
require (aRoute[0 ] == aToken0 && aRoute[lRouteLength - 1 ] == aToken1, OracleErrors.InvalidRoute ());
497
497
require (aRewardThresholds.length == lRouteLength - 1 , OracleErrors.InvalidRewardThresholdsLength ());
498
498
499
499
bytes32 lSlot = Utils.calculateSlot (aToken0, aToken1);
500
500
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
+
501
508
// simple route
502
509
if (lRouteLength == 2 ) {
503
510
uint256 lToken0Decimals = IERC20 (aToken0).decimals ();
@@ -548,7 +555,7 @@ contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuar
548
555
/// @notice Clears the defined route and the corresponding storage slots.
549
556
/// @param aToken0 Address of the lower token.
550
557
/// @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 {
552
559
_validateTokens (aToken0, aToken1);
553
560
554
561
(address [] memory lRoute ,,,) = _getRouteDecimalDifferencePrice (aToken0, aToken1);
0 commit comments