Skip to content

Commit

Permalink
Merge pull request #710 from aave/feat/enable-disable-flashloan-config
Browse files Browse the repository at this point in the history
feat/enable disable flashloan config
  • Loading branch information
miguelmtzinf authored Nov 15, 2022
2 parents 1b950ab + bf652c2 commit c18e3c4
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 80 deletions.
2 changes: 2 additions & 0 deletions contracts/deployments/ReservesSetupHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ contract ReservesSetupHelper is Ownable {
uint256 supplyCap;
bool stableBorrowingEnabled;
bool borrowingEnabled;
bool flashLoanEnabled;
}

/**
Expand Down Expand Up @@ -50,6 +51,7 @@ contract ReservesSetupHelper is Ownable {
inputParams[i].stableBorrowingEnabled
);
}
configurator.setReserveFlashLoaning(inputParams[i].asset, inputParams[i].flashLoanEnabled);
configurator.setSupplyCap(inputParams[i].asset, inputParams[i].supplyCap);
configurator.setReserveFactor(inputParams[i].asset, inputParams[i].reserveFactor);
}
Expand Down
14 changes: 14 additions & 0 deletions contracts/interfaces/IPoolConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ interface IPoolConfigurator {
**/
event ReserveBorrowing(address indexed asset, bool enabled);

/**
* @dev Emitted when flashloans are enabled or disabled on a reserve.
* @param asset The address of the underlying asset of the reserve
* @param enabled True if flashloans are enabled, false otherwise
*/
event ReserveFlashLoaning(address indexed asset, bool enabled);

/**
* @dev Emitted when the collateralization risk parameters for the specified asset are updated.
* @param asset The address of the underlying asset of the reserve
Expand Down Expand Up @@ -310,6 +317,13 @@ interface IPoolConfigurator {
**/
function setReserveStableRateBorrowing(address asset, bool enabled) external;

/**
* @notice Enable or disable flashloans on a reserve
* @param asset The address of the underlying asset of the reserve
* @param enabled True if flashloans need to be enabled, false otherwise
*/
function setReserveFlashLoaning(address asset, bool enabled) external;

/**
* @notice Activate or deactivate a reserve
* @param asset The address of the underlying asset of the reserve
Expand Down
12 changes: 12 additions & 0 deletions contracts/misc/AaveProtocolDataProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,16 @@ contract AaveProtocolDataProvider is IPoolDataProvider {

return (reserve.interestRateStrategyAddress);
}

/**
* @notice Returns whether the reserve has FlashLoans enabled or disabled
* @param asset The address of the underlying asset of the reserve
* @return True if FlashLoans are enabled, false otherwise
* */
function getFlashLoanEnabled(address asset) external view returns (bool) {
DataTypes.ReserveConfigurationMap memory configuration = IPool(ADDRESSES_PROVIDER.getPool())
.getConfiguration(asset);

return configuration.getFlashLoanEnabled();
}
}
14 changes: 13 additions & 1 deletion contracts/mocks/helpers/MockReserveConfiguration.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.10;

import {ReserveConfiguration} from '../../protocol/libraries/configuration/ReserveConfiguration.sol';
import {
ReserveConfiguration
} from '../../protocol/libraries/configuration/ReserveConfiguration.sol';
import {DataTypes} from '../../protocol/libraries/types/DataTypes.sol';

contract MockReserveConfiguration {
Expand Down Expand Up @@ -109,6 +111,16 @@ contract MockReserveConfiguration {
configuration = config;
}

function setFlashLoanEnabled(bool enabled) external {
DataTypes.ReserveConfigurationMap memory config = configuration;
config.setFlashLoanEnabled(enabled);
configuration = config;
}

function getFlashLoanEnabled() external view returns (bool) {
return configuration.getFlashLoanEnabled();
}

function setSupplyCap(uint256 supplyCap) external {
DataTypes.ReserveConfigurationMap memory config = configuration;
config.setSupplyCap(supplyCap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ library ReserveConfiguration {
uint256 internal constant PAUSED_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant BORROWABLE_IN_ISOLATION_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant SILOED_BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant FLASHLOAN_ENABLED_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant BORROW_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant SUPPLY_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
Expand All @@ -40,7 +41,7 @@ library ReserveConfiguration {
uint256 internal constant IS_PAUSED_START_BIT_POSITION = 60;
uint256 internal constant BORROWABLE_IN_ISOLATION_START_BIT_POSITION = 61;
uint256 internal constant SILOED_BORROWING_START_BIT_POSITION = 62;
/// @dev bit 63 reserved
uint256 internal constant FLASHLOAN_ENABLED_START_BIT_POSITION = 63;

uint256 internal constant RESERVE_FACTOR_START_BIT_POSITION = 64;
uint256 internal constant BORROW_CAP_START_BIT_POSITION = 80;
Expand Down Expand Up @@ -547,6 +548,33 @@ library ReserveConfiguration {
return (self.data & ~EMODE_CATEGORY_MASK) >> EMODE_CATEGORY_START_BIT_POSITION;
}

/**
* @notice Sets the flashloanble flag for the reserve
* @param self The reserve configuration
* @param flashLoanEnabled True if the asset is flashloanable, false otherwise
*/
function setFlashLoanEnabled(DataTypes.ReserveConfigurationMap memory self, bool flashLoanEnabled)
internal
pure
{
self.data =
(self.data & FLASHLOAN_ENABLED_MASK) |
(uint256(flashLoanEnabled ? 1 : 0) << FLASHLOAN_ENABLED_START_BIT_POSITION);
}

/**
* @notice Gets the flashloanable flag for the reserve
* @param self The reserve configuration
* @return The flashloanable flag
*/
function getFlashLoanEnabled(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (bool)
{
return (self.data & ~FLASHLOAN_ENABLED_MASK) != 0;
}

/**
* @notice Gets the configuration flags of the reserve
* @param self The reserve configuration
Expand Down
1 change: 1 addition & 0 deletions contracts/protocol/libraries/helpers/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ library Errors {
string public constant STABLE_BORROWING_ENABLED = '88'; // 'Stable borrowing is enabled'
string public constant SILOED_BORROWING_VIOLATION = '89'; // 'User is trying to borrow multiple assets including a siloed one'
string public constant RESERVE_DEBT_NOT_ZERO = '90'; // the total debt of the reserve needs to be 0
string public constant FLASHLOAN_DISABLED = '91'; // FlashLoaning for this asset is disabled
}
6 changes: 2 additions & 4 deletions contracts/protocol/libraries/logic/ValidationLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,7 @@ library ValidationLogic {
) internal view {
require(assets.length == amounts.length, Errors.INCONSISTENT_FLASHLOAN_PARAMS);
for (uint256 i = 0; i < assets.length; i++) {
DataTypes.ReserveConfigurationMap memory configuration = reservesData[assets[i]]
.configuration;
require(!configuration.getPaused(), Errors.RESERVE_PAUSED);
require(configuration.getActive(), Errors.RESERVE_INACTIVE);
validateFlashloanSimple(reservesData[assets[i]]);
}
}

Expand All @@ -469,6 +466,7 @@ library ValidationLogic {
DataTypes.ReserveConfigurationMap memory configuration = reserve.configuration;
require(!configuration.getPaused(), Errors.RESERVE_PAUSED);
require(configuration.getActive(), Errors.RESERVE_INACTIVE);
require(configuration.getFlashLoanEnabled(), Errors.FLASHLOAN_DISABLED);
}

struct ValidateLiquidationCallLocalVars {
Expand Down
13 changes: 13 additions & 0 deletions contracts/protocol/pool/PoolConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ contract PoolConfigurator is VersionedInitializable, IPoolConfigurator {
emit ReserveStableRateBorrowing(asset, enabled);
}

/// @inheritdoc IPoolConfigurator
function setReserveFlashLoaning(address asset, bool enabled)
external
override
onlyRiskOrPoolAdmins
{
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);

currentConfig.setFlashLoanEnabled(enabled);
_pool.setConfiguration(asset, currentConfig);
emit ReserveFlashLoaning(asset, enabled);
}

/// @inheritdoc IPoolConfigurator
function setReserveActive(address asset, bool active) external override onlyPoolAdmin {
if (!active) _checkNoSuppliers(asset);
Expand Down
1 change: 1 addition & 0 deletions helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export enum ProtocolErrors {
STABLE_BORROWING_ENABLED = '88', // 'Stable borrowing is enabled'
SILOED_BORROWING_VIOLATION = '89', // user is trying to violate the siloed borrowing rule
RESERVE_DEBT_NOT_ZERO = '90', // the total debt of the reserve needs to be 0
FLASHLOAN_DISABLED = '91', // FlashLoaning for this asset is disabled
// SafeCast
SAFECAST_UINT128_OVERFLOW = "SafeCast: value doesn't fit in 128 bits",

Expand Down
51 changes: 27 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aave/core-v3",
"version": "1.16.2",
"version": "1.16.2-beta.1",
"description": "Aave Protocol V3 core smart contracts",
"files": [
"contracts",
Expand Down Expand Up @@ -30,8 +30,8 @@
"prepublish": "npm run compile"
},
"devDependencies": {
"@aave/deploy-v3": "1.27.0",
"@aave/periphery-v3": "1.18.0",
"@aave/deploy-v3": "1.27.0-beta.7",
"@aave/periphery-v3": "^1.19.2-beta.0",
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13",
"@tenderly/hardhat-tenderly": "1.1.0-beta.5",
"@typechain/ethers-v5": "7.2.0",
Expand Down
25 changes: 25 additions & 0 deletions test-suites/configurator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,4 +1075,29 @@ makeSuite('PoolConfigurator', (testEnv: TestEnv) => {
const { helpersContract } = testEnv;
expect(await helpersContract.getDebtCeilingDecimals()).to.be.eq(2);
});

it('Check that the reserves have flashloans enabled', async () => {
const { weth, aave, usdc, dai, helpersContract } = testEnv;

const wethFlashLoanEnabled = await helpersContract.getFlashLoanEnabled(weth.address);
expect(wethFlashLoanEnabled).to.be.equal(true);

const aaveFlashLoanEnabled = await helpersContract.getFlashLoanEnabled(aave.address);
expect(aaveFlashLoanEnabled).to.be.equal(true);

const usdcFlashLoanEnabled = await helpersContract.getFlashLoanEnabled(usdc.address);
expect(usdcFlashLoanEnabled).to.be.equal(true);

const daiFlashLoanEnabled = await helpersContract.getFlashLoanEnabled(dai.address);
expect(daiFlashLoanEnabled).to.be.equal(true);
});

it('Disable weth flashloans', async () => {
const { weth, configurator, helpersContract } = testEnv;

expect(await configurator.setReserveFlashLoaning(weth.address, false));

const wethFlashLoanEnabled = await helpersContract.getFlashLoanEnabled(weth.address);
expect(wethFlashLoanEnabled).to.be.equal(false);
});
});
Loading

0 comments on commit c18e3c4

Please sign in to comment.