diff --git a/src/contracts/AaveStewardInjectorCaps.sol b/src/contracts/AaveStewardInjectorCaps.sol index ed8dff6..153ba4f 100644 --- a/src/contracts/AaveStewardInjectorCaps.sol +++ b/src/contracts/AaveStewardInjectorCaps.sol @@ -123,7 +123,7 @@ contract AaveStewardInjectorCaps is AaveStewardInjectorBase, IAaveStewardInjecto !isUpdateIdExecuted(updateRiskParams.updateId) && (updateRiskParams.timestamp + EXPIRATION_PERIOD > block.timestamp) && _markets.contains(updateRiskParams.market) && - updateRiskParams.updateType.equal('supplyCap') || updateRiskParams.updateType.equal('borrowCap') && + (updateRiskParams.updateType.equal('supplyCap') || updateRiskParams.updateType.equal('borrowCap')) && !isDisabled(updateRiskParams.updateId) ); } diff --git a/tests/AaveStewardsInjectorBase.t.sol b/tests/AaveStewardsInjectorBase.t.sol index 5c7b629..7f6ad0f 100644 --- a/tests/AaveStewardsInjectorBase.t.sol +++ b/tests/AaveStewardsInjectorBase.t.sol @@ -104,19 +104,11 @@ abstract contract AaveStewardsInjectorBaseTest is TestnetProcedures { vm.expectEmit(address(_stewardInjector)); emit ActionSucceeded(1); - bool isAutomationPerformed = _checkAndPerformAutomation(); - assertTrue(isAutomationPerformed); - - (, bytes memory performData) = _stewardInjector.checkUpkeep(''); - vm.expectRevert(IAaveStewardInjectorBase.UpdateCannotBeInjected.selector); + (bool shouldRunKeeper, bytes memory performData) = _stewardInjector.checkUpkeep(''); _stewardInjector.performUpkeep(performData); - } + assertTrue(shouldRunKeeper); - function test_reverts_ifUpdateDoesNotExist() public { - vm.expectRevert(bytes('No update found for the specified parameter and market.')); - (, bytes memory performData) = _stewardInjector.checkUpkeep(''); - - vm.expectRevert(bytes('No update found for the specified parameter and market.')); + vm.expectRevert(IAaveStewardInjectorBase.UpdateCannotBeInjected.selector); _stewardInjector.performUpkeep(performData); } diff --git a/tests/AaveStewardsInjectorCaps.t.sol b/tests/AaveStewardsInjectorCaps.t.sol new file mode 100644 index 0000000..52f8d04 --- /dev/null +++ b/tests/AaveStewardsInjectorCaps.t.sol @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity ^0.8.0; + +import {AaveStewardInjectorCaps} from '../src/contracts/AaveStewardInjectorCaps.sol'; +import './AaveStewardsInjectorBase.t.sol'; + +contract AaveStewardsInjectorCaps_Test is AaveStewardsInjectorBaseTest { + function setUp() public override { + super.setUp(); + + IRiskSteward.RiskParamConfig memory defaultRiskParamConfig = IRiskSteward.RiskParamConfig({ + minDelay: 3 days, + maxPercentChange: 100_00 + }); + IRiskSteward.Config memory riskConfig = IRiskSteward.Config({ + ltv: defaultRiskParamConfig, + liquidationThreshold: defaultRiskParamConfig, + liquidationBonus: defaultRiskParamConfig, + supplyCap: defaultRiskParamConfig, + borrowCap: defaultRiskParamConfig, + debtCeiling: defaultRiskParamConfig, + baseVariableBorrowRate: defaultRiskParamConfig, + variableRateSlope1: defaultRiskParamConfig, + variableRateSlope2: defaultRiskParamConfig, + optimalUsageRatio: defaultRiskParamConfig, + priceCapLst: defaultRiskParamConfig, + priceCapStable: defaultRiskParamConfig + }); + + // setup risk oracle + vm.startPrank(_riskOracleOwner); + address[] memory initialSenders = new address[](1); + initialSenders[0] = _riskOracleOwner; + string[] memory initialUpdateTypes = new string[](2); + initialUpdateTypes[0] = 'supplyCap'; + initialUpdateTypes[1] = 'borrowCap'; + + _riskOracle = new RiskOracle( + 'RiskOracle', + initialSenders, + initialUpdateTypes + ); + vm.stopPrank(); + + // setup steward injector + vm.startPrank(_stewardsInjectorOwner); + + address computedRiskStewardAddress = vm.computeCreateAddress(_stewardsInjectorOwner, vm.getNonce(_stewardsInjectorOwner) + 1); + _stewardInjector = new AaveStewardInjectorCaps( + address(_riskOracle), + address(computedRiskStewardAddress), + _stewardsInjectorOwner + ); + address[] memory whitelistedMarkets = new address[](1); + whitelistedMarkets[0] = address(weth); + AaveStewardInjectorCaps(address(_stewardInjector)).addMarkets(whitelistedMarkets); + + // setup risk steward + _riskSteward = new RiskSteward( + contracts.protocolDataProvider, + IEngine(report.configEngine), + address(_stewardInjector), + riskConfig + ); + + vm.assertEq(computedRiskStewardAddress, address(_riskSteward)); + vm.stopPrank(); + + vm.startPrank(poolAdmin); + contracts.aclManager.addRiskAdmin(address(_riskSteward)); + + // as initial caps are at 0, which the steward cannot update from + contracts.poolConfiguratorProxy.setSupplyCap(address(weth), 100); + contracts.poolConfiguratorProxy.setBorrowCap(address(weth), 50); + vm.stopPrank(); + } + + function test_noInjection_ifUpdateDoesNotExist() public { + assertFalse(_checkAndPerformAutomation()); + } + + function _addUpdateToRiskOracle() internal override { + vm.startPrank(_riskOracleOwner); + + _riskOracle.publishRiskParameterUpdate( + 'referenceId', + abi.encode(105), + 'supplyCap', + address(weth), + 'additionalData' + ); + vm.stopPrank(); + } +} diff --git a/tests/AaveStewardsInjectorRates.t.sol b/tests/AaveStewardsInjectorRates.t.sol index fa97d0d..f8c9062 100644 --- a/tests/AaveStewardsInjectorRates.t.sol +++ b/tests/AaveStewardsInjectorRates.t.sol @@ -68,6 +68,14 @@ contract AaveStewardsInjectorRates_Test is AaveStewardsInjectorBaseTest { vm.stopPrank(); } + function test_reverts_ifUpdateDoesNotExist() public { + vm.expectRevert(bytes('No update found for the specified parameter and market.')); + (, bytes memory performData) = _stewardInjector.checkUpkeep(''); + + vm.expectRevert(bytes('No update found for the specified parameter and market.')); + _stewardInjector.performUpkeep(performData); + } + function _addUpdateToRiskOracle() internal override { vm.startPrank(_riskOracleOwner);