From 926c817a72b15b10c54566fee443086518870ca1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Mon, 11 Dec 2023 23:53:06 +0100 Subject: [PATCH] fix: remove cap limitation (#195) * fix: remove cap limitation * Update src/ProtocolV3TestBase.sol Co-authored-by: Zer0dot * fix: remove unused parameter --------- Co-authored-by: Zer0dot --- src/ProtocolV3TestBase.sol | 58 ++++++++++++++-------------------- tests/ProtocolV3TestBase.t.sol | 2 +- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/ProtocolV3TestBase.sol b/src/ProtocolV3TestBase.sol index 325df78f..a12a51cc 100644 --- a/src/ProtocolV3TestBase.sol +++ b/src/ProtocolV3TestBase.sol @@ -112,7 +112,9 @@ contract ProtocolV3TestBase is CommonTestBase { if (i < configsBeforeLength) { // borrow increase should only happen on assets with borrowing enabled // unless it is setting a borrow cap for the first time - if (configBefore[i].borrowCap < configAfter[i].borrowCap && configBefore[i].borrowCap != 0) { + if ( + configBefore[i].borrowCap < configAfter[i].borrowCap && configBefore[i].borrowCap != 0 + ) { require(configAfter[i].borrowingEnabled, 'PL_BORROW_CAP_BORROW_DISABLED'); } } else { @@ -178,7 +180,7 @@ contract ProtocolV3TestBase is CommonTestBase { */ function e2eTest(IPool pool) public { ReserveConfig[] memory configs = _getReservesConfigs(pool); - ReserveConfig memory collateralConfig = _getGoodCollateral(pool, configs, 1000); + ReserveConfig memory collateralConfig = _getGoodCollateral(configs); uint256 snapshot = vm.snapshot(); for (uint256 i; i < configs.length; i++) { if (_includeInE2e(configs[i])) { @@ -203,15 +205,24 @@ contract ProtocolV3TestBase is CommonTestBase { address collateralSupplier = vm.addr(3); address testAssetSupplier = vm.addr(4); require(collateralConfig.usageAsCollateralEnabled, 'COLLATERAL_CONFIG_MUST_BE_COLLATERAL'); - uint256 testAssetAmount = _getTokenAmountByDollarValue(pool, testAssetConfig, 100); + uint256 collateralAssetAmount = _getTokenAmountByDollarValue(pool, collateralConfig, 100000); + uint256 testAssetAmount = _getTokenAmountByDollarValue(pool, testAssetConfig, 1000); + + // remove caps as they should not prevent testing + IPoolAddressesProvider addressesProvider = IPoolAddressesProvider(pool.ADDRESSES_PROVIDER()); + IPoolConfigurator poolConfigurator = IPoolConfigurator(addressesProvider.getPoolConfigurator()); + vm.startPrank(addressesProvider.getACLAdmin()); + if (collateralConfig.supplyCap != 0) + poolConfigurator.setSupplyCap(testAssetConfig.underlying, 0); + if (testAssetConfig.supplyCap != 0) + poolConfigurator.setSupplyCap(testAssetConfig.underlying, 0); + if (testAssetConfig.borrowCap != 0) + poolConfigurator.setBorrowCap(testAssetConfig.underlying, 0); + vm.stopPrank(); + // GHO is a special case as it cannot be supplied if (testAssetConfig.underlying == AaveV3EthereumAssets.GHO_UNDERLYING) { - _deposit( - collateralConfig, - pool, - collateralSupplier, - _getTokenAmountByDollarValue(pool, collateralConfig, 10000) - ); + _deposit(collateralConfig, pool, collateralSupplier, collateralAssetAmount); uint256 snapshot = vm.snapshot(); // test variable borrowing if (testAssetConfig.borrowingEnabled) { @@ -224,19 +235,7 @@ contract ProtocolV3TestBase is CommonTestBase { } } } else { - if ( - (testAssetConfig.supplyCap * 10 ** testAssetConfig.decimals) < - IERC20(testAssetConfig.aToken).totalSupply() + testAssetAmount - ) { - console.log('Skip: %s, supply cap fully utilized', testAssetConfig.symbol); - return; - } - _deposit( - collateralConfig, - pool, - collateralSupplier, - _getTokenAmountByDollarValue(pool, collateralConfig, 10000) - ); + _deposit(collateralConfig, pool, collateralSupplier, collateralAssetAmount); _deposit(testAssetConfig, pool, testAssetSupplier, testAssetAmount); uint256 snapshot = vm.snapshot(); // test withdrawal @@ -305,10 +304,8 @@ contract ProtocolV3TestBase is CommonTestBase { * @dev returns a "good" collateral in the list that cannot be borrowed in stable mode */ function _getGoodCollateral( - IPool pool, - ReserveConfig[] memory configs, - uint256 minSupplyCapDollarMargin - ) private view returns (ReserveConfig memory config) { + ReserveConfig[] memory configs + ) private pure returns (ReserveConfig memory config) { for (uint256 i = 0; i < configs.length; i++) { if ( // not frozen etc @@ -318,14 +315,7 @@ contract ProtocolV3TestBase is CommonTestBase { // not stable borrowable as this makes testing stable borrowing unnecessary hard to reason about !configs[i].stableBorrowRateEnabled && // not isolated asset as we can only borrow stablecoins against it - configs[i].debtCeiling == 0 && - // supply cap not yet reached - ((configs[i].supplyCap * 10 ** configs[i].decimals) > - IERC20(configs[i].aToken).totalSupply()) && - (// supply cap margin big enough - (configs[i].supplyCap * 10 ** configs[i].decimals) - - IERC20(configs[i].aToken).totalSupply() > - _getTokenAmountByDollarValue(pool, configs[i], minSupplyCapDollarMargin)) + configs[i].debtCeiling == 0 ) return configs[i]; } revert('ERROR: No usable collateral found'); diff --git a/tests/ProtocolV3TestBase.t.sol b/tests/ProtocolV3TestBase.t.sol index ecc8fd6a..3486af4c 100644 --- a/tests/ProtocolV3TestBase.t.sol +++ b/tests/ProtocolV3TestBase.t.sol @@ -70,7 +70,7 @@ contract ProtocolV3TestE2ETestAll is ProtocolV3TestBase { contract ProtocolV3TestE2ETestAllMainnet is ProtocolV3TestBase { function setUp() public { - vm.createSelectFork('mainnet', 17990597); + vm.createSelectFork('mainnet', 18763779); } function test_e2e() public {