Skip to content

Commit

Permalink
add isCapped view
Browse files Browse the repository at this point in the history
  • Loading branch information
rustboyar committed Mar 1, 2024
1 parent 5a08f7c commit 9392d63
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/contracts/PriceCapAdapterBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 8 additions & 0 deletions src/contracts/PriceCapAdapterStable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/interfaces/IPriceCapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/interfaces/IPriceCapAdapterStable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9392d63

Please sign in to comment.