Skip to content

Commit

Permalink
fix: PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Nov 18, 2024
1 parent 1b8d048 commit f220e79
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/ReservoirPair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20 {
updateSwapFee();
updatePlatformFee();
updateOracleCaller();
setClampParams(factory.read(MAX_CHANGE_RATE_NAME).toUint128(), factory.read(MAX_CHANGE_PER_TRADE_NAME).toUint128());
setClampParams(
factory.read(MAX_CHANGE_RATE_NAME).toUint128(), factory.read(MAX_CHANGE_PER_TRADE_NAME).toUint128()
);
}
}

Expand Down Expand Up @@ -518,7 +520,7 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20 {
event OracleCallerUpdated(address oldCaller, address newCaller);
event ClampParamsUpdated(uint128 newMaxChangeRatePerSecond, uint128 newMaxChangePerTrade);

// 100 basis points per second which is 60% per minute
// 1% per second which is 60% per minute
uint256 internal constant MAX_CHANGE_PER_SEC = 0.01e18;
// 10%
uint256 internal constant MAX_CHANGE_PER_TRADE = 0.1e18;
Expand Down Expand Up @@ -567,13 +569,11 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20 {
) internal virtual returns (uint256 rClampedPrice, int256 rClampedLogPrice) {
// call to `percentDelta` will revert if the difference between aCurrRawPrice and aPrevClampedPrice is
// greater than uint196 (1e59). It is extremely unlikely that one trade can change the price by 1e59
bool lRateOfChangeWithinThreshold =
aCurrRawPrice.percentDelta(aPrevClampedPrice) <= maxChangeRate * aTimeElapsed;
bool lPerTradeWithinThreshold = aCurrRawPrice.percentDelta(aPrevClampedPrice) <= maxChangePerTrade;
if (
(
aCurrRawPrice.percentDelta(aPrevClampedPrice) <= maxChangeRate * aTimeElapsed
&& aCurrRawPrice.percentDelta(aPrevClampedPrice) <= maxChangePerTrade
)
// this is the first ever calculation of clamped price, and so should be set to the raw price
|| aPreviousTimestamp == 0
(lRateOfChangeWithinThreshold && lPerTradeWithinThreshold) || aPreviousTimestamp == 0 // first ever calculation of the clamped price, and so should be set to the raw price
) {
(rClampedPrice, rClampedLogPrice) = (aCurrRawPrice, aCurrLogRawPrice);
} else {
Expand Down

0 comments on commit f220e79

Please sign in to comment.