Skip to content

Commit

Permalink
change params to struct, cbETH update
Browse files Browse the repository at this point in the history
  • Loading branch information
kyzia551 committed Jan 29, 2024
1 parent 03133e5 commit 70cc11c
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 188 deletions.
12 changes: 3 additions & 9 deletions src/contracts/CLRatePriceCapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ contract CLRatePriceCapAdapter is PriceCapAdapterBase {
* @param ratioProviderAddress the address of the (lstASSET / ASSET) ratio feed
* @param pairName name identifier
* @param minimumSnapshotDelay minimum time (in seconds) that should have passed from the snapshot timestamp to the current block.timestamp
* @param snapshotRatio the latest exchange ratio
* @param snapshotTimestamp the timestamp of the latest exchange ratio
* @param maxYearlyRatioGrowthPercent maximum growth of the underlying asset value per year, 100_00 is equal 100%
* @param priceCapParams parameters to set price cap
*/
constructor(
IACLManager aclManager,
address assetToBaseAggregatorAddress,
address ratioProviderAddress,
string memory pairName,
uint48 minimumSnapshotDelay,
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
PriceCapUpdateParams memory priceCapParams
)
PriceCapAdapterBase(
aclManager,
Expand All @@ -40,9 +36,7 @@ contract CLRatePriceCapAdapter is PriceCapAdapterBase {
pairName,
IChainlinkAggregator(ratioProviderAddress).decimals(),
minimumSnapshotDelay,
snapshotRatio,
snapshotTimestamp,
maxYearlyRatioGrowthPercent
priceCapParams
)
{}

Expand Down
12 changes: 3 additions & 9 deletions src/contracts/CbETHPriceCapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ contract CbETHPriceCapAdapter is PriceCapAdapterBase {
* @param ratioProviderAddress the address of the (cbETH / ETH) ratio provider
* @param pairName name identifier
* @param minimumSnapshotDelay minimum time (in seconds) that should have passed from the snapshot timestamp to the current block.timestamp
* @param snapshotRatio the latest exchange ratio
* @param snapshotTimestamp the timestamp of the latest exchange ratio
* @param maxYearlyRatioGrowthPercent maximum growth of the underlying asset value per year, 100_00 is equal 100%
* @param priceCapParams parameters to set price cap
*/
constructor(
IACLManager aclManager,
address cbETHToBaseAggregatorAddress,
address ratioProviderAddress,
string memory pairName,
uint48 minimumSnapshotDelay,
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
PriceCapUpdateParams memory priceCapParams
)
PriceCapAdapterBase(
aclManager,
Expand All @@ -42,9 +38,7 @@ contract CbETHPriceCapAdapter is PriceCapAdapterBase {
pairName,
18,
minimumSnapshotDelay,
snapshotRatio,
snapshotTimestamp,
maxYearlyRatioGrowthPercent
priceCapParams
)
{}

Expand Down
12 changes: 3 additions & 9 deletions src/contracts/MaticPriceCapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@ contract MaticPriceCapAdapter is PriceCapAdapterBase {
* @param ratioProviderAddress the address of (lst Matic / MATIC) pair ratio feed
* @param pairName name identifier
* @param minimumSnapshotDelay minimum time (in seconds) that should have passed from the snapshot timestamp to the current block.timestamp
* @param snapshotRatio the latest exchange ratio
* @param snapshotTimestamp the timestamp of the latest exchange ratio
* @param maxYearlyRatioGrowthPercent maximum growth of the underlying asset value per year, 100_00 is equal 100%
* @param priceCapParams parameters to set price cap
*/
constructor(
IACLManager aclManager,
address maticToBaseAggregatorAddress,
address ratioProviderAddress,
string memory pairName,
uint48 minimumSnapshotDelay,
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
PriceCapUpdateParams memory priceCapParams
)
PriceCapAdapterBase(
aclManager,
Expand All @@ -41,9 +37,7 @@ contract MaticPriceCapAdapter is PriceCapAdapterBase {
pairName,
18,
minimumSnapshotDelay,
snapshotRatio,
snapshotTimestamp,
maxYearlyRatioGrowthPercent
priceCapParams
)
{}

Expand Down
57 changes: 27 additions & 30 deletions src/contracts/PriceCapAdapterBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ abstract contract PriceCapAdapterBase is IPriceCapAdapter {
* @param pairDescription the capped (lstAsset / underlyingAsset) pair description
* @param ratioDecimals the number of decimal places of the (lstAsset / underlyingAsset) ratio feed
* @param minimumSnapshotDelay minimum time (in seconds) that should have passed from the snapshot timestamp to the current block.timestamp
* @param snapshotRatio the latest exchange ratio
* @param snapshotTimestamp the timestamp of the latest exchange ratio
* @param maxYearlyRatioGrowthPercent maximum growth of the underlying asset value per year, 100_00 is equal 100%
* @param priceCapParams parameters to set price cap
*/
constructor(
IACLManager aclManager,
Expand All @@ -79,9 +77,7 @@ abstract contract PriceCapAdapterBase is IPriceCapAdapter {
string memory pairDescription,
uint8 ratioDecimals,
uint48 minimumSnapshotDelay,
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
PriceCapUpdateParams memory priceCapParams
) {
if (address(aclManager) == address(0)) {
revert ACLManagerIsZeroAddress();
Expand All @@ -95,7 +91,7 @@ abstract contract PriceCapAdapterBase is IPriceCapAdapter {

_description = pairDescription;

_setCapParameters(snapshotRatio, snapshotTimestamp, maxYearlyRatioGrowthPercent);
_setCapParameters(priceCapParams);
}

/// @inheritdoc ICLSynchronicityPriceAdapter
Expand Down Expand Up @@ -129,16 +125,12 @@ abstract contract PriceCapAdapterBase is IPriceCapAdapter {
}

/// @inheritdoc IPriceCapAdapter
function setCapParameters(
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
) external {
function setCapParameters(PriceCapUpdateParams memory priceCapParams) external {
if (!ACL_MANAGER.isRiskAdmin(msg.sender) && !ACL_MANAGER.isPoolAdmin(msg.sender)) {
revert CallerIsNotRiskOrPoolAdmin();
}

_setCapParameters(snapshotRatio, snapshotTimestamp, maxYearlyRatioGrowthPercent);
_setCapParameters(priceCapParams);
}

/// @inheritdoc ICLSynchronicityPriceAdapter
Expand Down Expand Up @@ -167,29 +159,31 @@ abstract contract PriceCapAdapterBase is IPriceCapAdapter {
return price;
}

function _setCapParameters(
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
) internal {
/**
* @notice Updates price cap parameters
* @param priceCapParams parameters to set price cap
*/
function _setCapParameters(PriceCapUpdateParams memory priceCapParams) internal {
// if snapshot ratio is 0 then growth will not work as expected
if (snapshotRatio == 0) {
if (priceCapParams.snapshotRatio == 0) {
revert SnapshotRatioIsZero();
}

// new snapshot timestamp should be gt then stored one, but not gt then timestamp of the current block
if (
_snapshotTimestamp >= snapshotTimestamp ||
snapshotTimestamp > block.timestamp - MINIMUM_SNAPSHOT_DELAY
_snapshotTimestamp >= priceCapParams.snapshotTimestamp ||
priceCapParams.snapshotTimestamp > block.timestamp - MINIMUM_SNAPSHOT_DELAY
) {
revert InvalidRatioTimestamp(snapshotTimestamp);
revert InvalidRatioTimestamp(priceCapParams.snapshotTimestamp);
}
_snapshotRatio = snapshotRatio;
_snapshotTimestamp = snapshotTimestamp;
_maxYearlyRatioGrowthPercent = maxYearlyRatioGrowthPercent;
_snapshotRatio = priceCapParams.snapshotRatio;
_snapshotTimestamp = priceCapParams.snapshotTimestamp;
_maxYearlyRatioGrowthPercent = priceCapParams.maxYearlyRatioGrowthPercent;

_maxRatioGrowthPerSecond = uint104(
(uint256(snapshotRatio) * maxYearlyRatioGrowthPercent) / PERCENTAGE_FACTOR / SECONDS_PER_YEAR
(uint256(priceCapParams.snapshotRatio) * priceCapParams.maxYearlyRatioGrowthPercent) /
PERCENTAGE_FACTOR /
SECONDS_PER_YEAR
);

// if the ratio on the current growth speed can overflow less then in a MINIMAL_RATIO_INCREASE_LIFETIME years, revert
Expand All @@ -198,14 +192,17 @@ abstract contract PriceCapAdapterBase is IPriceCapAdapter {
(_maxRatioGrowthPerSecond * SECONDS_PER_YEAR * MINIMAL_RATIO_INCREASE_LIFETIME) >
type(uint104).max
) {
revert SnapshotMayOverflowSoon(snapshotRatio, maxYearlyRatioGrowthPercent);
revert SnapshotMayOverflowSoon(
priceCapParams.snapshotRatio,
priceCapParams.maxYearlyRatioGrowthPercent
);
}

emit CapParametersUpdated(
snapshotRatio,
snapshotTimestamp,
priceCapParams.snapshotRatio,
priceCapParams.snapshotTimestamp,
_maxRatioGrowthPerSecond,
maxYearlyRatioGrowthPercent
priceCapParams.maxYearlyRatioGrowthPercent
);
}

Expand Down
12 changes: 3 additions & 9 deletions src/contracts/RETHPriceCapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ contract RETHPriceCapAdapter is PriceCapAdapterBase {
* @param rETHAddress the address of the rETH token, the (rETH / ETH) ratio feed
* @param pairName name identifier
* @param minimumSnapshotDelay minimum time (in seconds) that should have passed from the snapshot timestamp to the current block.timestamp
* @param snapshotRatio the latest exchange ratio
* @param snapshotTimestamp the timestamp of the latest exchange ratio
* @param maxYearlyRatioGrowthPercent maximum growth of the underlying asset value per year, 100_00 is equal 100%
* @param priceCapParams parameters to set price cap
*/
constructor(
IACLManager aclManager,
address rETHToBaseAggregatorAddress,
address rETHAddress,
string memory pairName,
uint48 minimumSnapshotDelay,
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
PriceCapUpdateParams memory priceCapParams
)
PriceCapAdapterBase(
aclManager,
Expand All @@ -40,9 +36,7 @@ contract RETHPriceCapAdapter is PriceCapAdapterBase {
pairName,
18,
minimumSnapshotDelay,
snapshotRatio,
snapshotTimestamp,
maxYearlyRatioGrowthPercent
priceCapParams
)
{}

Expand Down
12 changes: 3 additions & 9 deletions src/contracts/SAvaxPriceCapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ contract SAvaxPriceCapAdapter is PriceCapAdapterBase {
* @param sAVAXAddress the address of the sAVAX token, the (sAVAX / AVAX) ratio feed
* @param pairName name identifier
* @param minimumSnapshotDelay minimum time (in seconds) that should have passed from the snapshot timestamp to the current block.timestamp
* @param snapshotRatio the latest exchange ratio
* @param snapshotTimestamp the timestamp of the latest exchange ratio
* @param maxYearlyRatioGrowthPercent maximum growth of the underlying asset value per year, 100_00 is equal 100%
* @param priceCapParams parameters to set price cap
*/
constructor(
IACLManager aclManager,
address avaxToBaseAggregatorAddress,
address sAVAXAddress,
string memory pairName,
uint48 minimumSnapshotDelay,
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
PriceCapUpdateParams memory priceCapParams
)
PriceCapAdapterBase(
aclManager,
Expand All @@ -40,9 +36,7 @@ contract SAvaxPriceCapAdapter is PriceCapAdapterBase {
pairName,
18,
minimumSnapshotDelay,
snapshotRatio,
snapshotTimestamp,
maxYearlyRatioGrowthPercent
priceCapParams
)
{}

Expand Down
12 changes: 3 additions & 9 deletions src/contracts/SDAIGnosisPriceCapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ contract SDAIGnosisPriceCapAdapter is PriceCapAdapterBase {
* @param sDaiAddress the address of the sDAI, used as the (sDAI / DAI) ratio feed
* @param pairName name identifier
* @param minimumSnapshotDelay minimum time (in seconds) that should have passed from the snapshot timestamp to the current block.timestamp
* @param snapshotRatio The latest exchange ratio
* @param snapshotTimestamp The timestamp of the latest exchange ratio
* @param maxYearlyRatioGrowthPercent Maximum growth of the underlying asset value per year, 100_00 is equal 100%
* @param priceCapParams parameters to set price cap
*/
constructor(
IACLManager aclManager,
address daiToBaseAggregatorAddress,
address sDaiAddress,
string memory pairName,
uint48 minimumSnapshotDelay,
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
PriceCapUpdateParams memory priceCapParams
)
PriceCapAdapterBase(
aclManager,
Expand All @@ -40,9 +36,7 @@ contract SDAIGnosisPriceCapAdapter is PriceCapAdapterBase {
pairName,
IERC4626(sDaiAddress).decimals(),
minimumSnapshotDelay,
snapshotRatio,
snapshotTimestamp,
maxYearlyRatioGrowthPercent
priceCapParams
)
{}

Expand Down
12 changes: 3 additions & 9 deletions src/contracts/SDAIPriceCapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ contract SDAIPriceCapAdapter is PriceCapAdapterBase {
* @param potAddress the address of the sDAI pot, used the (sDAI / DAI) ratio feed
* @param pairName name identifier
* @param minimumSnapshotDelay minimum time (in seconds) that should have passed from the snapshot timestamp to the current block.timestamp
* @param snapshotRatio the latest exchange ratio
* @param snapshotTimestamp the timestamp of the latest exchange ratio
* @param maxYearlyRatioGrowthPercent maximum growth of the underlying asset value per year, 100_00 is equal 100%
* @param priceCapParams parameters to set price cap
*/
constructor(
IACLManager aclManager,
address daiToBaseAggregatorAddress,
address potAddress,
string memory pairName,
uint48 minimumSnapshotDelay,
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
PriceCapUpdateParams memory priceCapParams
)
PriceCapAdapterBase(
aclManager,
Expand All @@ -40,9 +36,7 @@ contract SDAIPriceCapAdapter is PriceCapAdapterBase {
pairName,
27,
minimumSnapshotDelay,
snapshotRatio,
snapshotTimestamp,
maxYearlyRatioGrowthPercent
priceCapParams
)
{}

Expand Down
12 changes: 3 additions & 9 deletions src/contracts/WstETHPriceCapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ contract WstETHPriceCapAdapter is PriceCapAdapterBase {
* @param stEthAddress the address of the stETH contract, the (wStETH / ETH) ratio feed
* @param pairName name identifier
* @param minimumSnapshotDelay minimum time (in seconds) that should have passed from the snapshot timestamp to the current block.timestamp
* @param snapshotRatio the latest exchange ratio
* @param snapshotTimestamp the timestamp of the latest exchange ratio
* @param maxYearlyRatioGrowthPercent maximum growth of the underlying asset value per year, 100_00 is equal 100%
* @param priceCapParams parameters to set price cap
*/
constructor(
IACLManager aclManager,
address ethToBaseAggregatorAddress,
address stEthAddress,
string memory pairName,
uint48 minimumSnapshotDelay,
uint104 snapshotRatio,
uint48 snapshotTimestamp,
uint16 maxYearlyRatioGrowthPercent
PriceCapUpdateParams memory priceCapParams
)
PriceCapAdapterBase(
aclManager,
Expand All @@ -40,9 +36,7 @@ contract WstETHPriceCapAdapter is PriceCapAdapterBase {
pairName,
18,
minimumSnapshotDelay,
snapshotRatio,
snapshotTimestamp,
maxYearlyRatioGrowthPercent
priceCapParams
)
{}

Expand Down
Loading

0 comments on commit 70cc11c

Please sign in to comment.