diff --git a/contracts/protocol/libraries/helpers/Errors.sol b/contracts/protocol/libraries/helpers/Errors.sol index 4d349712e..754f79013 100644 --- a/contracts/protocol/libraries/helpers/Errors.sol +++ b/contracts/protocol/libraries/helpers/Errors.sol @@ -89,4 +89,6 @@ library Errors { string public constant INVALID_SIGNATURE = '80'; // 'Invalid signature' string public constant OPERATION_NOT_SUPPORTED = '81'; // 'Operation not supported' string public constant DEBT_CEILING_NOT_ZERO = '82'; // 'Debt ceiling is not zero' + string public constant INVALID_OPTIMAL_UTILIZATION_RATE = '83'; // 'Invalid optimal utilization ratio' + string public constant INVALID_OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO = '84'; // 'Invalid optimal stable to total debt ratio' } diff --git a/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol b/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol index e8dc47f56..6215ebd87 100644 --- a/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol +++ b/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol @@ -75,6 +75,11 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy { uint256 stableRateExcessOffset, uint256 optimalStableToTotalDebtRatio ) { + require(WadRayMath.RAY >= optimalUtilizationRate, Errors.INVALID_OPTIMAL_UTILIZATION_RATE); + require( + WadRayMath.RAY >= optimalStableToTotalDebtRatio, + Errors.INVALID_OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO + ); OPTIMAL_UTILIZATION_RATE = optimalUtilizationRate; EXCESS_UTILIZATION_RATE = WadRayMath.RAY - optimalUtilizationRate; OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO = optimalStableToTotalDebtRatio; diff --git a/helpers/types.ts b/helpers/types.ts index b31913e2d..7961b3d5a 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -153,6 +153,8 @@ export enum ProtocolErrors { INVALID_SIGNATURE = '80', // 'Invalid signature' OPERATION_NOT_SUPPORTED = '81', // 'Operation not supported' DEBT_CEILING_NOT_ZERO = '82', // 'Debt ceiling is not zero' + INVALID_OPTIMAL_UTILIZATION_RATE = '83', + INVALID_OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO = '84', // SafeCast SAFECAST_UINT128_OVERFLOW = "SafeCast: value doesn't fit in 128 bits", diff --git a/test-suites/rate-strategy.spec.ts b/test-suites/rate-strategy.spec.ts index 195a8241f..9b53e4de3 100644 --- a/test-suites/rate-strategy.spec.ts +++ b/test-suites/rate-strategy.spec.ts @@ -6,6 +6,7 @@ import { AToken, DefaultReserveInterestRateStrategy, MintableERC20 } from '../ty import { strategyDAI } from '@aave/deploy-v3/dist/markets/aave/reservesConfigs'; import { rateStrategyStableTwo } from '@aave/deploy-v3/dist/markets/aave/rateStrategies'; import { TestEnv, makeSuite } from './helpers/make-suite'; +import { ProtocolErrors, RateMode } from '../helpers/types'; import { formatUnits } from '@ethersproject/units'; import './helpers/utils/wadraymath'; @@ -31,6 +32,9 @@ makeSuite('InterestRateStrategy', (testEnv: TestEnv) => { rateStrategyStableTwo.baseStableRateOffset ); + const { INVALID_OPTIMAL_UTILIZATION_RATE, INVALID_OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO } = + ProtocolErrors; + before(async () => { dai = testEnv.dai; aDai = testEnv.aDai; @@ -365,7 +369,7 @@ makeSuite('InterestRateStrategy', (testEnv: TestEnv) => { ); }); - it('Deploy an interest rate strategy with optimalUtilizationRate out of range', async () => { + it('Deploy an interest rate strategy with optimalUtilizationRate out of range (expect revert)', async () => { const { addressesProvider } = testEnv; await expect( @@ -381,10 +385,10 @@ makeSuite('InterestRateStrategy', (testEnv: TestEnv) => { rateStrategyStableTwo.stableRateExcessOffset, rateStrategyStableTwo.optimalStableToTotalDebtRatio, ]) - ).to.be.reverted; + ).to.be.revertedWith(INVALID_OPTIMAL_UTILIZATION_RATE); }); - it('Deploy an interest rate strategy with optimalStableToTotalDebtRatio out of range', async () => { + it('Deploy an interest rate strategy with optimalStableToTotalDebtRatio out of range (expect revert)', async () => { const { addressesProvider } = testEnv; await expect( deployDefaultReserveInterestRateStrategy([ @@ -399,6 +403,6 @@ makeSuite('InterestRateStrategy', (testEnv: TestEnv) => { rateStrategyStableTwo.stableRateExcessOffset, utils.parseUnits('1.0', 28), ]) - ).to.be.reverted; + ).to.be.revertedWith(INVALID_OPTIMAL_STABLE_TO_TOTAL_DEBT_RATIO); }); });