Skip to content

Commit

Permalink
test: aave steward cap injector
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlymite committed Jan 30, 2025
1 parent 753eefd commit 694625b
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/contracts/AaveStewardInjectorCaps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down
14 changes: 3 additions & 11 deletions tests/AaveStewardsInjectorBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
94 changes: 94 additions & 0 deletions tests/AaveStewardsInjectorCaps.t.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
8 changes: 8 additions & 0 deletions tests/AaveStewardsInjectorRates.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 694625b

Please sign in to comment.