Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/enable disable flashloan config #710

Merged
merged 28 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bb62572
feat: enable and disable flashloans
Aug 29, 2022
d7aa26a
fix: remove gitignore update
Aug 29, 2022
348ce20
feat: bump to beta version
Aug 29, 2022
8b9221b
feat: remove borrow enabled requirement
Aug 29, 2022
8d12d79
feat: updates and tests
Aug 29, 2022
a5ce86a
fix: remove unrelated change
Aug 29, 2022
4c2cda0
fix: remove formatting conflicts
Aug 29, 2022
2710b9c
Update contracts/protocol/pool/PoolConfigurator.sol
Oct 18, 2022
c3c6e75
Update contracts/protocol/libraries/configuration/ReserveConfiguratio…
Oct 18, 2022
6f5d692
Update contracts/protocol/libraries/configuration/ReserveConfiguratio…
Oct 18, 2022
4fb58e8
Update contracts/protocol/libraries/configuration/ReserveConfiguratio…
Oct 18, 2022
a5d188c
Update contracts/protocol/libraries/configuration/ReserveConfiguratio…
Oct 18, 2022
c646e35
Update contracts/misc/AaveProtocolDataProvider.sol
Oct 18, 2022
7d3bedd
Update contracts/interfaces/IPoolConfigurator.sol
Oct 18, 2022
c17c5a8
Update contracts/interfaces/IPoolConfigurator.sol comments
Oct 18, 2022
2f2e18e
Update contracts/interfaces/IPoolConfigurator.sol comments
Oct 18, 2022
9d84549
fix: update comment for setReserveFlashLoaning
Oct 18, 2022
284b492
fix: check revert msg and event emission
Oct 18, 2022
8888093
feat: add additional flashloan scenario
Oct 18, 2022
748818f
feat: switch bit used for flashloan enabled
Oct 25, 2022
7bd04e7
Update test-suites/pool-flashloan.spec.ts - move await
Oct 25, 2022
49d0f4e
feat: add unit test for reserve configuration
Oct 25, 2022
516e0e8
fix: streamline test
Oct 25, 2022
81b9cb9
Merge branch 'feat/enable-disable-flashloan-config' of github.com:aav…
Oct 25, 2022
d87efa6
Merge branch 'feat/3.0.1' into feat/enable-disable-flashloan-config
Oct 28, 2022
1820962
Merge branch 'feat/3.0.1' into feat/enable-disable-flashloan-config
Nov 10, 2022
078fa28
fix: update deploy and periphery dependencies
Nov 15, 2022
bf652c2
fix: add validation to simpleFlashLoan
Nov 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
miguelmtzinf marked this conversation as resolved.
Show resolved Hide resolved
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
*/
stevenvaleri marked this conversation as resolved.
Show resolved Hide resolved
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
3 changes: 2 additions & 1 deletion helpers/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber } from 'ethers';
import {BigNumber} from 'ethers';

export interface SymbolMap<T> {
[symbol: string]: T;
Expand Down 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);
miguelmtzinf marked this conversation as resolved.
Show resolved Hide resolved

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