Skip to content

Commit

Permalink
test: edge risk steward
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlymite committed Sep 30, 2024
1 parent b7375b4 commit 9a721eb
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 19 deletions.
97 changes: 97 additions & 0 deletions tests/EdgeRiskSteward.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {EdgeRiskSteward} from 'src/contracts/EdgeRiskSteward.sol';
import './RiskSteward.t.sol';

contract EdgeRiskSteward_Test is RiskSteward_Test {
function setUp() public override {
super.setUp();

vm.startPrank(GovernanceV3Ethereum.EXECUTOR_LVL_1);
steward = new EdgeRiskSteward(
AaveV3Ethereum.AAVE_PROTOCOL_DATA_PROVIDER,
IEngine(configEngine),
riskCouncil,
riskConfig
);
AaveV3Ethereum.ACL_MANAGER.addRiskAdmin(address(steward));
vm.stopPrank();
}

/* ----------------------------- Caps Tests ----------------------------- */

function test_updateCaps() public override {
(uint256 daiBorrowCapBefore, uint256 daiSupplyCapBefore) = AaveV3Ethereum
.AAVE_PROTOCOL_DATA_PROVIDER
.getReserveCaps(AaveV3EthereumAssets.DAI_UNDERLYING);

IEngine.CapsUpdate[] memory capUpdates = new IEngine.CapsUpdate[](1);
capUpdates[0] = IEngine.CapsUpdate(
AaveV3EthereumAssets.DAI_UNDERLYING,
(daiSupplyCapBefore * 110) / 100, // 10% relative increase
(daiBorrowCapBefore * 110) / 100 // 10% relative increase
);

vm.startPrank(riskCouncil);
vm.expectRevert(IRiskSteward.UpdateNotAllowed.selector);
steward.updateCaps(capUpdates);
}

function test_updateCaps_outOfRange() public override {}

function test_updateCaps_debounceNotRespected() public override {}

function test_updateCaps_allKeepCurrent() public override {}

function test_updateCaps_noSameUpdate() public override {}

function test_updateCaps_assetUnlisted() public override {}

function test_updateCaps_assetRestricted() public override {}

function test_updateCaps_toValueZeroNotAllowed() public override {}

/* ----------------------------- Collateral Tests ----------------------------- */

function test_updateCollateralSide() public override {
(, uint256 ltvBefore, uint256 ltBefore, uint256 lbBefore, , , , , , ) = AaveV3Ethereum
.AAVE_PROTOCOL_DATA_PROVIDER
.getReserveConfigurationData(AaveV3EthereumAssets.UNI_UNDERLYING);

// as the definition is with 2 decimals, and config engine does not take the decimals into account, so we divide by 100.
uint256 debtCeilingBefore = AaveV3Ethereum.AAVE_PROTOCOL_DATA_PROVIDER.getDebtCeiling(
AaveV3EthereumAssets.UNI_UNDERLYING
) / 100;

IEngine.CollateralUpdate[] memory collateralUpdates = new IEngine.CollateralUpdate[](1);
collateralUpdates[0] = IEngine.CollateralUpdate({
asset: AaveV3EthereumAssets.UNI_UNDERLYING,
ltv: ltvBefore + 10_00, // 10% absolute increase
liqThreshold: ltBefore + 5_00, // 5% absolute increase
liqBonus: (lbBefore - 100_00) + 2_00, // 2% absolute increase
debtCeiling: (debtCeilingBefore * 110) / 100, // 10% relative increase
liqProtocolFee: EngineFlags.KEEP_CURRENT
});

vm.startPrank(riskCouncil);
vm.expectRevert(IRiskSteward.UpdateNotAllowed.selector);
steward.updateCollateralSide(collateralUpdates);
}

function test_updateCollateralSide_outOfRange() public override {}

function test_updateCollateralSide_debounceNotRespected() public override {}

function test_updateCollateralSide_liqProtocolFeeNotAllowed() public override {}

function test_updateCollateralSide_assetUnlisted() public override {}

function test_updateCollateralSide_assetRestricted() public override {}

function test_updateCollateralSide_toValueZeroNotAllowed() public override {}

function test_updateCollaterals_allKeepCurrent() public override {}

function test_updateCollaterals_noSameUpdate() public override {}
}
38 changes: 19 additions & 19 deletions tests/RiskSteward.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {ConfigEngineDeployer} from './utils/ConfigEngineDeployer.sol';

contract RiskSteward_Test is Test {
address public constant riskCouncil = address(42);
RiskSteward public steward;
IRiskSteward public steward;
address public configEngine;
IRiskSteward.RiskParamConfig public defaultRiskParamConfig;
IRiskSteward.Config public riskConfig;
Expand All @@ -22,7 +22,7 @@ contract RiskSteward_Test is Test {

event RiskConfigSet(IRiskSteward.Config indexed riskConfig);

function setUp() public {
function setUp() public virtual {
vm.createSelectFork(vm.rpcUrl('mainnet'), 20439517);

configEngine = AaveV3Ethereum.CONFIG_ENGINE;
Expand Down Expand Up @@ -64,7 +64,7 @@ contract RiskSteward_Test is Test {

/* ----------------------------- Caps Tests ----------------------------- */

function test_updateCaps() public {
function test_updateCaps() public virtual {
(uint256 daiBorrowCapBefore, uint256 daiSupplyCapBefore) = AaveV3Ethereum
.AAVE_PROTOCOL_DATA_PROVIDER
.getReserveCaps(AaveV3EthereumAssets.DAI_UNDERLYING);
Expand Down Expand Up @@ -113,7 +113,7 @@ contract RiskSteward_Test is Test {
assertEq(daiSupplyCapAfter, capUpdates[0].supplyCap);
}

function test_updateCaps_outOfRange() public {
function test_updateCaps_outOfRange() public virtual {
(uint256 daiBorrowCapBefore, uint256 daiSupplyCapBefore) = AaveV3Ethereum
.AAVE_PROTOCOL_DATA_PROVIDER
.getReserveCaps(AaveV3EthereumAssets.DAI_UNDERLYING);
Expand All @@ -140,7 +140,7 @@ contract RiskSteward_Test is Test {
vm.stopPrank();
}

function test_updateCaps_debounceNotRespected() public {
function test_updateCaps_debounceNotRespected() public virtual {
(uint256 daiBorrowCapBefore, uint256 daiSupplyCapBefore) = AaveV3Ethereum
.AAVE_PROTOCOL_DATA_PROVIDER
.getReserveCaps(AaveV3EthereumAssets.DAI_UNDERLYING);
Expand Down Expand Up @@ -172,7 +172,7 @@ contract RiskSteward_Test is Test {
vm.stopPrank();
}

function test_updateCaps_allKeepCurrent() public {
function test_updateCaps_allKeepCurrent() public virtual {
IEngine.CapsUpdate[] memory capUpdates = new IEngine.CapsUpdate[](1);
capUpdates[0] = IEngine.CapsUpdate(
AaveV3EthereumAssets.DAI_UNDERLYING,
Expand All @@ -185,7 +185,7 @@ contract RiskSteward_Test is Test {
steward.updateCaps(capUpdates);
}

function test_updateCaps_noSameUpdate() public {
function test_updateCaps_noSameUpdate() public virtual {
(uint256 daiBorrowCapBefore, uint256 daiSupplyCapBefore) = AaveV3Ethereum
.AAVE_PROTOCOL_DATA_PROVIDER
.getReserveCaps(AaveV3EthereumAssets.DAI_UNDERLYING);
Expand All @@ -202,7 +202,7 @@ contract RiskSteward_Test is Test {
steward.updateCaps(capUpdates);
}

function test_updateCaps_assetUnlisted() public {
function test_updateCaps_assetUnlisted() public virtual {
address unlistedAsset = 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84; // stETH

IEngine.CapsUpdate[] memory capUpdates = new IEngine.CapsUpdate[](1);
Expand All @@ -214,7 +214,7 @@ contract RiskSteward_Test is Test {
steward.updateCaps(capUpdates);
}

function test_updateCaps_assetRestricted() public {
function test_updateCaps_assetRestricted() public virtual {
vm.startPrank(GovernanceV3Ethereum.EXECUTOR_LVL_1);
steward.setAddressRestricted(AaveV3EthereumAssets.GHO_UNDERLYING, true);
vm.stopPrank();
Expand All @@ -228,7 +228,7 @@ contract RiskSteward_Test is Test {
vm.stopPrank();
}

function test_updateCaps_toValueZeroNotAllowed() public {
function test_updateCaps_toValueZeroNotAllowed() public virtual {
// set risk config to allow 100% cap change to 0
IRiskSteward.RiskParamConfig memory capsParamConfig = IRiskSteward.RiskParamConfig({
minDelay: 5 days,
Expand Down Expand Up @@ -489,7 +489,7 @@ contract RiskSteward_Test is Test {

/* ----------------------------- Collateral Tests ----------------------------- */

function test_updateCollateralSide() public {
function test_updateCollateralSide() public virtual {
(, uint256 ltvBefore, uint256 ltBefore, uint256 lbBefore, , , , , , ) = AaveV3Ethereum
.AAVE_PROTOCOL_DATA_PROVIDER
.getReserveConfigurationData(AaveV3EthereumAssets.UNI_UNDERLYING);
Expand Down Expand Up @@ -578,7 +578,7 @@ contract RiskSteward_Test is Test {
assertEq(lastUpdated.liquidationBonusLastUpdated, block.timestamp);
}

function test_updateCollateralSide_outOfRange() public {
function test_updateCollateralSide_outOfRange() public virtual {
(, uint256 ltvBefore, uint256 ltBefore, uint256 lbBefore, , , , , , ) = AaveV3Ethereum
.AAVE_PROTOCOL_DATA_PROVIDER
.getReserveConfigurationData(AaveV3EthereumAssets.UNI_UNDERLYING);
Expand Down Expand Up @@ -619,7 +619,7 @@ contract RiskSteward_Test is Test {
vm.stopPrank();
}

function test_updateCollateralSide_debounceNotRespected() public {
function test_updateCollateralSide_debounceNotRespected() public virtual {
// as the definition is with 2 decimals, and config engine does not take the decimals into account, so we divide by 100.
uint256 debtCeilingBefore = AaveV3Ethereum.AAVE_PROTOCOL_DATA_PROVIDER.getDebtCeiling(
AaveV3EthereumAssets.UNI_UNDERLYING
Expand Down Expand Up @@ -659,7 +659,7 @@ contract RiskSteward_Test is Test {
vm.stopPrank();
}

function test_updateCollateralSide_liqProtocolFeeNotAllowed() public {
function test_updateCollateralSide_liqProtocolFeeNotAllowed() public virtual {
IEngine.CollateralUpdate[] memory collateralUpdates = new IEngine.CollateralUpdate[](1);
collateralUpdates[0] = IEngine.CollateralUpdate({
asset: AaveV3EthereumAssets.UNI_UNDERLYING,
Expand All @@ -676,7 +676,7 @@ contract RiskSteward_Test is Test {
vm.stopPrank();
}

function test_updateCollateralSide_assetUnlisted() public {
function test_updateCollateralSide_assetUnlisted() public virtual {
IEngine.CollateralUpdate[] memory collateralUpdates = new IEngine.CollateralUpdate[](1);
collateralUpdates[0] = IEngine.CollateralUpdate({
asset: 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84, // stETH
Expand All @@ -692,7 +692,7 @@ contract RiskSteward_Test is Test {
steward.updateCollateralSide(collateralUpdates);
}

function test_updateCollateralSide_assetRestricted() public {
function test_updateCollateralSide_assetRestricted() public virtual {
vm.startPrank(GovernanceV3Ethereum.EXECUTOR_LVL_1);
steward.setAddressRestricted(AaveV3EthereumAssets.UNI_UNDERLYING, true);
vm.stopPrank();
Expand All @@ -712,7 +712,7 @@ contract RiskSteward_Test is Test {
steward.updateCollateralSide(collateralUpdates);
}

function test_updateCollateralSide_toValueZeroNotAllowed() public {
function test_updateCollateralSide_toValueZeroNotAllowed() public virtual {
// set risk config to allow 100% collateral param change to 0
IRiskSteward.RiskParamConfig memory collateralParamConfig = IRiskSteward.RiskParamConfig({
minDelay: 5 days,
Expand Down Expand Up @@ -742,7 +742,7 @@ contract RiskSteward_Test is Test {
steward.updateCollateralSide(collateralUpdates);
}

function test_updateCollaterals_allKeepCurrent() public {
function test_updateCollaterals_allKeepCurrent() public virtual {
IEngine.CollateralUpdate[] memory collateralUpdates = new IEngine.CollateralUpdate[](1);
collateralUpdates[0] = IEngine.CollateralUpdate({
asset: AaveV3EthereumAssets.UNI_UNDERLYING,
Expand All @@ -758,7 +758,7 @@ contract RiskSteward_Test is Test {
steward.updateCollateralSide(collateralUpdates);
}

function test_updateCollaterals_noSameUpdate() public {
function test_updateCollaterals_noSameUpdate() public virtual {
(, uint256 ltvBefore, uint256 ltBefore, uint256 lbBefore, , , , , , ) = AaveV3Ethereum
.AAVE_PROTOCOL_DATA_PROVIDER
.getReserveConfigurationData(AaveV3EthereumAssets.UNI_UNDERLYING);
Expand Down

0 comments on commit 9a721eb

Please sign in to comment.