Skip to content

Commit

Permalink
feat: enable and disable flashloans
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Valeri committed Aug 29, 2022
1 parent e497caf commit bb62572
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ coverage
.coverage_cache
.coverage_contracts
coverage.json
deployments/
deployments/

.DS_Store
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 All @@ -43,6 +44,7 @@ contract ReservesSetupHelper is Ownable {

if (inputParams[i].borrowingEnabled) {
configurator.setReserveBorrowing(inputParams[i].asset, true);
configurator.setReserveFlashLoaning(inputParams[i].asset, inputParams[i].flashLoanEnabled);

configurator.setBorrowCap(inputParams[i].asset, inputParams[i].borrowCap);
configurator.setReserveStableRateBorrowing(
Expand Down
15 changes: 15 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 if flashloans are disabled
*/
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,14 @@ interface IPoolConfigurator {
**/
function setReserveStableRateBorrowing(address asset, bool enabled) external;

/**
* @notice Configures flashloans on a reserve
* @dev Can only be enabled (set to true) if borrowing is enabled
* @param asset The address of the underlying asset of the reserve
* @param enabled True if flashloans need to be enabled, false to disable falshloans
*/
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ library ReserveConfiguration {
uint256 internal constant EMODE_CATEGORY_MASK = 0xFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant UNBACKED_MINT_CAP_MASK = 0xFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant DEBT_CEILING_MASK = 0xF0000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant FLASHLOAN_ENABLED_MASK = 0xEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore

/// @dev For the LTV, the start bit is 0 (up to 15), hence no bitshifting is needed
uint256 internal constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16;
Expand All @@ -49,6 +50,7 @@ library ReserveConfiguration {
uint256 internal constant EMODE_CATEGORY_START_BIT_POSITION = 168;
uint256 internal constant UNBACKED_MINT_CAP_START_BIT_POSITION = 176;
uint256 internal constant DEBT_CEILING_START_BIT_POSITION = 212;
uint256 internal constant FLASHLOAN_ENABLED_START_BIT_POSITION = 252;

uint256 internal constant MAX_VALID_LTV = 65535;
uint256 internal constant MAX_VALID_LIQUIDATION_THRESHOLD = 65535;
Expand Down Expand Up @@ -547,6 +549,32 @@ library ReserveConfiguration {
return (self.data & ~EMODE_CATEGORY_MASK) >> EMODE_CATEGORY_START_BIT_POSITION;
}

/**
* @dev Set whether or not FlashLoaning this asset is enabled
* @param self The reserve configuration
* @param flashLoanEnabled boolean to indicated if Flashloans should be enabled (1) or disabled (0)
*/
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);
}

/**
* @dev Get the flashLoanEnabledSetting
* @param self The reserve configuration
*/
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 @@ -97,4 +97,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
}
1 change: 1 addition & 0 deletions contracts/protocol/libraries/logic/ValidationLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ library ValidationLogic {
.configuration;
require(!configuration.getPaused(), Errors.RESERVE_PAUSED);
require(configuration.getActive(), Errors.RESERVE_INACTIVE);
require(configuration.getFlashLoanEnabled(), Errors.FLASHLOAN_DISABLED);
}
}

Expand Down
18 changes: 17 additions & 1 deletion contracts/protocol/pool/PoolConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ contract PoolConfigurator is VersionedInitializable, IPoolConfigurator {
uint256 public constant CONFIGURATOR_REVISION = 0x1;

/// @inheritdoc VersionedInitializable
function getRevision() internal pure virtual override returns (uint256) {
function getRevision() internal virtual override pure returns (uint256) {
return CONFIGURATOR_REVISION;
}

Expand Down Expand Up @@ -191,6 +191,22 @@ 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);

if (enabled) {
require(currentConfig.getBorrowingEnabled(), Errors.BORROWING_NOT_ENABLED);
}
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

0 comments on commit bb62572

Please sign in to comment.