Skip to content

Commit

Permalink
fix: interest-rate-strategy-range-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Valeri committed Dec 29, 2021
1 parent 254a021 commit adf2f4c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions contracts/protocol/libraries/helpers/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions test-suites/rate-strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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([
Expand All @@ -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);
});
});

0 comments on commit adf2f4c

Please sign in to comment.