diff --git a/src/contracts/PriceCapAdapterBase.sol b/src/contracts/PriceCapAdapterBase.sol index 641215e..d567d80 100644 --- a/src/contracts/PriceCapAdapterBase.sol +++ b/src/contracts/PriceCapAdapterBase.sol @@ -208,4 +208,17 @@ abstract contract PriceCapAdapterBase is IPriceCapAdapter { /// @inheritdoc IPriceCapAdapter function getRatio() public view virtual returns (int256); + + /// @inheritdoc IPriceCapAdapter + function isCapped() public view virtual returns (bool) { + // get the current lst to underlying ratio + int256 currentRatio = getRatio(); + + // calculate the ratio based on snapshot ratio and max growth rate + int256 maxRatio = int256( + _snapshotRatio + _maxRatioGrowthPerSecond * (block.timestamp - _snapshotTimestamp) + ); + + return currentRatio > maxRatio; + } } diff --git a/src/contracts/PriceCapAdapterStable.sol b/src/contracts/PriceCapAdapterStable.sol index c18c9de..4cb9e22 100644 --- a/src/contracts/PriceCapAdapterStable.sol +++ b/src/contracts/PriceCapAdapterStable.sol @@ -68,6 +68,14 @@ contract PriceCapAdapterStable is IPriceCapAdapterStable { _setPriceCap(priceCap); } + /// @inheritdoc IPriceCapAdapterStable + function isCapped() public view virtual returns (bool) { + int256 basePrice = ASSET_TO_USD_AGGREGATOR.latestAnswer(); + int256 priceCap = _priceCap; + + return basePrice > priceCap; + } + /** * @notice Updates price cap * @param priceCap the new price cap diff --git a/src/interfaces/IPriceCapAdapter.sol b/src/interfaces/IPriceCapAdapter.sol index 015828d..0a3807f 100644 --- a/src/interfaces/IPriceCapAdapter.sol +++ b/src/interfaces/IPriceCapAdapter.sol @@ -106,6 +106,11 @@ interface IPriceCapAdapter is ICLSynchronicityPriceAdapter { */ function getMaxYearlyGrowthRatePercent() external view returns (uint256); + /** + * @notice Returns if the price is currently capped + */ + function isCapped() external view returns (bool); + error ACLManagerIsZeroAddress(); error SnapshotRatioIsZero(); error SnapshotMayOverflowSoon(uint104 snapshotRatio, uint16 maxYearlyRatioGrowthPercent); diff --git a/src/interfaces/IPriceCapAdapterStable.sol b/src/interfaces/IPriceCapAdapterStable.sol index 9cc2dae..5fe016f 100644 --- a/src/interfaces/IPriceCapAdapterStable.sol +++ b/src/interfaces/IPriceCapAdapterStable.sol @@ -29,6 +29,11 @@ interface IPriceCapAdapterStable is ICLSynchronicityPriceAdapter { */ function setPriceCap(int256 priceCap) external; + /** + * @notice Returns if the price is currently capped + */ + function isCapped() external view returns (bool); + error ACLManagerIsZeroAddress(); error CallerIsNotRiskOrPoolAdmin(); error CapLowerThanActualPrice();