Skip to content

Commit

Permalink
make functions private instead of internal where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverNChalk committed Jul 8, 2024
1 parent c6f4277 commit a605766
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/ReservoirPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
/// 1e18 == 100%
uint64 public priceDeviationThreshold;

/// @notice This number is multiplied by the base fee to determine the reward for keepers
/// @notice This number is multiplied by the base fee to determine the reward for keepers.
uint64 public rewardGasAmount;

/// @notice TWAP period (in seconds) for querying the oracle
/// @notice TWAP period (in seconds) for querying the oracle.
uint64 public twapPeriod;

/// @notice Designated pairs to serve as price feed for a certain token0 and token1
/// @notice Designated pairs to serve as price feed for a certain token0 and token1.
mapping(address token0 => mapping(address token1 => ReservoirPair pair)) public pairs;

///////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -101,6 +101,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.

// price update related functions

// REVIEW: While this is nice in terms of self documentation, I think any MEV bot can just do `address(reservoirOracle).balance` right?
function gasBountyAvailable() external view returns (uint256) {
return address(this).balance;
}
Expand Down Expand Up @@ -199,15 +200,15 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
if (aToken1 <= aToken0) revert OracleErrors.InvalidTokensProvided();
}

function _getTimeWeightedAverageSingle(OracleAverageQuery memory aQuery) internal view returns (uint256 rResult) {
function _getTimeWeightedAverageSingle(OracleAverageQuery memory aQuery) private view returns (uint256 rResult) {
ReservoirPair lPair = pairs[aQuery.base][aQuery.quote];
_validatePair(lPair);

(,,, uint16 lIndex) = lPair.getReserves();
rResult = lPair.getTimeWeightedAverage(aQuery.priceType, aQuery.secs, aQuery.ago, lIndex);
}

function _calcPercentageDiff(uint256 aOriginal, uint256 aNew) internal pure returns (uint256) {
function _calcPercentageDiff(uint256 aOriginal, uint256 aNew) private pure returns (uint256) {
unchecked {
if (aOriginal == 0) return 0;

Expand All @@ -221,7 +222,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
}
}

function _rewardUpdater(address aRecipient) internal {
function _rewardUpdater(address aRecipient) private {
if (aRecipient == address(0)) return;

// N.B. Revisit this whenever deployment on a new chain is needed
Expand All @@ -247,7 +248,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
/// @return rDecimalDiff The result of token1.decimals() - token0.decimals() if it's a simple route. 0 otherwise
/// @return rPrice The price of aToken0/aToken1 if it's a simple route (i.e. rRoute.length == 2). 0 otherwise
function _getRouteDecimalDifferencePrice(address aToken0, address aToken1)
internal
private
view
returns (address[] memory rRoute, int256 rDecimalDiff, uint256 rPrice)
{
Expand Down Expand Up @@ -315,7 +316,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.

// performs an SLOAD to load 1 word which contains the simple price and decimal difference
function _priceCache(address aToken0, address aToken1)
internal
private
view
returns (uint256 rPrice, int256 rDecimalDiff)
{
Expand All @@ -331,7 +332,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
}
}

function _writePriceCache(address aToken0, address aToken1, uint256 aNewPrice) internal {
function _writePriceCache(address aToken0, address aToken1, uint256 aNewPrice) private {
if (aNewPrice == 0 || aNewPrice > Constants.MAX_SUPPORTED_PRICE) revert OracleErrors.PriceOutOfRange(aNewPrice);

bytes32 lSlot = Utils.calculateSlot(aToken0, aToken1);
Expand All @@ -350,7 +351,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
}

function _getQuotes(uint256 aAmount, address aBase, address aQuote, bool aIsGetQuotes)
internal
private
view
returns (uint256 rBidOut, uint256 rAskOut)
{
Expand Down Expand Up @@ -387,20 +388,20 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
assert(lRoute[0] == aBase);

for (uint256 i = 0; i < lRoute.length - 1; ++i) {
(address lLowerToken, address lHigherToken) = Utils.sortTokens(lRoute[i], lRoute[i + 1]);
(address lToken0, address lToken1) = Utils.sortTokens(lRoute[i], lRoute[i + 1]);
// it is assumed that intermediate routes defined here are simple routes and not composite routes
(lPrice, lDecimalDiff) = _priceCache(lLowerToken, lHigherToken);
(lPrice, lDecimalDiff) = _priceCache(lToken0, lToken1);

if (lPrice == 0) revert OracleErrors.PriceZero();
lIntermediateAmount = _calcAmtOut(lIntermediateAmount, lPrice, lDecimalDiff, lRoute[i] != lLowerToken);
lIntermediateAmount = _calcAmtOut(lIntermediateAmount, lPrice, lDecimalDiff, lRoute[i] != lToken0);
}
rBidOut = rAskOut = lIntermediateAmount;
}
}

/// @dev aPrice assumed to be > 0, as checked by _getQuote
function _calcAmtOut(uint256 aAmountIn, uint256 aPrice, int256 aDecimalDiff, bool aInverse)
internal
private
pure
returns (uint256 rOut)
{
Expand Down Expand Up @@ -428,7 +429,7 @@ contract ReservoirPriceOracle is IPriceOracle, IReservoirPriceOracle, Owned(msg.
}

function _useFallbackOracle(uint256 aAmount, address aBase, address aQuote, bool aIsGetQuotes)
internal
private
view
returns (uint256 rBidOut, uint256 rAskOut)
{
Expand Down

0 comments on commit a605766

Please sign in to comment.